From 7428ee1b5d1b646d9008f4f467b869cdc517d6cc Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 28 Nov 2022 11:14:18 +0100 Subject: [PATCH] fix tests --- .../info/nightscout/androidaps/TestBase.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 plugins/sync/src/test/java/info/nightscout/androidaps/TestBase.kt diff --git a/plugins/sync/src/test/java/info/nightscout/androidaps/TestBase.kt b/plugins/sync/src/test/java/info/nightscout/androidaps/TestBase.kt new file mode 100644 index 0000000000..03d778b101 --- /dev/null +++ b/plugins/sync/src/test/java/info/nightscout/androidaps/TestBase.kt @@ -0,0 +1,39 @@ +package info.nightscout.androidaps + +import info.nightscout.rx.AapsSchedulers +import info.nightscout.rx.TestAapsSchedulers +import info.nightscout.rx.logging.AAPSLoggerTest +import org.junit.Before +import org.junit.Rule +import org.mockito.Mockito +import org.mockito.junit.MockitoJUnit +import org.mockito.junit.MockitoRule +import java.util.Locale + +open class TestBase { + + val aapsLogger = AAPSLoggerTest() + val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() + + // Add a JUnit rule that will setup the @Mock annotated vars and log. + // Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method. + @get:Rule + val mockitoRule: MockitoRule = MockitoJUnit.rule() + + @Before + fun setupLocale() { + Locale.setDefault(Locale.ENGLISH) + System.setProperty("disableFirebase", "true") + } + + // Workaround for Kotlin nullability. + // https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791 + // https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin + fun anyObject(): T { + Mockito.any() + return uninitialized() + } + + @Suppress("Unchecked_Cast") + fun uninitialized(): T = null as T +} \ No newline at end of file