-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
228 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,6 @@ build/ | |
|
||
# Project | ||
src/main/resources/application.conf | ||
|
||
# System | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Komok" type="JetRunConfigurationType"> | ||
<option name="MAIN_CLASS_NAME" value="io.heapy.komok.Application" /> | ||
<module name="komok.main" /> | ||
<shortenClasspath name="NONE" /> | ||
<method v="2"> | ||
<option name="Make" enabled="true" /> | ||
</method> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
komok-tech-di-test/src/main/kotlin/io/heapy/komok/tech/di/test2/ModuleA.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.heapy.komok.tech.di.test2 | ||
|
||
import io.heapy.komok.tech.di.lib.Module | ||
|
||
class A | ||
|
||
@Module | ||
open class ModuleA { | ||
open val a by lazy { | ||
A() | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
komok-tech-di-test/src/main/kotlin/io/heapy/komok/tech/di/test2/ModuleB.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.heapy.komok.tech.di.test2 | ||
|
||
import io.heapy.komok.tech.di.lib.Module | ||
|
||
class B( | ||
private val a: A, | ||
) { | ||
fun getA() = a | ||
} | ||
|
||
@Module | ||
open class ModuleB( | ||
private val moduleA: ModuleA, | ||
) { | ||
open val b by lazy { | ||
B(moduleA.a) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
komok-tech-di-test/src/main/kotlin/io/heapy/komok/tech/di/test2/ModuleC.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.heapy.komok.tech.di.test2 | ||
|
||
import io.heapy.komok.tech.di.lib.Module | ||
|
||
class C( | ||
private val a: A, | ||
) { | ||
fun getA() = | ||
a | ||
} | ||
|
||
@Module | ||
open class ModuleC( | ||
private val moduleA: ModuleA, | ||
) { | ||
open val c by lazy { | ||
C(moduleA.a) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
komok-tech-di-test/src/main/kotlin/io/heapy/komok/tech/di/test2/ModuleD.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.heapy.komok.tech.di.test2 | ||
|
||
import io.heapy.komok.tech.di.lib.Module | ||
|
||
class D( | ||
private val a: A, | ||
private val b: B, | ||
private val c: C, | ||
) { | ||
fun getAA() = a | ||
fun getAB() = b.getA() | ||
fun getAC() = c.getA() | ||
} | ||
|
||
@Module | ||
open class ModuleD( | ||
private val moduleA: ModuleA, | ||
private val moduleB: ModuleB, | ||
private val moduleC: ModuleC, | ||
) { | ||
open val d by lazy { | ||
D(moduleA.a, moduleB.b, moduleC.c) | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
komok-tech-di-test/src/test/kotlin/io/heapy/komok/tech/di/test2/SingletonTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.heapy.komok.tech.di.test2 | ||
|
||
import org.junit.jupiter.api.Assertions.assertAll | ||
import org.junit.jupiter.api.Assertions.assertSame | ||
import org.junit.jupiter.api.Test | ||
|
||
class SingletonTest { | ||
@Test | ||
fun `test singleton`() { | ||
val moduleD = createModuleD {} | ||
|
||
assertAll( | ||
{ assertSame(moduleD.d.getAA(), moduleD.d.getAB()) }, | ||
{ assertSame(moduleD.d.getAB(), moduleD.d.getAC()) }, | ||
{ assertSame(moduleD.d.getAA(), moduleD.d.getAC()) }, | ||
) | ||
} | ||
|
||
@Test | ||
fun `test singleton flatten`() { | ||
val flat = createFlattenModuleD {} | ||
|
||
assertAll( | ||
{ assertSame(flat.moduleD.d.getAA(), flat.moduleD.d.getAB()) }, | ||
{ assertSame(flat.moduleD.d.getAB(), flat.moduleD.d.getAC()) }, | ||
{ assertSame(flat.moduleD.d.getAA(), flat.moduleD.d.getAC()) }, | ||
{ assertSame(flat.moduleA.a, flat.moduleD.d.getAA()) }, | ||
) | ||
} | ||
|
||
@Test | ||
fun `test singleton with override`() { | ||
val a = A() | ||
val moduleD = createModuleD { | ||
moduleA { | ||
a { | ||
a | ||
} | ||
} | ||
} | ||
|
||
assertAll( | ||
{ assertSame(moduleD.d.getAA(), moduleD.d.getAB()) }, | ||
{ assertSame(moduleD.d.getAB(), moduleD.d.getAC()) }, | ||
{ assertSame(moduleD.d.getAA(), moduleD.d.getAC()) }, | ||
) | ||
} | ||
|
||
@Test | ||
fun `test singleton with override flatten`() { | ||
val a = A() | ||
val flat = createFlattenModuleD { | ||
moduleA { | ||
a { | ||
a | ||
} | ||
} | ||
} | ||
|
||
assertAll( | ||
{ assertSame(a, flat.moduleD.d.getAA()) }, | ||
{ assertSame(a, flat.moduleD.d.getAB()) }, | ||
{ assertSame(a, flat.moduleD.d.getAC()) }, | ||
{ assertSame(a, flat.moduleA.a) }, | ||
{ assertSame(a, flat.moduleB.b.getA()) }, | ||
{ assertSame(a, flat.moduleC.c.getA()) }, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.