Insulin tests

This commit is contained in:
Milos Kozak 2020-01-11 15:19:46 +01:00
parent 65ec024751
commit cb12967b17
5 changed files with 143 additions and 3 deletions

View file

@ -9,7 +9,7 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class DefaultValueHelper @Inject constructor(
open class DefaultValueHelper @Inject constructor(
private val sp: SP,
private val profileFunction: ProfileFunction
) {

View file

@ -52,7 +52,7 @@ class InsulinOrefBasePluginTest {
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
lateinit var sut: InsulinBaseTest
private lateinit var sut: InsulinBaseTest
@Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var resourceHelper: ResourceHelper
@ -61,7 +61,7 @@ class InsulinOrefBasePluginTest {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
private var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector {
if (it is Treatment) {
it.defaultValueHelper = defaultValueHelper
@ -87,6 +87,11 @@ class InsulinOrefBasePluginTest {
Assert.assertTrue(shortDiaNotificationSend)
}
@Test
fun minDiaTes() {
Assert.assertEquals(5.0, MIN_DIA, 0.0001)
}
@Test
fun testIobCalcForTreatment() {
val treatment = Treatment(treatmentInjector) //TODO: this should be a separate sut. I'd prefer a separate class.

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.insulin
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.InsulinInterface
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
@ -54,6 +55,24 @@ class InsulinOrefFreePeakPluginTest {
assertEquals(90, sut.peak)
}
@Test
fun getIdTest() {
assertEquals(InsulinInterface.OREF_FREE_PEAK, sut.id)
}
@Test
fun commentStandardTextTest() {
`when`(sp.getInt(eq(R.string.key_insulin_oref_peak), anyInt())).thenReturn(90)
`when`(resourceHelper.gs(eq(R.string.insulin_peak_time))).thenReturn("Peak Time [min]")
assertEquals("Peak Time [min]: 90", sut.commentStandardText())
}
@Test
fun getFriendlyNameTest() {
`when`(resourceHelper.gs(eq(R.string.free_peak_oref))).thenReturn("Free-Peak Oref")
assertEquals("Free-Peak Oref", sut.friendlyName)
}
// 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

View file

@ -0,0 +1,58 @@
package info.nightscout.androidaps.plugins.insulin
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.InsulinInterface
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
class InsulinOrefRapidActingPluginTest {
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
private lateinit var sut: InsulinOrefRapidActingPlugin
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var aapsLogger: AAPSLogger
@Before
fun setup() {
sut = InsulinOrefRapidActingPlugin(resourceHelper, profileFunction, rxBus, aapsLogger)
}
@Test
fun `simple peak test`() {
assertEquals(75, sut.peak)
}
@Test
fun getIdTest() {
assertEquals(InsulinInterface.OREF_RAPID_ACTING, sut.id)
}
@Test
fun commentStandardTextTest() {
`when`(resourceHelper.gs(eq(R.string.fastactinginsulincomment))).thenReturn("Novorapid, Novolog, Humalog")
assertEquals("Novorapid, Novolog, Humalog", sut.commentStandardText())
}
@Test
fun getFriendlyNameTest() {
`when`(resourceHelper.gs(eq(R.string.rapid_acting_oref))).thenReturn("Rapid-Acting Oref")
assertEquals("Rapid-Acting Oref", sut.friendlyName)
}
}

View file

@ -0,0 +1,58 @@
package info.nightscout.androidaps.plugins.insulin
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.InsulinInterface
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
class InsulinOrefUltraRapidActingPluginTest {
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
private lateinit var sut: InsulinOrefUltraRapidActingPlugin
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var aapsLogger: AAPSLogger
@Before
fun setup() {
sut = InsulinOrefUltraRapidActingPlugin(resourceHelper, profileFunction, rxBus, aapsLogger)
}
@Test
fun `simple peak test`() {
assertEquals(55, sut.peak)
}
@Test
fun getIdTest() {
assertEquals(InsulinInterface.OREF_ULTRA_RAPID_ACTING, sut.id)
}
@Test
fun commentStandardTextTest() {
`when`(resourceHelper.gs(eq(R.string.ultrafastactinginsulincomment))).thenReturn("Fiasp")
assertEquals("Fiasp", sut.commentStandardText())
}
@Test
fun getFriendlyNameTest() {
`when`(resourceHelper.gs(eq(R.string.ultrarapid_oref))).thenReturn("Ultra-Rapid Oref")
assertEquals("Ultra-Rapid Oref", sut.friendlyName)
}
}