diff --git a/app/src/main/java/info/nightscout/androidaps/utils/ResourceHelper.kt b/app/src/main/java/info/nightscout/androidaps/utils/ResourceHelper.kt index 655c319170..a718a0803e 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/ResourceHelper.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/ResourceHelper.kt @@ -9,7 +9,7 @@ import javax.inject.Inject /** * Created by adrian on 2019-12-23. */ -class ResourceHelper @Inject constructor() { +open class ResourceHelper @Inject constructor() { fun gs(@StringRes id: Int): String = MainApp.sResources.getString(id) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt new file mode 100644 index 0000000000..806c8e0379 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt @@ -0,0 +1,60 @@ +package info.nightscout.androidaps.plugins.insulin + +import info.nightscout.androidaps.R +import info.nightscout.androidaps.utils.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP +import junit.framework.Assert.assertEquals +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.mockito.ArgumentMatchers.anyInt +import org.mockito.ArgumentMatchers.eq +import org.mockito.Mock +import org.mockito.Mockito +import org.mockito.Mockito.`when` +import org.mockito.junit.MockitoJUnit +import org.mockito.junit.MockitoRule + +/** + * Created by adrian on 2019-12-25. + */ + +class InsulinOrefFreePeakPluginTest { + + + // TODO: move to a base class + // 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() + + lateinit var sut: InsulinOrefFreePeakPlugin + + @Mock + lateinit var sp: SP + + @Mock + lateinit var resourceHelper: ResourceHelper + + @Before + fun setup() { + sut = InsulinOrefFreePeakPlugin(sp, resourceHelper) + } + + @Test + fun `simple peak test`() { + `when`(sp.getInt(eq(R.string.key_insulin_oref_peak), anyInt())).thenReturn(90) + assertEquals(90, sut.peak) + } + + // Workaround for Kotlin nullability. TODO: move to a base class + // https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791 + // https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin + private fun anyObject(): T { + Mockito.any() + return uninitialized() + } + + private fun uninitialized(): T = null as T + +} \ No newline at end of file