Skip to content

Commit

Permalink
reuse KoinCoreTest to avoid unwanted dangling Koin instance
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgiuliani committed Jan 9, 2025
1 parent f28a59d commit 53d8c7b
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.core

import org.koin.KoinCoreTest
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
Expand Down Expand Up @@ -33,7 +34,7 @@ class SomeClassB : SomeClassInterface {
}
}

class OverrideAndCreateatStartTest {
class OverrideAndCreateatStartTest : KoinCoreTest(){
val moduleA = module {
single<SomeClassInterface>(createdAtStart = true) {
SomeClassA()
Expand All @@ -46,11 +47,6 @@ class OverrideAndCreateatStartTest {
}
}

@AfterTest
fun after() {
stopKoin()
}

@OptIn(KoinInternalApi::class)
@Test
fun testDefinitionOverride() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.logger.Level
import org.koin.core.qualifier.named
Expand All @@ -9,7 +10,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals

// TODO - Check flaky tests
class AdditionalTypeBindingTest {
class AdditionalTypeBindingTest : KoinCoreTest() {

// @Test
// fun `can resolve an additional type - bind`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
Expand All @@ -9,7 +10,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class CloseDefinitionTest {
class CloseDefinitionTest : KoinCoreTest() {

@Test
fun test_onClose() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.core.logger.Level
import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.factoryOf
Expand All @@ -9,7 +10,7 @@ import kotlin.test.Test
import kotlin.test.assertNotNull
import kotlin.test.assertNull

class ConstructorDSLTest {
class ConstructorDSLTest : KoinCoreTest() {

@Test
fun test_reified_type_constructor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.component.KoinComponent
import org.koin.core.context.startKoin
Expand All @@ -9,12 +10,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class CreateOnStart {

@AfterTest
fun after() {
stopKoin()
}
class CreateOnStart : KoinCoreTest() {

@Test
fun `works with koin 2_2_3 and koin 3_0_2 breaks with koin 3_1_4`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.core.module.flatten
import kotlin.test.Test
import kotlin.test.assertTrue

class FlattenTest {
class FlattenTest : KoinCoreTest() {

@Test
fun test_simple_flatten() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.Simple.ComponentA
import org.koin.Simple.ComponentB
import org.koin.core.annotation.KoinInternalApi
Expand All @@ -19,12 +20,7 @@ import kotlin.test.assertNotNull
import kotlin.test.fail

@OptIn(KoinInternalApi::class)
class KoinAppCreationTest {

@AfterTest
fun after() {
stopKoin()
}
class KoinAppCreationTest : KoinCoreTest() {

@Test
fun `make a Koin application`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.error.InstanceCreationException
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.fail

class ModuleAndPropertiesTest {
class ModuleAndPropertiesTest : KoinCoreTest() {

@Test
fun `get a property from a module`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.logger.Level
import org.koin.test.assertDefinitionsCount
import kotlin.test.Test
import kotlin.test.assertEquals

class ModuleCreationTest {
class ModuleCreationTest : KoinCoreTest() {

@Test
fun `create an empty module`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.error.DefinitionOverrideException
import org.koin.core.logger.Level
Expand All @@ -8,7 +9,7 @@ import org.koin.test.assertDefinitionsCount
import kotlin.test.Test
import kotlin.test.assertEquals

class ModuleDeclarationRulesTest {
class ModuleDeclarationRulesTest : KoinCoreTest() {

@Test
fun `don't allow redeclaration`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.module.Module
Expand All @@ -14,7 +15,7 @@ val myGetModule : Module get() = module { single { Simple.ComponentA() } }
fun myFunModule() = module { single { Simple.ComponentA() } }

@OptIn(KoinInternalApi::class)
class ModuleFactoryIsolationTest {
class ModuleFactoryIsolationTest : KoinCoreTest() {

@Test
fun testVariableIsolationAndInstanceFactories(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.core.module.dsl.singleOf
import org.koin.core.qualifier.named
import kotlin.test.Test
import kotlin.test.assertNotNull

class ModuleIncludeTest {
class ModuleIncludeTest : KoinCoreTest() {

@Test
fun test_include() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
Expand All @@ -9,7 +10,7 @@ import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test

class ModuleRestartTest : KoinComponent {
class ModuleRestartTest : KoinComponent, KoinCoreTest() {

@BeforeTest
fun before() {
Expand All @@ -22,11 +23,6 @@ class ModuleRestartTest : KoinComponent {
}
}

@AfterTest
fun after() {
stopKoin()
}

@Test
fun first_test() {
get<Simple.ComponentA>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.core.qualifier.named
import kotlin.test.Test
import kotlin.test.assertEquals

class ModuleSpecialRulesTest {
class ModuleSpecialRulesTest : KoinCoreTest() {

@Test
fun `generic type declaration`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.logger.Level
import org.koin.core.qualifier.*
import kotlin.test.Test
import kotlin.test.assertEquals

class NamingTest {
class NamingTest : KoinCoreTest(){

@Test
fun `can resolve naming from root`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package org.koin.dsl

import org.koin.KoinCoreTest
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.instance.FactoryInstanceFactory
import org.koin.core.instance.ScopedInstanceFactory
Expand All @@ -18,7 +19,7 @@ class ClassA2 : IClassA
class ClassB(val a: IClassA)
interface IClassA

class NewDSLTest {
class NewDSLTest : KoinCoreTest() {

@Test
fun singleof_options() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.koin.dsl

import org.koin.KoinCoreTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class PropertyDefinitionTest {
class PropertyDefinitionTest : KoinCoreTest(){

@Test
fun `load and get properties`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.koin.full

import org.koin.KoinCoreTest
import org.koin.core.logger.Level
import org.koin.dsl.koinApplication
import org.koin.dsl.module
import kotlin.test.*

class TODOAppTest {
class TODOAppTest : KoinCoreTest(){

val defaultModule = module {
single { TasksRepository(get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.koincomponent

import org.koin.KoinCoreTest
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.koin.core.context.startKoin
Expand All @@ -16,7 +17,7 @@ class MyApp : KoinComponent {
val presenter: TasksPresenter by inject()
}

class AppTest {
class AppTest : KoinCoreTest(){

@Test
fun can_run_KoinComponent_app() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.koincomponent

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.Koin
import org.koin.core.component.KoinComponent
Expand Down Expand Up @@ -31,7 +32,7 @@ class MyCustomApp : CustomKoinComponent() {
val a: Simple.ComponentA by inject()
}

class CustomKoinComponentTest {
class CustomKoinComponentTest : KoinCoreTest(){

@Test
fun can_inject_KoinComponent_from_custom_instance() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.koincomponent

import org.koin.KoinCoreTest
import org.koin.Simple
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
Expand All @@ -20,7 +21,7 @@ class MyLazyComponent : KoinComponent {
val anInject: Simple.ComponentA by inject()
}

class KoinComponentTest {
class KoinComponentTest : KoinCoreTest(){

@Test
fun can_lazy_inject_from_KoinComponent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.koincomponent

import org.koin.KoinCoreTest
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.koin.core.context.startKoin
Expand All @@ -10,7 +11,7 @@ import org.koin.dsl.bind
import org.koin.dsl.module
import kotlin.test.Test

class TODOAppTest {
class TODOAppTest : KoinCoreTest(){

val todoAppModule = module {
single { TasksView() } bind TasksContract.View::class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.koin.core

import org.junit.Test
import org.koin.KoinCoreTest
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.core.logger.Level

@OptIn(KoinInternalApi::class)
class DebugLogTest {
class DebugLogTest : KoinCoreTest(){

@Test
fun fasterDebug() {
Expand Down
Loading

0 comments on commit 53d8c7b

Please sign in to comment.