Insulin tests
This commit is contained in:
parent
2f527169d9
commit
64184f164f
4 changed files with 37 additions and 31 deletions
|
@ -26,12 +26,13 @@ class InsulinOrefBasePluginTest {
|
||||||
var shortDiaNotificationSend = false
|
var shortDiaNotificationSend = false
|
||||||
|
|
||||||
inner class InsulinBaseTest(
|
inner class InsulinBaseTest(
|
||||||
|
injector: HasAndroidInjector,
|
||||||
resourceHelper: ResourceHelper,
|
resourceHelper: ResourceHelper,
|
||||||
profileFunction: ProfileFunction,
|
profileFunction: ProfileFunction,
|
||||||
rxBus: RxBusWrapper,
|
rxBus: RxBusWrapper,
|
||||||
aapsLogger: AAPSLogger
|
aapsLogger: AAPSLogger
|
||||||
) : InsulinOrefBasePlugin(
|
) : InsulinOrefBasePlugin(
|
||||||
resourceHelper, profileFunction, rxBus, aapsLogger
|
injector, resourceHelper, profileFunction, rxBus, aapsLogger
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun sendShortDiaNotification(dia: Double) {
|
override fun sendShortDiaNotification(dia: Double) {
|
||||||
|
@ -61,7 +62,7 @@ class InsulinOrefBasePluginTest {
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||||
|
|
||||||
private var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
|
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
if (it is Treatment) {
|
if (it is Treatment) {
|
||||||
it.defaultValueHelper = defaultValueHelper
|
it.defaultValueHelper = defaultValueHelper
|
||||||
|
@ -74,7 +75,7 @@ class InsulinOrefBasePluginTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
sut = InsulinBaseTest(resourceHelper, profileFunction, rxBus, aapsLogger)
|
sut = InsulinBaseTest(injector, resourceHelper, profileFunction, rxBus, aapsLogger)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -94,7 +95,7 @@ class InsulinOrefBasePluginTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testIobCalcForTreatment() {
|
fun testIobCalcForTreatment() {
|
||||||
val treatment = Treatment(treatmentInjector) //TODO: this should be a separate sut. I'd prefer a separate class.
|
val treatment = Treatment(injector) //TODO: this should be a separate sut. I'd prefer a separate class.
|
||||||
val expected = Iob()
|
val expected = Iob()
|
||||||
Assert.assertEquals(expected, sut.iobCalcForTreatment(treatment, 0, 0.0))
|
Assert.assertEquals(expected, sut.iobCalcForTreatment(treatment, 0, 0.0))
|
||||||
testPeak = 30
|
testPeak = 30
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package info.nightscout.androidaps.plugins.insulin
|
package info.nightscout.androidaps.plugins.insulin
|
||||||
|
|
||||||
|
import dagger.android.AndroidInjector
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.TestBase
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface
|
import info.nightscout.androidaps.interfaces.InsulinInterface
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
@ -23,14 +26,7 @@ import org.mockito.junit.MockitoRule
|
||||||
* Created by adrian on 2019-12-25.
|
* Created by adrian on 2019-12-25.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class InsulinOrefFreePeakPluginTest {
|
class InsulinOrefFreePeakPluginTest : TestBase() {
|
||||||
|
|
||||||
|
|
||||||
// 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
|
lateinit var sut: InsulinOrefFreePeakPlugin
|
||||||
|
|
||||||
|
@ -40,13 +36,20 @@ class InsulinOrefFreePeakPluginTest {
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
|
|
||||||
|
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||||
|
AndroidInjector {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
sut = InsulinOrefFreePeakPlugin(sp = sp,
|
sut = InsulinOrefFreePeakPlugin(
|
||||||
resourceHelper = resourceHelper,
|
injector,
|
||||||
rxBus = rxBus,
|
sp,
|
||||||
profileFunction = profileFunction,
|
resourceHelper,
|
||||||
aapsLogger = aapsLogger)
|
profileFunction,
|
||||||
|
rxBus,
|
||||||
|
aapsLogger)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -72,16 +75,4 @@ class InsulinOrefFreePeakPluginTest {
|
||||||
`when`(resourceHelper.gs(eq(R.string.free_peak_oref))).thenReturn("Free-Peak Oref")
|
`when`(resourceHelper.gs(eq(R.string.free_peak_oref))).thenReturn("Free-Peak Oref")
|
||||||
assertEquals("Free-Peak Oref", sut.friendlyName)
|
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
|
|
||||||
private fun <T> anyObject(): T {
|
|
||||||
Mockito.any<T>()
|
|
||||||
return uninitialized()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("Unchecked_Cast")
|
|
||||||
private fun <T> uninitialized(): T = null as T
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.insulin
|
package info.nightscout.androidaps.plugins.insulin
|
||||||
|
|
||||||
|
import dagger.android.AndroidInjector
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface
|
import info.nightscout.androidaps.interfaces.InsulinInterface
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
@ -28,9 +30,14 @@ class InsulinOrefRapidActingPluginTest {
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
|
|
||||||
|
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||||
|
AndroidInjector {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
sut = InsulinOrefRapidActingPlugin(resourceHelper, profileFunction, rxBus, aapsLogger)
|
sut = InsulinOrefRapidActingPlugin(injector, resourceHelper, profileFunction, rxBus, aapsLogger)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.insulin
|
package info.nightscout.androidaps.plugins.insulin
|
||||||
|
|
||||||
|
import dagger.android.AndroidInjector
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface
|
import info.nightscout.androidaps.interfaces.InsulinInterface
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
@ -28,9 +30,14 @@ class InsulinOrefUltraRapidActingPluginTest {
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
|
|
||||||
|
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||||
|
AndroidInjector {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
sut = InsulinOrefUltraRapidActingPlugin(resourceHelper, profileFunction, rxBus, aapsLogger)
|
sut = InsulinOrefUltraRapidActingPlugin(injector, resourceHelper, profileFunction, rxBus, aapsLogger)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue