forked from InsertKoinIO/koin
-
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.
fix InsertKoinIO#1213 Mock instance check
- Loading branch information
1 parent
aa7f660
commit b462f16
Showing
4 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
android/koin-android/src/test/java/org/koin/test/android/CheckTest.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,44 @@ | ||
package org.koin.test.android | ||
|
||
import android.content.Context | ||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TestRule | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.core.context.startKoin | ||
import org.koin.core.logger.Level | ||
import org.koin.dsl.module | ||
import org.koin.test.KoinTest | ||
import org.koin.test.check.checkKoinModules | ||
import org.koin.test.check.checkModules | ||
import org.koin.test.mock.MockProviderRule | ||
import org.mockito.Mockito | ||
import kotlin.reflect.KClass | ||
|
||
class PrefsManager(val context: Context) | ||
|
||
// KoinModulesTest.kt | ||
class KoinModulesTest : KoinTest { | ||
|
||
@get:Rule | ||
val rule: TestRule = InstantTaskExecutorRule() | ||
|
||
// KoinAppModule.kt | ||
val prefsModule = module { | ||
single { PrefsManager(context = get()) } // package.PrefsManager constructor(context: Context) | ||
} | ||
|
||
@get:Rule | ||
val mockProvider = MockProviderRule.create { kClass: KClass<*> -> | ||
// invokes properly with android.content.Context | ||
Mockito.mock(kClass.java) | ||
} | ||
|
||
@Test | ||
fun checkAllModules() { | ||
checkKoinModules(listOf(prefsModule)){ | ||
withInstance<Context>() | ||
} | ||
} | ||
} |
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