From 5104dc1416025dc900b087e3a557e6fc4f6504a1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 26 Jun 2020 12:25:29 +0200 Subject: [PATCH] fix tests --- .../actions/ActionStartTempTargetTest.kt | 1 - .../general/automation/actions/ActionsTestBase.kt | 15 +++++++++++++-- .../automation/elements/InputTempTargetTest.kt | 2 ++ .../automation/triggers/TriggerTestBase.kt | 5 +++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt index f35e797a0b..0bf99824ec 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt @@ -24,7 +24,6 @@ class ActionStartTempTargetTest : ActionsTestBase() { @Before fun setup() { - PowerMockito.mockStatic(MainApp::class.java) `when`(resourceHelper.gs(R.string.starttemptarget)).thenReturn("Start temp target") sut = ActionStartTempTarget(injector) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt index 5d56382e0b..84e90208ed 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.general.automation.actions import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Constants import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.interfaces.ActivePluginProvider @@ -9,11 +10,14 @@ import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin +import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.utils.sharedPreferences.SP +import org.junit.Before import org.mockito.Mock +import org.mockito.Mockito.`when` import org.powermock.core.classloader.annotations.PrepareForTest @PrepareForTest(VirtualPumpPlugin::class, RxBusWrapper::class, LocalProfilePlugin::class, SmsCommunicatorPlugin::class, ConfigBuilderPlugin::class) @@ -25,8 +29,8 @@ open class ActionsTestBase : TestBaseWithProfile() { @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var loopPlugin: LoopPlugin @Mock lateinit var activePlugin: ActivePluginProvider - @Mock lateinit var localProfilePlugin : LocalProfilePlugin - @Mock lateinit var smsCommunicatorPlugin : SmsCommunicatorPlugin + @Mock lateinit var localProfilePlugin: LocalProfilePlugin + @Mock lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin var injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { @@ -87,7 +91,14 @@ open class ActionsTestBase : TestBaseWithProfile() { it.aapsLogger = aapsLogger it.resourceHelper = resourceHelper } + if (it is InputTempTarget) { + it.profileFunction = profileFunction + } } } + @Before + fun mock() { + `when`(profileFunction.getUnits()).thenReturn(Constants.MGDL) + } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt index d98ca75f1c..b137a8ef9b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt @@ -1,10 +1,12 @@ package info.nightscout.androidaps.plugins.general.automation.elements import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith +import org.mockito.Mock import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt index 2b35932914..bda0b5c532 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt @@ -6,9 +6,11 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.db.BgReading import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin import info.nightscout.androidaps.plugins.general.automation.elements.InputBg +import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin @@ -71,6 +73,9 @@ open class TriggerTestBase : TestBaseWithProfile() { if (it is InputBg) { it.profileFunction = profileFunction } + if (it is InputTempTarget) { + it.profileFunction = profileFunction + } if (it is GlucoseStatus) { it.aapsLogger = aapsLogger it.iobCobCalculatorPlugin = iobCobCalculatorPlugin