test with AndroidInjector

This commit is contained in:
AdrianLxM 2020-01-11 12:40:11 +01:00
parent 6326c3f6f9
commit cde7b44606
2 changed files with 20 additions and 8 deletions

View file

@ -36,10 +36,10 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
@DatabaseTable(tableName = Treatment.TABLE_TREATMENTS) @DatabaseTable(tableName = Treatment.TABLE_TREATMENTS)
public class Treatment implements DataPointWithLabelInterface, DbObjectBase { public class Treatment implements DataPointWithLabelInterface, DbObjectBase {
@Inject DefaultValueHelper defaultValueHelper; @Inject public DefaultValueHelper defaultValueHelper;
@Inject ResourceHelper resourceHelper; @Inject public ResourceHelper resourceHelper;
@Inject ProfileFunction profileFunction; @Inject public ProfileFunction profileFunction;
@Inject ConfigBuilderPlugin configBuilderPlugin; @Inject public ConfigBuilderPlugin configBuilderPlugin;
public static final String TABLE_TREATMENTS = "Treatments"; public static final String TABLE_TREATMENTS = "Treatments";

View file

@ -1,13 +1,15 @@
package info.nightscout.androidaps.plugins.insulin package info.nightscout.androidaps.plugins.insulin
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.data.Iob import info.nightscout.androidaps.data.Iob
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.Companion.MIN_DIA import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.Companion.MIN_DIA
import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.plugins.treatments.Treatment
import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
@ -16,7 +18,6 @@ import org.junit.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule import org.mockito.junit.MockitoRule
import org.powermock.core.classloader.annotations.PrepareForTest
class InsulinOrefBasePluginTest { class InsulinOrefBasePluginTest {
@ -53,12 +54,23 @@ class InsulinOrefBasePluginTest {
lateinit var sut: InsulinBaseTest lateinit var sut: InsulinBaseTest
@Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
@Mock lateinit var injector: HasAndroidInjector var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector {
if (it is Treatment) {
it.defaultValueHelper = defaultValueHelper
it.resourceHelper = resourceHelper
it.profileFunction = profileFunction
it.configBuilderPlugin = configBuilderPlugin
}
}
}
@Before @Before
fun setUp() { fun setUp() {
@ -77,7 +89,7 @@ class InsulinOrefBasePluginTest {
@Test @Test
fun testIobCalcForTreatment() { fun testIobCalcForTreatment() {
val treatment = Treatment(injector) val treatment = Treatment(treatmentInjector) //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