ActionStartTempTargetTest
This commit is contained in:
parent
6a365b3483
commit
350e23647e
|
@ -23,9 +23,9 @@ import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.JsonHelper;
|
import info.nightscout.androidaps.utils.JsonHelper;
|
||||||
|
|
||||||
public class ActionStartTempTarget extends Action {
|
public class ActionStartTempTarget extends Action {
|
||||||
private String reason = "";
|
String reason = "";
|
||||||
private InputBg value;
|
InputBg value;
|
||||||
private InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
||||||
|
|
||||||
public ActionStartTempTarget() {
|
public ActionStartTempTarget() {
|
||||||
value = new InputBg(Constants.MGDL);
|
value = new InputBg(Constants.MGDL);
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
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.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputBg;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
|
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.anyDouble;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({MainApp.class, SP.class, TreatmentsPlugin.class})
|
||||||
|
public class ActionStartTempTargetTest {
|
||||||
|
ActionStartTempTarget actionStartTempTarget = new ActionStartTempTarget();
|
||||||
|
TreatmentsPlugin treatmentsPlugin;
|
||||||
|
TempTarget tempTargetAdded;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void friendlyNameTest() {
|
||||||
|
Assert.assertEquals(R.string.starttemptarget, actionStartTempTarget.friendlyName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 applyTest() {
|
||||||
|
ActionLoopSuspend a = new ActionLoopSuspend();
|
||||||
|
a.minutes = 20;
|
||||||
|
ActionLoopSuspend b = new ActionLoopSuspend();
|
||||||
|
b.apply(a);
|
||||||
|
Assert.assertEquals(20, b.minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hasDialogTest() {
|
||||||
|
Assert.assertTrue(actionStartTempTarget.hasDialog());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toJSONTest() {
|
||||||
|
actionStartTempTarget = new ActionStartTempTarget();
|
||||||
|
actionStartTempTarget.reason = "Test";
|
||||||
|
actionStartTempTarget.value = new InputBg(Constants.MGDL);
|
||||||
|
actionStartTempTarget.value.setMgdl(100);
|
||||||
|
actionStartTempTarget.duration = new InputDuration(30, InputDuration.TimeUnit.MINUTES);
|
||||||
|
Assert.assertEquals("{\"data\":{\"reason\":\"Test\",\"valueInMg\":100,\"durationInMinutes\":30,\"units\":\"mg/dl\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget\"}", actionStartTempTarget.toJSON());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fromJSONTest() {
|
||||||
|
actionStartTempTarget = new ActionStartTempTarget();
|
||||||
|
actionStartTempTarget.fromJSON("{\"reason\":\"Test\",\"valueInMg\":100,\"durationInMinutes\":30,\"units\":\"mg/dl\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget\"");
|
||||||
|
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();
|
||||||
|
treatmentsPlugin = AAPSMocker.mockTreatmentPlugin();
|
||||||
|
|
||||||
|
Mockito.doAnswer(invocation -> {
|
||||||
|
tempTargetAdded = invocation.getArgument(0);
|
||||||
|
return null;
|
||||||
|
}).when(treatmentsPlugin).addToHistoryTempTarget(any(TempTarget.class));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue