Actions tests
This commit is contained in:
parent
5cab10f51f
commit
04c90302bd
23 changed files with 808 additions and 902 deletions
|
@ -2,6 +2,7 @@ package info
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
import info.nightscout.androidaps.data.ProfileStore
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
|
@ -11,6 +12,16 @@ import org.mockito.junit.MockitoRule
|
||||||
open class TestBase {
|
open class TestBase {
|
||||||
val validProfileJSON = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
val validProfileJSON = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||||
val validProfile: Profile = Profile(JSONObject(validProfileJSON), Constants.MGDL)
|
val validProfile: Profile = Profile(JSONObject(validProfileJSON), Constants.MGDL)
|
||||||
|
val TESTPROFILENAME = "someProfile"
|
||||||
|
|
||||||
|
fun getValidProfileStore(): ProfileStore {
|
||||||
|
val json = JSONObject()
|
||||||
|
val store = JSONObject()
|
||||||
|
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
|
||||||
|
json.put("defaultProfile", TESTPROFILENAME)
|
||||||
|
json.put("store", store)
|
||||||
|
return ProfileStore(json)
|
||||||
|
}
|
||||||
|
|
||||||
// Add a JUnit rule that will setup the @Mock annotated vars and log.
|
// 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.
|
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
|
||||||
|
|
|
@ -1,63 +1,26 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
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.data.PumpEnactResult
|
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription
|
import info.nightscout.androidaps.interfaces.PumpDescription
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
|
||||||
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.pump.virtual.VirtualPumpPlugin
|
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.ArgumentMatchers.eq
|
import org.mockito.ArgumentMatchers.eq
|
||||||
import org.mockito.Mock
|
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
import org.powermock.modules.junit4.PowerMockRunner
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
@PrepareForTest(VirtualPumpPlugin::class, RxBusWrapper::class)
|
class ActionLoopDisableTest : ActionsTestBase() {
|
||||||
class ActionLoopDisableTest : TestBase() {
|
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var rxBus: RxBusWrapper
|
|
||||||
@Mock lateinit var sp: SP
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
|
||||||
@Mock lateinit var commandQueue: CommandQueueProvider
|
|
||||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
|
||||||
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
|
|
||||||
@Mock lateinit var loopPlugin: LoopPlugin
|
|
||||||
|
|
||||||
lateinit var sut: ActionLoopDisable
|
lateinit var sut: ActionLoopDisable
|
||||||
|
|
||||||
private var injector: HasAndroidInjector = HasAndroidInjector {
|
|
||||||
AndroidInjector {
|
|
||||||
if (it is ActionLoopDisable) {
|
|
||||||
it.loopPlugin = loopPlugin
|
|
||||||
it.resourceHelper = resourceHelper
|
|
||||||
it.configBuilderPlugin = configBuilderPlugin
|
|
||||||
it.commandQueue = commandQueue
|
|
||||||
it.rxBus = rxBus
|
|
||||||
}
|
|
||||||
if (it is PumpEnactResult) {
|
|
||||||
it.aapsLogger = aapsLogger
|
|
||||||
it.resourceHelper = resourceHelper
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
|
|
||||||
|
@ -68,12 +31,12 @@ class ActionLoopDisableTest : TestBase() {
|
||||||
`when`(resourceHelper.gs(R.string.disableloop)).thenReturn("Disable loop")
|
`when`(resourceHelper.gs(R.string.disableloop)).thenReturn("Disable loop")
|
||||||
`when`(resourceHelper.gs(R.string.alreadydisabled)).thenReturn("Disable loop")
|
`when`(resourceHelper.gs(R.string.alreadydisabled)).thenReturn("Disable loop")
|
||||||
|
|
||||||
sut = ActionLoopDisable(injector) // do nothing injector
|
sut = ActionLoopDisable(injector)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun friendlyNameTest() {
|
fun friendlyNameTest() {
|
||||||
Assert.assertEquals(R.string.disableloop.toLong(), sut.friendlyName().toLong())
|
Assert.assertEquals(R.string.disableloop, sut.friendlyName())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,80 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
import static org.powermock.api.mockito.PowerMockito.mock;
|
|
||||||
import static org.powermock.api.mockito.PowerMockito.when;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class})
|
|
||||||
public class ActionLoopEnableTest {
|
|
||||||
ActionLoopEnable actionLoopEnable = new ActionLoopEnable();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void friendlyNameTest() {
|
|
||||||
Assert.assertEquals(R.string.enableloop, actionLoopEnable.friendlyName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shortDescriptionTest() {
|
|
||||||
Assert.assertEquals(MainApp.gs(R.string.enableloop), actionLoopEnable.shortDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void iconTest() {
|
|
||||||
Assert.assertEquals(Optional.of(R.drawable.ic_play_circle_outline_24dp), actionLoopEnable.icon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doActionTest() {
|
|
||||||
LoopPlugin.getPlugin().setPluginEnabled(PluginType.LOOP, false);
|
|
||||||
actionLoopEnable.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Assert.assertEquals(true, LoopPlugin.getPlugin().isEnabled(PluginType.LOOP));
|
|
||||||
// another call should keep it enabled
|
|
||||||
actionLoopEnable.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Assert.assertEquals(true, LoopPlugin.getPlugin().isEnabled(PluginType.LOOP));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void prepareTest() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockApplicationContext();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockConfigBuilder();
|
|
||||||
AAPSMocker.mockCommandQueue();
|
|
||||||
|
|
||||||
VirtualPumpPlugin pump = mock(VirtualPumpPlugin.class);
|
|
||||||
when(pump.specialEnableCondition()).thenReturn(true);
|
|
||||||
PumpDescription pumpDescription = new PumpDescription();
|
|
||||||
pumpDescription.isTempBasalCapable = true;
|
|
||||||
when(pump.getPumpDescription()).thenReturn(pumpDescription);
|
|
||||||
when(AAPSMocker.configBuilderPlugin.getActivePump()).thenReturn(pump);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpDescription
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
class ActionLoopEnableTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
lateinit var sut: ActionLoopEnable
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
|
||||||
|
`when`(virtualPumpPlugin.specialEnableCondition()).thenReturn(true)
|
||||||
|
val pumpDescription = PumpDescription().apply { isTempBasalCapable = true }
|
||||||
|
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
|
||||||
|
`when`(configBuilderPlugin.activePump).thenReturn(virtualPumpPlugin)
|
||||||
|
`when`(resourceHelper.gs(R.string.enableloop)).thenReturn("Enable loop")
|
||||||
|
`when`(resourceHelper.gs(R.string.alreadyenabled)).thenReturn("Already enabled")
|
||||||
|
|
||||||
|
sut = ActionLoopEnable(injector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun friendlyNameTest() {
|
||||||
|
Assert.assertEquals(R.string.enableloop, sut.friendlyName())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun shortDescriptionTest() {
|
||||||
|
Assert.assertEquals("Enable loop", sut.shortDescription())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun iconTest() {
|
||||||
|
Assert.assertEquals(R.drawable.ic_play_circle_outline_24dp, sut.icon())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun doActionTest() {
|
||||||
|
`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false)
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {}
|
||||||
|
})
|
||||||
|
Mockito.verify(loopPlugin, Mockito.times(1)).setPluginEnabled(PluginType.LOOP, true)
|
||||||
|
Mockito.verify(configBuilderPlugin, Mockito.times(1)).storeSettings("ActionLoopEnable")
|
||||||
|
|
||||||
|
`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true)
|
||||||
|
|
||||||
|
// another call should keep it disabled, no new invocation
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {}
|
||||||
|
})
|
||||||
|
Mockito.verify(loopPlugin, Mockito.times(1)).setPluginEnabled(PluginType.LOOP, true)
|
||||||
|
Mockito.verify(configBuilderPlugin, Mockito.times(1)).storeSettings("ActionLoopEnable")
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,73 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
import info.nightscout.androidaps.utils.T;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class, NSUpload.class})
|
|
||||||
public class ActionLoopResumeTest {
|
|
||||||
ActionLoopResume actionLoopResume = new ActionLoopResume();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void friendlyNameTest() {
|
|
||||||
Assert.assertEquals(R.string.resumeloop, actionLoopResume.friendlyName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shortDescriptionTest() {
|
|
||||||
Assert.assertEquals("Resume loop", actionLoopResume.shortDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void iconTest() {
|
|
||||||
Assert.assertEquals(Optional.of(R.drawable.ic_replay_24dp), actionLoopResume.icon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doActionTest() {
|
|
||||||
LoopPlugin.getPlugin().suspendTo(DateUtil.now() + T.hours(1).msecs());
|
|
||||||
actionLoopResume.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Assert.assertEquals(false, LoopPlugin.getPlugin().isSuspended());
|
|
||||||
// another call should keep it resumed
|
|
||||||
actionLoopResume.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Assert.assertEquals(false, LoopPlugin.getPlugin().isSuspended());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void prepareTest() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockApplicationContext();
|
|
||||||
AAPSMocker.mockDatabaseHelper();
|
|
||||||
AAPSMocker.mockStrings();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockConfigBuilder();
|
|
||||||
AAPSMocker.mockNSUpload();
|
|
||||||
AAPSMocker.mockCommandQueue();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
class ActionLoopResumeTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
lateinit var sut: ActionLoopResume
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
|
||||||
|
`when`(virtualPumpPlugin.specialEnableCondition()).thenReturn(true)
|
||||||
|
`when`(resourceHelper.gs(R.string.resumeloop)).thenReturn("Resume loop")
|
||||||
|
`when`(resourceHelper.gs(R.string.notsuspended)).thenReturn("Not suspended")
|
||||||
|
|
||||||
|
sut = ActionLoopResume(injector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun friendlyNameTest() {
|
||||||
|
Assert.assertEquals(R.string.resumeloop, sut.friendlyName())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun shortDescriptionTest() {
|
||||||
|
Assert.assertEquals("Resume loop", sut.shortDescription())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun iconTest() {
|
||||||
|
Assert.assertEquals(R.drawable.ic_replay_24dp, sut.icon())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun doActionTest() {
|
||||||
|
`when`(loopPlugin.isSuspended).thenReturn(true)
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {}
|
||||||
|
})
|
||||||
|
Mockito.verify(loopPlugin, Mockito.times(1)).suspendTo(0)
|
||||||
|
Mockito.verify(configBuilderPlugin, Mockito.times(1)).storeSettings("ActionLoopResume")
|
||||||
|
Mockito.verify(loopPlugin, Mockito.times(1)).createOfflineEvent(0)
|
||||||
|
|
||||||
|
// another call should keep it resumed, , no new invocation
|
||||||
|
`when`(loopPlugin.isSuspended).thenReturn(false)
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {}
|
||||||
|
})
|
||||||
|
Mockito.verify(loopPlugin, Mockito.times(1)).suspendTo(0)
|
||||||
|
Mockito.verify(configBuilderPlugin, Mockito.times(1)).storeSettings("ActionLoopResume")
|
||||||
|
Mockito.verify(loopPlugin, Mockito.times(1)).createOfflineEvent(0)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,90 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class, NSUpload.class})
|
|
||||||
public class ActionLoopSuspendTest {
|
|
||||||
ActionLoopSuspend actionLoopSuspend = new ActionLoopSuspend();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void friendlyNameTest() {
|
|
||||||
Assert.assertEquals(R.string.suspendloop, actionLoopSuspend.friendlyName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shortDescriptionTest() {
|
|
||||||
actionLoopSuspend.minutes = new InputDuration(30, InputDuration.TimeUnit.MINUTES);
|
|
||||||
Assert.assertEquals(null, actionLoopSuspend.shortDescription()); // string not in AAPSMocker
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void iconTest() {
|
|
||||||
Assert.assertEquals(Optional.of(R.drawable.ic_pause_circle_outline_24dp), actionLoopSuspend.icon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doActionTest() {
|
|
||||||
actionLoopSuspend.minutes = new InputDuration(30, InputDuration.TimeUnit.MINUTES);
|
|
||||||
|
|
||||||
LoopPlugin.getPlugin().suspendTo(0);
|
|
||||||
actionLoopSuspend.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Assert.assertEquals(true, LoopPlugin.getPlugin().isSuspended());
|
|
||||||
// another call should keep it suspended
|
|
||||||
actionLoopSuspend.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Assert.assertEquals(true, LoopPlugin.getPlugin().isSuspended());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void applyTest() {
|
|
||||||
ActionLoopSuspend a = new ActionLoopSuspend();
|
|
||||||
a.minutes = new InputDuration(20, InputDuration.TimeUnit.MINUTES);
|
|
||||||
ActionLoopSuspend b = new ActionLoopSuspend();
|
|
||||||
b.apply(a);
|
|
||||||
Assert.assertEquals(20, b.minutes.getMinutes());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hasDialogTest() {
|
|
||||||
ActionLoopSuspend a = new ActionLoopSuspend();
|
|
||||||
Assert.assertTrue(a.hasDialog());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void prepareTest() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockApplicationContext();
|
|
||||||
AAPSMocker.mockDatabaseHelper();
|
|
||||||
AAPSMocker.mockStrings();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockConfigBuilder();
|
|
||||||
AAPSMocker.mockNSUpload();
|
|
||||||
AAPSMocker.mockCommandQueue();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.ArgumentMatchers
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
class ActionLoopSuspendTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
lateinit var sut: ActionLoopSuspend
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
|
||||||
|
`when`(virtualPumpPlugin.specialEnableCondition()).thenReturn(true)
|
||||||
|
`when`(configBuilderPlugin.activePump).thenReturn(virtualPumpPlugin)
|
||||||
|
`when`(resourceHelper.gs(R.string.suspendloop)).thenReturn("Suspend loop")
|
||||||
|
`when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.suspendloopforXmin), ArgumentMatchers.anyInt())).thenReturn("Suspend loop for %d min")
|
||||||
|
|
||||||
|
sut = ActionLoopSuspend(injector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun friendlyNameTest() {
|
||||||
|
Assert.assertEquals(R.string.suspendloop, sut.friendlyName())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun shortDescriptionTest() {
|
||||||
|
sut.minutes = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES)
|
||||||
|
Assert.assertEquals("Suspend loop for %d min", sut.shortDescription())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun iconTest() {
|
||||||
|
Assert.assertEquals(R.drawable.ic_pause_circle_outline_24dp, sut.icon())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun doActionTest() {
|
||||||
|
`when`(loopPlugin.isSuspended).thenReturn(false)
|
||||||
|
sut.minutes = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES)
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {}
|
||||||
|
})
|
||||||
|
Mockito.verify(loopPlugin, Mockito.times(1)).suspendLoop(30)
|
||||||
|
|
||||||
|
// another call should keep it suspended, no more invocations
|
||||||
|
`when`(loopPlugin.isSuspended).thenReturn(true)
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {}
|
||||||
|
})
|
||||||
|
Mockito.verify(loopPlugin, Mockito.times(1)).suspendLoop(30)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun applyTest() {
|
||||||
|
val a = ActionLoopSuspend(injector)
|
||||||
|
a.minutes = InputDuration(injector, 20, InputDuration.TimeUnit.MINUTES)
|
||||||
|
val b = ActionLoopSuspend(injector)
|
||||||
|
b.apply(a)
|
||||||
|
Assert.assertEquals(20, b.minutes.getMinutes().toLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun hasDialogTest() {
|
||||||
|
val a = ActionLoopSuspend(injector)
|
||||||
|
Assert.assertTrue(a.hasDialog())
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,80 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputString;
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, SP.class, NSUpload.class})
|
|
||||||
public class ActionNotificationTest {
|
|
||||||
private ActionNotification actionNotification;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void friendlyNameTest() {
|
|
||||||
Assert.assertEquals(R.string.notification, actionNotification.friendlyName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shortDescriptionTest() {
|
|
||||||
actionNotification = new ActionNotification();
|
|
||||||
actionNotification.text = new InputString().setValue("Asd");
|
|
||||||
Assert.assertEquals(null, actionNotification.shortDescription()); // not mocked
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void iconTest() {
|
|
||||||
Assert.assertEquals(Optional.of(R.drawable.ic_notifications), actionNotification.icon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doActionTest() {
|
|
||||||
actionNotification.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Assert.assertTrue(result.success);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hasDialogTest() {
|
|
||||||
Assert.assertTrue(actionNotification.hasDialog());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void toJSONTest() {
|
|
||||||
actionNotification = new ActionNotification();
|
|
||||||
actionNotification.text = new InputString().setValue("Asd");
|
|
||||||
Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionNotification\"}", actionNotification.toJSON());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromJSONTest() {
|
|
||||||
actionNotification = new ActionNotification();
|
|
||||||
actionNotification.fromJSON("{\"text\":\"Asd\"}");
|
|
||||||
Assert.assertEquals("Asd", actionNotification.text.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void prepareTest() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockStrings();
|
|
||||||
AAPSMocker.mockNSUpload();
|
|
||||||
|
|
||||||
actionNotification = new ActionNotification();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputString
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.ArgumentMatchers
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.powermock.api.mockito.PowerMockito
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
@PrepareForTest(NSUpload::class)
|
||||||
|
class ActionNotificationTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
private lateinit var sut: ActionNotification
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
PowerMockito.mockStatic(NSUpload::class.java)
|
||||||
|
`when`(resourceHelper.gs(R.string.notification)).thenReturn("Notification")
|
||||||
|
`when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.notification_message), ArgumentMatchers.anyString())).thenReturn("Notification: %s")
|
||||||
|
|
||||||
|
sut = ActionNotification(injector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun friendlyNameTest() {
|
||||||
|
Assert.assertEquals(R.string.notification, sut.friendlyName())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun shortDescriptionTest() {
|
||||||
|
sut.text = InputString(injector, "Asd")
|
||||||
|
Assert.assertEquals("Notification: %s", sut.shortDescription())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun iconTest() {
|
||||||
|
Assert.assertEquals(R.drawable.ic_notifications, sut.icon())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun doActionTest() {
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertTrue(result.success)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Mockito.verify(rxBus, Mockito.times(2)).send(anyObject())
|
||||||
|
PowerMockito.verifyStatic(NSUpload::class.java, Mockito.times(1))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun hasDialogTest() {
|
||||||
|
Assert.assertTrue(sut.hasDialog())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun toJSONTest() {
|
||||||
|
sut.text = InputString(injector, "Asd")
|
||||||
|
Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionNotification\"}", sut.toJSON())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun fromJSONTest() {
|
||||||
|
sut.text = InputString(injector, "Asd")
|
||||||
|
sut.fromJSON("{\"text\":\"Asd\"}")
|
||||||
|
Assert.assertEquals("Asd", sut.text.value)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,84 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
|
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputPercent;
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, SP.class, ProfileFunctions.class})
|
|
||||||
public class ActionProfileSwitchPercentTest {
|
|
||||||
private ActionProfileSwitchPercent actionProfileSwitchPercent;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void friendlyNameTest() {
|
|
||||||
Assert.assertEquals(R.string.profilepercentage, actionProfileSwitchPercent.friendlyName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shortDescriptionTest() {
|
|
||||||
actionProfileSwitchPercent = new ActionProfileSwitchPercent();
|
|
||||||
actionProfileSwitchPercent.pct = new InputPercent().setValue(100);
|
|
||||||
actionProfileSwitchPercent.duration = new InputDuration(30, InputDuration.TimeUnit.MINUTES);
|
|
||||||
Assert.assertNull(actionProfileSwitchPercent.shortDescription()); // not mocked
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void iconTest() {
|
|
||||||
Assert.assertEquals(Optional.of(R.drawable.icon_actions_profileswitch), actionProfileSwitchPercent.icon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doActionTest() {
|
|
||||||
actionProfileSwitchPercent.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Assert.assertTrue(result.success);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hasDialogTest() {
|
|
||||||
Assert.assertTrue(actionProfileSwitchPercent.hasDialog());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void toJSONTest() {
|
|
||||||
actionProfileSwitchPercent = new ActionProfileSwitchPercent();
|
|
||||||
actionProfileSwitchPercent.pct = new InputPercent().setValue(100);
|
|
||||||
actionProfileSwitchPercent.duration = new InputDuration(30, InputDuration.TimeUnit.MINUTES);
|
|
||||||
Assert.assertEquals("{\"data\":{\"percentage\":100,\"durationInMinutes\":30},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitchPercent\"}", actionProfileSwitchPercent.toJSON());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromJSONTest() {
|
|
||||||
actionProfileSwitchPercent = new ActionProfileSwitchPercent();
|
|
||||||
actionProfileSwitchPercent.fromJSON("{\"percentage\":100,\"durationInMinutes\":30}");
|
|
||||||
Assert.assertEquals(100, actionProfileSwitchPercent.pct.getValue(), 0.001d);
|
|
||||||
Assert.assertEquals(30, actionProfileSwitchPercent.duration.getMinutes(), 0.001);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void prepareTest() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockStrings();
|
|
||||||
AAPSMocker.mockProfileFunctions();
|
|
||||||
|
|
||||||
actionProfileSwitchPercent = new ActionProfileSwitchPercent();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputPercent
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
class ActionProfileSwitchPercentTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
private lateinit var sut: ActionProfileSwitchPercent
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
|
||||||
|
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
||||||
|
`when`(resourceHelper.gs(R.string.startprofileforever)).thenReturn("Start profile %d%%")
|
||||||
|
`when`(resourceHelper.gs(R.string.startprofile)).thenReturn("Start profile %d%% for %d min")
|
||||||
|
|
||||||
|
sut = ActionProfileSwitchPercent(injector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun friendlyNameTest() {
|
||||||
|
Assert.assertEquals(R.string.profilepercentage, sut.friendlyName())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun shortDescriptionTest() {
|
||||||
|
sut.pct = InputPercent(injector, 100.0)
|
||||||
|
sut.duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES)
|
||||||
|
Assert.assertNull(sut.shortDescription()) // not mocked
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun iconTest() {
|
||||||
|
Assert.assertEquals(R.drawable.icon_actions_profileswitch, sut.icon())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun doActionTest() {
|
||||||
|
sut.pct = InputPercent(injector, 110.0)
|
||||||
|
sut.duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES)
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertTrue(result.success)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Mockito.verify(treatmentsPlugin, Mockito.times(1)).doProfileSwitch(30, 110, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun hasDialogTest() {
|
||||||
|
Assert.assertTrue(sut.hasDialog())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun toJSONTest() {
|
||||||
|
sut.pct = InputPercent(injector, 100.0)
|
||||||
|
sut.duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES)
|
||||||
|
Assert.assertEquals("{\"data\":{\"percentage\":100,\"durationInMinutes\":30},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitchPercent\"}", sut.toJSON())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun fromJSONTest() {
|
||||||
|
sut.fromJSON("{\"percentage\":100,\"durationInMinutes\":30}")
|
||||||
|
Assert.assertEquals(100.0, sut.pct.value, 0.001)
|
||||||
|
Assert.assertEquals(30.0, sut.duration.getMinutes().toDouble(), 0.001)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,119 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.SPMocker;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
|
||||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.powermock.api.mockito.PowerMockito.when;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, SP.class, TreatmentsPlugin.class, ProfileFunctions.class, ConfigBuilderPlugin.class, NSProfilePlugin.class})
|
|
||||||
public class ActionProfileSwitchTest {
|
|
||||||
TreatmentsPlugin treatmentsPlugin;
|
|
||||||
ProfileSwitch profileAdded;
|
|
||||||
private ActionProfileSwitch actionProfileSwitch;
|
|
||||||
private String stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitch\"}";
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
SPMocker.prepareMock();
|
|
||||||
SP.putString("profile", AAPSMocker.getValidProfileStore().getData().toString());
|
|
||||||
AAPSMocker.mockConfigBuilder();
|
|
||||||
AAPSMocker.mockApplicationContext();
|
|
||||||
AAPSMocker.mockStrings();
|
|
||||||
AAPSMocker.mockTreatmentService();
|
|
||||||
AAPSMocker.mockDatabaseHelper();
|
|
||||||
AAPSMocker.mockProfileFunctions();
|
|
||||||
|
|
||||||
treatmentsPlugin = AAPSMocker.mockTreatmentPlugin();
|
|
||||||
NSProfilePlugin profilePlugin = NSProfilePlugin.getPlugin();
|
|
||||||
when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface())
|
|
||||||
.thenReturn(profilePlugin);
|
|
||||||
|
|
||||||
Mockito.doAnswer(invocation -> {
|
|
||||||
profileAdded = invocation.getArgument(0);
|
|
||||||
return null;
|
|
||||||
}).when(treatmentsPlugin).addToHistoryProfileSwitch(any(ProfileSwitch.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void friendlyName() {
|
|
||||||
actionProfileSwitch = new ActionProfileSwitch();
|
|
||||||
Assert.assertEquals(R.string.profilename, actionProfileSwitch.friendlyName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shortDescriptionTest() {
|
|
||||||
actionProfileSwitch = new ActionProfileSwitch();
|
|
||||||
actionProfileSwitch.inputProfileName.setValue("Test");
|
|
||||||
when(MainApp.gs(anyInt(), anyString())).thenReturn("Change profile to Test");
|
|
||||||
Assert.assertEquals("Change profile to Test", actionProfileSwitch.shortDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doAction() {
|
|
||||||
PowerMockito.when(ProfileFunctions.getInstance().getProfileName()).thenReturn("Test");
|
|
||||||
|
|
||||||
actionProfileSwitch = new ActionProfileSwitch();
|
|
||||||
actionProfileSwitch.inputProfileName.setValue("someOtherProfile");
|
|
||||||
actionProfileSwitch.profileName = "someProfile";
|
|
||||||
|
|
||||||
actionProfileSwitch.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Assert.assertTrue(result.success);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hasDialogTest() {
|
|
||||||
actionProfileSwitch = new ActionProfileSwitch();
|
|
||||||
Assert.assertTrue(actionProfileSwitch.hasDialog());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void toJSONTest() {
|
|
||||||
actionProfileSwitch = new ActionProfileSwitch();
|
|
||||||
actionProfileSwitch.inputProfileName.setValue("Test");
|
|
||||||
Assert.assertEquals(stringJson, actionProfileSwitch.toJSON());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromJSONTest() {
|
|
||||||
String data = "{\"profileToSwitchTo\":\"Test\"}";
|
|
||||||
actionProfileSwitch = new ActionProfileSwitch();
|
|
||||||
actionProfileSwitch.fromJSON(data);
|
|
||||||
Assert.assertEquals("Test", actionProfileSwitch.profileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void iconTest() {
|
|
||||||
actionProfileSwitch = new ActionProfileSwitch();
|
|
||||||
Assert.assertEquals(Optional.of(R.drawable.icon_actions_profileswitch), actionProfileSwitch.icon());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,133 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import com.google.common.base.Optional
|
||||||
|
import info.AAPSMocker
|
||||||
|
import info.SPMocker
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.db.ProfileSwitch
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputProfileName
|
||||||
|
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
|
||||||
|
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin
|
||||||
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import info.nightscout.androidaps.utils.SP
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.ArgumentMatchers
|
||||||
|
import org.mockito.ArgumentMatchers.anyLong
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.mockito.Mockito.anyInt
|
||||||
|
import org.mockito.Mockito.anyString
|
||||||
|
import org.mockito.invocation.InvocationOnMock
|
||||||
|
import org.powermock.api.mockito.PowerMockito
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
@PrepareForTest(LocalProfilePlugin::class)
|
||||||
|
class ActionProfileSwitchTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
private lateinit var sut: ActionProfileSwitch
|
||||||
|
|
||||||
|
private val stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitch\"}"
|
||||||
|
|
||||||
|
@Before fun setUp() {
|
||||||
|
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
||||||
|
`when`(resourceHelper.gs(R.string.profilename)).thenReturn("Change profile to")
|
||||||
|
`when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.changengetoprofilename), ArgumentMatchers.anyString())).thenReturn("Change profile to %s")
|
||||||
|
`when`(resourceHelper.gs(R.string.alreadyset)).thenReturn("Already set")
|
||||||
|
`when`(resourceHelper.gs(R.string.notexists)).thenReturn("not exists")
|
||||||
|
`when`(resourceHelper.gs(R.string.ok)).thenReturn("OK")
|
||||||
|
|
||||||
|
sut = ActionProfileSwitch(injector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun friendlyName() {
|
||||||
|
Assert.assertEquals(R.string.profilename, sut.friendlyName())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun shortDescriptionTest() {
|
||||||
|
Assert.assertEquals("Change profile to %s", sut.shortDescription())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun doAction() {
|
||||||
|
//Empty input
|
||||||
|
`when`(profileFunction.getProfileName()).thenReturn("Test")
|
||||||
|
sut.inputProfileName = InputProfileName(injector, "")
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertFalse(result.success)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
//Not initialized profileStore
|
||||||
|
`when`(profileFunction.getProfile()).thenReturn(null)
|
||||||
|
sut.inputProfileName = InputProfileName(injector, "someProfile")
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertFalse(result.success)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
//profile already set
|
||||||
|
`when`(profileFunction.getProfile()).thenReturn(validProfile)
|
||||||
|
`when`(profileFunction.getProfileName()).thenReturn("Test")
|
||||||
|
sut.inputProfileName = InputProfileName(injector, "Test")
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertTrue(result.success)
|
||||||
|
Assert.assertEquals("Already set", result.comment)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// profile doesn't exists
|
||||||
|
`when`(activePlugin.activeProfileInterface).thenReturn(localProfilePlugin)
|
||||||
|
`when`(localProfilePlugin.profile).thenReturn(getValidProfileStore())
|
||||||
|
`when`(profileFunction.getProfileName()).thenReturn("Active")
|
||||||
|
sut.inputProfileName = InputProfileName(injector, "Test")
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertFalse(result.success)
|
||||||
|
Assert.assertEquals("not exists", result.comment)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// do profileswitch
|
||||||
|
`when`(activePlugin.activeProfileInterface).thenReturn(localProfilePlugin)
|
||||||
|
`when`(localProfilePlugin.profile).thenReturn(getValidProfileStore())
|
||||||
|
`when`(profileFunction.getProfileName()).thenReturn("Test")
|
||||||
|
sut.inputProfileName = InputProfileName(injector, TESTPROFILENAME)
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertTrue(result.success)
|
||||||
|
Assert.assertEquals("OK", result.comment)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Mockito.verify(treatmentsPlugin, Mockito.times(1)).doProfileSwitch(anyObject(), anyString(), anyInt(), anyInt(), anyInt(), anyLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun hasDialogTest() {
|
||||||
|
Assert.assertTrue(sut.hasDialog())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun toJSONTest() {
|
||||||
|
sut.inputProfileName = InputProfileName(injector, "Test")
|
||||||
|
Assert.assertEquals(stringJson, sut.toJSON())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun fromJSONTest() {
|
||||||
|
val data = "{\"profileToSwitchTo\":\"Test\"}"
|
||||||
|
sut.fromJSON(data)
|
||||||
|
Assert.assertEquals("Test", sut.inputProfileName.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun iconTest() {
|
||||||
|
Assert.assertEquals(R.drawable.icon_actions_profileswitch, sut.icon())
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,86 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
|
||||||
|
|
||||||
import android.telephony.SmsManager;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputString;
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
import static org.powermock.api.mockito.PowerMockito.mock;
|
|
||||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, SP.class, SmsManager.class})
|
|
||||||
public class ActionSendSMSTest {
|
|
||||||
private ActionSendSMS actionSendSMS;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void friendlyNameTest() {
|
|
||||||
Assert.assertEquals(R.string.sendsmsactiondescription, actionSendSMS.friendlyName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shortDescriptionTest() {
|
|
||||||
actionSendSMS = new ActionSendSMS();
|
|
||||||
Assert.assertEquals(null, actionSendSMS.shortDescription()); // not mocked
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void iconTest() {
|
|
||||||
Assert.assertEquals(Optional.of(R.drawable.ic_notifications), actionSendSMS.icon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doActionTest() {
|
|
||||||
actionSendSMS.text = new InputString().setValue("Asd");
|
|
||||||
actionSendSMS.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Assert.assertTrue(result.success);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hasDialogTest() {
|
|
||||||
Assert.assertTrue(actionSendSMS.hasDialog());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void toJSONTest() {
|
|
||||||
actionSendSMS = new ActionSendSMS();
|
|
||||||
actionSendSMS.text = new InputString().setValue("Asd");
|
|
||||||
Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS\"}", actionSendSMS.toJSON());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromJSONTest() {
|
|
||||||
actionSendSMS = new ActionSendSMS();
|
|
||||||
actionSendSMS.fromJSON("{\"text\":\"Asd\"}");
|
|
||||||
Assert.assertEquals("Asd", actionSendSMS.text.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void prepareTest() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
mockStatic(SmsManager.class);
|
|
||||||
SmsManager smsManager = mock(SmsManager.class);
|
|
||||||
PowerMockito.when(SmsManager.getDefault()).thenReturn(smsManager);
|
|
||||||
PowerMockito.when(SP.getString(R.string.key_smscommunicator_allowednumbers, "")).thenReturn("1234;5678");
|
|
||||||
actionSendSMS = new ActionSendSMS();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputString
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.ArgumentMatchers.anyString
|
||||||
|
import org.mockito.ArgumentMatchers.eq
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
class ActionSendSMSTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
private lateinit var sut: ActionSendSMS
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
|
||||||
|
`when`(resourceHelper.gs(eq(R.string.sendsmsactionlabel), anyString())).thenReturn("Send SMS: %s")
|
||||||
|
`when`(resourceHelper.gs(R.string.sendsmsactiondescription)).thenReturn("Send SMS to all numbers")
|
||||||
|
|
||||||
|
sut = ActionSendSMS(injector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun friendlyNameTest() {
|
||||||
|
Assert.assertEquals(R.string.sendsmsactiondescription, sut.friendlyName())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun shortDescriptionTest() {
|
||||||
|
Assert.assertEquals("Send SMS: %s", sut.shortDescription())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun iconTest() {
|
||||||
|
Assert.assertEquals(R.drawable.ic_notifications, sut.icon())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun doActionTest() {
|
||||||
|
`when`(smsCommunicatorPlugin.sendNotificationToAllNumbers(anyString())).thenReturn(true)
|
||||||
|
sut.text = InputString(injector, "Asd")
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertTrue(result.success)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun hasDialogTest() {
|
||||||
|
Assert.assertTrue(sut.hasDialog())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun toJSONTest() {
|
||||||
|
sut.text = InputString(injector, "Asd")
|
||||||
|
Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS\"}", sut.toJSON())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun fromJSONTest() {
|
||||||
|
sut.fromJSON("{\"text\":\"Asd\"}")
|
||||||
|
Assert.assertEquals("Asd", sut.text.value)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,103 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.nightscout.androidaps.Constants;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
|
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget;
|
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, SP.class, TreatmentsPlugin.class, ProfileFunctions.class})
|
|
||||||
public class ActionStartTempTargetTest {
|
|
||||||
private ActionStartTempTarget actionStartTempTarget;
|
|
||||||
private TreatmentsPlugin treatmentsPlugin;
|
|
||||||
private TempTarget tempTargetAdded;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void friendlyNameTest() {
|
|
||||||
Assert.assertEquals(R.string.starttemptarget, actionStartTempTarget.friendlyName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shortDescriptionTest() {
|
|
||||||
actionStartTempTarget = new ActionStartTempTarget();
|
|
||||||
actionStartTempTarget.reason = "Test";
|
|
||||||
actionStartTempTarget.value = new InputTempTarget().setValue(100).setUnits(Constants.MGDL);
|
|
||||||
actionStartTempTarget.duration = new InputDuration(30, InputDuration.TimeUnit.MINUTES);
|
|
||||||
Assert.assertEquals("Start temp target: 100mg/dl@null(Test)", actionStartTempTarget.shortDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void iconTest() {
|
|
||||||
Assert.assertEquals(Optional.of(R.drawable.icon_cp_cgm_target), actionStartTempTarget.icon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doActionTest() {
|
|
||||||
|
|
||||||
actionStartTempTarget.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Assert.assertNotEquals(null, tempTargetAdded);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hasDialogTest() {
|
|
||||||
Assert.assertTrue(actionStartTempTarget.hasDialog());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void toJSONTest() {
|
|
||||||
actionStartTempTarget = new ActionStartTempTarget();
|
|
||||||
actionStartTempTarget.reason = "Test";
|
|
||||||
actionStartTempTarget.value = new InputTempTarget().setValue(100).setUnits(Constants.MGDL);
|
|
||||||
actionStartTempTarget.duration = new InputDuration(30, InputDuration.TimeUnit.MINUTES);
|
|
||||||
Assert.assertEquals("{\"data\":{\"reason\":\"Test\",\"durationInMinutes\":30,\"units\":\"mg/dl\",\"value\":100},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget\"}", actionStartTempTarget.toJSON());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromJSONTest() {
|
|
||||||
actionStartTempTarget = new ActionStartTempTarget();
|
|
||||||
actionStartTempTarget.fromJSON("{\"reason\":\"Test\",\"value\":100,\"durationInMinutes\":30,\"units\":\"mg/dl\"}");
|
|
||||||
Assert.assertEquals(Constants.MGDL, actionStartTempTarget.value.getUnits());
|
|
||||||
Assert.assertEquals(100, actionStartTempTarget.value.getValue(), 0.001d);
|
|
||||||
Assert.assertEquals(30, actionStartTempTarget.duration.getMinutes(), 0.001);
|
|
||||||
Assert.assertEquals("Test", actionStartTempTarget.reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void prepareTest() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockStrings();
|
|
||||||
AAPSMocker.mockProfileFunctions();
|
|
||||||
treatmentsPlugin = AAPSMocker.mockTreatmentPlugin();
|
|
||||||
|
|
||||||
Mockito.doAnswer(invocation -> {
|
|
||||||
tempTargetAdded = invocation.getArgument(0);
|
|
||||||
return null;
|
|
||||||
}).when(treatmentsPlugin).addToHistoryTempTarget(any(TempTarget.class));
|
|
||||||
|
|
||||||
actionStartTempTarget = new ActionStartTempTarget();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import info.AAPSMocker
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
@PrepareForTest(MainApp::class)
|
||||||
|
class ActionStartTempTargetTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
private lateinit var sut: ActionStartTempTarget
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
AAPSMocker.mockMainApp()
|
||||||
|
`when`(resourceHelper.gs(R.string.starttemptarget)).thenReturn("Start temp target")
|
||||||
|
|
||||||
|
sut = ActionStartTempTarget(injector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun friendlyNameTest() {
|
||||||
|
Assert.assertEquals(R.string.starttemptarget, sut.friendlyName())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun shortDescriptionTest() {
|
||||||
|
sut.value = InputTempTarget(injector)
|
||||||
|
sut.value.value = 100.0
|
||||||
|
sut.duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES)
|
||||||
|
Assert.assertEquals("Start temp target: 100mg/dl@null(Automation)", sut.shortDescription())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun iconTest() {
|
||||||
|
Assert.assertEquals(R.drawable.icon_cp_cgm_target, sut.icon())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun doActionTest() {
|
||||||
|
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertTrue(result.success)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Mockito.verify(treatmentsPlugin, Mockito.times(1)).addToHistoryTempTarget(anyObject())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun hasDialogTest() {
|
||||||
|
Assert.assertTrue(sut.hasDialog())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun toJSONTest() {
|
||||||
|
sut.value = InputTempTarget(injector)
|
||||||
|
sut.value.value = 100.0
|
||||||
|
sut.duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES)
|
||||||
|
Assert.assertEquals("{\"data\":{\"durationInMinutes\":30,\"units\":\"mg/dl\",\"value\":100},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget\"}", sut.toJSON())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun fromJSONTest() {
|
||||||
|
sut.fromJSON("{\"value\":100,\"durationInMinutes\":30,\"units\":\"mg/dl\"}")
|
||||||
|
Assert.assertEquals(Constants.MGDL, sut.value.units)
|
||||||
|
Assert.assertEquals(100.0, sut.value.value, 0.001)
|
||||||
|
Assert.assertEquals(30.0, sut.duration.getMinutes().toDouble(), 0.001)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,87 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, SP.class, TreatmentsPlugin.class})
|
|
||||||
public class ActionStopTempTargetTest {
|
|
||||||
ActionStopTempTarget actionStopTempTarget = new ActionStopTempTarget();
|
|
||||||
TreatmentsPlugin treatmentsPlugin;
|
|
||||||
TempTarget tempTargetAdded;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void friendlyNameTest() {
|
|
||||||
Assert.assertEquals(R.string.stoptemptarget, actionStopTempTarget.friendlyName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shortDescriptionTest() {
|
|
||||||
Assert.assertEquals("Stop temp target", actionStopTempTarget.shortDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void iconTest() {
|
|
||||||
Assert.assertEquals(Optional.of(R.drawable.ic_stop_24dp), actionStopTempTarget.icon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doActionTest() {
|
|
||||||
|
|
||||||
actionStopTempTarget.doAction(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Assert.assertNotEquals(null, tempTargetAdded);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hasDialogTest() {
|
|
||||||
Assert.assertFalse(actionStopTempTarget.hasDialog());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void toJSONTest() {
|
|
||||||
actionStopTempTarget = new ActionStopTempTarget();
|
|
||||||
actionStopTempTarget.reason = "Test";
|
|
||||||
Assert.assertEquals("{\"data\":{\"reason\":\"Test\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionStopTempTarget\"}", actionStopTempTarget.toJSON());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromJSONTest() {
|
|
||||||
actionStopTempTarget = new ActionStopTempTarget();
|
|
||||||
actionStopTempTarget.fromJSON("{\"reason\":\"Test\"}");
|
|
||||||
Assert.assertEquals("Test", actionStopTempTarget.reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void prepareTest() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockStrings();
|
|
||||||
treatmentsPlugin = AAPSMocker.mockTreatmentPlugin();
|
|
||||||
|
|
||||||
Mockito.doAnswer(invocation -> {
|
|
||||||
tempTargetAdded = invocation.getArgument(0);
|
|
||||||
return null;
|
|
||||||
}).when(treatmentsPlugin).addToHistoryTempTarget(any(TempTarget.class));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import info.AAPSMocker
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
@PrepareForTest(MainApp::class)
|
||||||
|
class ActionStopTempTargetTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
private lateinit var sut: ActionStopTempTarget
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
AAPSMocker.mockMainApp()
|
||||||
|
`when`(resourceHelper.gs(R.string.stoptemptarget)).thenReturn("Stop temp target")
|
||||||
|
|
||||||
|
sut = ActionStopTempTarget(injector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun friendlyNameTest() {
|
||||||
|
Assert.assertEquals(R.string.stoptemptarget, sut.friendlyName())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun shortDescriptionTest() {
|
||||||
|
Assert.assertEquals("Stop temp target", sut.shortDescription())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun iconTest() {
|
||||||
|
Assert.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun doActionTest() {
|
||||||
|
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertTrue(result.success)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Mockito.verify(treatmentsPlugin, Mockito.times(1)).addToHistoryTempTarget(anyObject())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun hasDialogTest() {
|
||||||
|
Assert.assertFalse(sut.hasDialog())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun toJSONTest() {
|
||||||
|
Assert.assertEquals("{\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionStopTempTarget\"}", sut.toJSON())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun fromJSONTest() {
|
||||||
|
sut.fromJSON("{\"reason\":\"Test\"}")
|
||||||
|
Assert.assertNotNull(sut)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,60 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({})
|
|
||||||
public class ActionTest extends Action {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int friendlyName() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String shortDescription() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doAction(Callback callback) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Integer> icon() {
|
|
||||||
return Optional.absent();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hasDialogTest() {
|
|
||||||
Assert.assertEquals(false, hasDialog());
|
|
||||||
generateDialog(null); // coverage only
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void toJSONTest() {
|
|
||||||
Assert.assertEquals("{\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionTest\"}", toJSON());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromJSONTest() {
|
|
||||||
Assert.assertEquals(this, fromJSON("any"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void instantiateTest() throws JSONException {
|
|
||||||
Action action = Action.instantiate(new JSONObject("{\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionTest\"}"));
|
|
||||||
Assert.assertNotEquals(null, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
@PrepareForTest
|
||||||
|
class ActionTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun instantiateTest() {
|
||||||
|
val action: Action? = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy\"}"))
|
||||||
|
Assert.assertNotEquals(null, action)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import dagger.android.AndroidInjector
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.TestBase
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
|
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
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.configBuilder.ProfileFunction
|
||||||
|
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.plugins.treatments.TreatmentsPlugin
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
|
||||||
|
@PrepareForTest(VirtualPumpPlugin::class, RxBusWrapper::class, LocalProfilePlugin::class, SmsCommunicatorPlugin::class)
|
||||||
|
open class ActionsTestBase : TestBase() {
|
||||||
|
|
||||||
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
|
@Mock lateinit var rxBus: RxBusWrapper
|
||||||
|
@Mock lateinit var sp: SP
|
||||||
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
@Mock lateinit var commandQueue: CommandQueueProvider
|
||||||
|
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||||
|
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
|
||||||
|
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||||
|
@Mock lateinit var loopPlugin: LoopPlugin
|
||||||
|
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||||
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
|
@Mock lateinit var localProfilePlugin : LocalProfilePlugin
|
||||||
|
@Mock lateinit var smsCommunicatorPlugin : SmsCommunicatorPlugin
|
||||||
|
|
||||||
|
var injector: HasAndroidInjector = HasAndroidInjector {
|
||||||
|
AndroidInjector {
|
||||||
|
if (it is ActionStopTempTarget) {
|
||||||
|
it.aapsLogger = aapsLogger
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.activePlugin = activePlugin
|
||||||
|
}
|
||||||
|
if (it is ActionStartTempTarget) {
|
||||||
|
it.aapsLogger = aapsLogger
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.activePlugin = activePlugin
|
||||||
|
}
|
||||||
|
if (it is ActionSendSMS) {
|
||||||
|
it.aapsLogger = aapsLogger
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.smsCommunicatorPlugin = smsCommunicatorPlugin
|
||||||
|
}
|
||||||
|
if (it is ActionProfileSwitch) {
|
||||||
|
it.aapsLogger = aapsLogger
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.activePlugin = activePlugin
|
||||||
|
it.profileFunction = profileFunction
|
||||||
|
}
|
||||||
|
if (it is ActionProfileSwitchPercent) {
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.activePlugin = activePlugin
|
||||||
|
}
|
||||||
|
if (it is ActionNotification) {
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.rxBus = rxBus
|
||||||
|
}
|
||||||
|
if (it is ActionLoopSuspend) {
|
||||||
|
it.loopPlugin = loopPlugin
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.rxBus = rxBus
|
||||||
|
}
|
||||||
|
if (it is ActionLoopResume) {
|
||||||
|
it.loopPlugin = loopPlugin
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.configBuilderPlugin = configBuilderPlugin
|
||||||
|
it.rxBus = rxBus
|
||||||
|
}
|
||||||
|
if (it is ActionLoopEnable) {
|
||||||
|
it.loopPlugin = loopPlugin
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.configBuilderPlugin = configBuilderPlugin
|
||||||
|
it.rxBus = rxBus
|
||||||
|
}
|
||||||
|
if (it is ActionLoopDisable) {
|
||||||
|
it.loopPlugin = loopPlugin
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.configBuilderPlugin = configBuilderPlugin
|
||||||
|
it.commandQueue = commandQueue
|
||||||
|
it.rxBus = rxBus
|
||||||
|
}
|
||||||
|
if (it is PumpEnactResult) {
|
||||||
|
it.aapsLogger = aapsLogger
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue