Insulin tests
This commit is contained in:
parent
2f527169d9
commit
64184f164f
|
@ -26,12 +26,13 @@ class InsulinOrefBasePluginTest {
|
|||
var shortDiaNotificationSend = false
|
||||
|
||||
inner class InsulinBaseTest(
|
||||
injector: HasAndroidInjector,
|
||||
resourceHelper: ResourceHelper,
|
||||
profileFunction: ProfileFunction,
|
||||
rxBus: RxBusWrapper,
|
||||
aapsLogger: AAPSLogger
|
||||
) : InsulinOrefBasePlugin(
|
||||
resourceHelper, profileFunction, rxBus, aapsLogger
|
||||
injector, resourceHelper, profileFunction, rxBus, aapsLogger
|
||||
) {
|
||||
|
||||
override fun sendShortDiaNotification(dia: Double) {
|
||||
|
@ -61,7 +62,7 @@ class InsulinOrefBasePluginTest {
|
|||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||
|
||||
private var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
|
||||
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is Treatment) {
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
|
@ -74,7 +75,7 @@ class InsulinOrefBasePluginTest {
|
|||
|
||||
@Before
|
||||
fun setUp() {
|
||||
sut = InsulinBaseTest(resourceHelper, profileFunction, rxBus, aapsLogger)
|
||||
sut = InsulinBaseTest(injector, resourceHelper, profileFunction, rxBus, aapsLogger)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -94,7 +95,7 @@ class InsulinOrefBasePluginTest {
|
|||
|
||||
@Test
|
||||
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()
|
||||
Assert.assertEquals(expected, sut.iobCalcForTreatment(treatment, 0, 0.0))
|
||||
testPeak = 30
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
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.interfaces.InsulinInterface
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
|
@ -23,14 +26,7 @@ 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()
|
||||
class InsulinOrefFreePeakPluginTest : TestBase() {
|
||||
|
||||
lateinit var sut: InsulinOrefFreePeakPlugin
|
||||
|
||||
|
@ -40,13 +36,20 @@ class InsulinOrefFreePeakPluginTest {
|
|||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
sut = InsulinOrefFreePeakPlugin(sp = sp,
|
||||
resourceHelper = resourceHelper,
|
||||
rxBus = rxBus,
|
||||
profileFunction = profileFunction,
|
||||
aapsLogger = aapsLogger)
|
||||
sut = InsulinOrefFreePeakPlugin(
|
||||
injector,
|
||||
sp,
|
||||
resourceHelper,
|
||||
profileFunction,
|
||||
rxBus,
|
||||
aapsLogger)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -72,16 +75,4 @@ class InsulinOrefFreePeakPluginTest {
|
|||
`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
|
||||
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
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
|
@ -28,9 +30,14 @@ class InsulinOrefRapidActingPluginTest {
|
|||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
sut = InsulinOrefRapidActingPlugin(resourceHelper, profileFunction, rxBus, aapsLogger)
|
||||
sut = InsulinOrefRapidActingPlugin(injector, resourceHelper, profileFunction, rxBus, aapsLogger)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.insulin
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
|
@ -28,9 +30,14 @@ class InsulinOrefUltraRapidActingPluginTest {
|
|||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
sut = InsulinOrefUltraRapidActingPlugin(resourceHelper, profileFunction, rxBus, aapsLogger)
|
||||
sut = InsulinOrefUltraRapidActingPlugin(injector, resourceHelper, profileFunction, rxBus, aapsLogger)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue