ActionStopTempTarget
This commit is contained in:
parent
5a555cdfba
commit
dc0846eab9
11 changed files with 184 additions and 20 deletions
|
@ -32,10 +32,6 @@ public class ActionStartTempTarget extends Action {
|
|||
value = new InputBg(Constants.MGDL);
|
||||
}
|
||||
|
||||
public ActionStartTempTarget(String units) {
|
||||
value = new InputBg(units);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int friendlyName() {
|
||||
return R.string.starttemptarget;
|
||||
|
@ -43,7 +39,7 @@ public class ActionStartTempTarget extends Action {
|
|||
|
||||
@Override
|
||||
public String shortDescription() {
|
||||
return MainApp.gs(R.string.resumeloop) + ": " + tempTarget.toString();
|
||||
return MainApp.gs(R.string.starttemptarget) + ": " + (tempTarget == null ? "null" : tempTarget.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
|
||||
public class ActionStopTempTarget extends Action {
|
||||
String reason = "";
|
||||
TempTarget tempTarget;
|
||||
|
||||
public ActionStopTempTarget() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int friendlyName() {
|
||||
return R.string.stoptemptarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String shortDescription() {
|
||||
return MainApp.gs(R.string.stoptemptarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(Callback callback) {
|
||||
tempTarget = new TempTarget().date(DateUtil.now()).duration(0).reason(reason).source(Source.USER).low(0).high(0);
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||
if (callback != null)
|
||||
callback.result(new PumpEnactResult().success(true).comment(R.string.ok)).run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDialog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JSONObject o = new JSONObject();
|
||||
try {
|
||||
o.put("type", ActionStopTempTarget.class.getName());
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("reason", reason);
|
||||
o.put("data", data);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action fromJSON(String data) {
|
||||
try {
|
||||
JSONObject d = new JSONObject(data);
|
||||
reason = JsonHelper.safeGetString(d, "reason");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Integer> icon() {
|
||||
return Optional.of(R.drawable.ic_stop_24dp);
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopE
|
|||
import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopResume;
|
||||
import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopSuspend;
|
||||
import info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget;
|
||||
import info.nightscout.androidaps.plugins.general.automation.actions.ActionStopTempTarget;
|
||||
|
||||
public class ChooseActionDialog extends DialogFragment {
|
||||
|
||||
|
@ -38,6 +39,7 @@ public class ChooseActionDialog extends DialogFragment {
|
|||
add(new ActionLoopResume());
|
||||
add(new ActionLoopSuspend());
|
||||
add(new ActionStartTempTarget());
|
||||
add(new ActionStopTempTarget());
|
||||
}};
|
||||
|
||||
private Unbinder mUnbinder;
|
||||
|
|
|
@ -1330,6 +1330,7 @@
|
|||
<string name="resumeloop">Resume loop</string>
|
||||
<string name="notsuspended">Not suspended</string>
|
||||
<string name="starttemptarget">Start temp target</string>
|
||||
<string name="stoptemptarget">Stop temp target</string>
|
||||
<string name="islesser">is lesser than</string>
|
||||
<string name="isequalorlesser">is equal or lesser than</string>
|
||||
<string name="isequal">is equal to</string>
|
||||
|
|
|
@ -151,6 +151,12 @@ public class AAPSMocker {
|
|||
when(MainApp.gs(R.string.pumpsuspended)).thenReturn("Pump suspended");
|
||||
when(MainApp.gs(R.string.cob)).thenReturn("COB");
|
||||
when(MainApp.gs(R.string.value_unavailable_short)).thenReturn("n/a");
|
||||
when(MainApp.gs(R.string.starttemptarget)).thenReturn("Start temp target");
|
||||
when(MainApp.gs(R.string.stoptemptarget)).thenReturn("Stop temp target");
|
||||
when(MainApp.gs(R.string.disableloop)).thenReturn("Disable loop");
|
||||
when(MainApp.gs(R.string.enableloop)).thenReturn("Enable loop");
|
||||
when(MainApp.gs(R.string.resumeloop)).thenReturn("Resume loop");
|
||||
when(MainApp.gs(R.string.suspendloop)).thenReturn("Suspend loop");
|
||||
}
|
||||
|
||||
public static MainApp mockMainApp() {
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ActionLoopDisableTest {
|
|||
|
||||
@Test
|
||||
public void shortDescriptionTest() {
|
||||
Assert.assertEquals(R.string.disableloop, actionLoopDisable.friendlyName());
|
||||
Assert.assertEquals("Disable loop", actionLoopDisable.shortDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -69,6 +69,7 @@ public class ActionLoopDisableTest {
|
|||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockConfigBuilder();
|
||||
AAPSMocker.mockCommandQueue();
|
||||
AAPSMocker.mockStrings();
|
||||
|
||||
VirtualPumpPlugin pump = mock(VirtualPumpPlugin.class);
|
||||
when(pump.specialEnableCondition()).thenReturn(true);
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ActionLoopEnableTest {
|
|||
|
||||
@Test
|
||||
public void shortDescriptionTest() {
|
||||
Assert.assertEquals(R.string.enableloop, actionLoopEnable.friendlyName());
|
||||
Assert.assertEquals(MainApp.gs(R.string.enableloop), actionLoopEnable.shortDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -32,7 +32,7 @@ public class ActionLoopResumeTest {
|
|||
|
||||
@Test
|
||||
public void shortDescriptionTest() {
|
||||
Assert.assertEquals(R.string.resumeloop, actionLoopResume.friendlyName());
|
||||
Assert.assertEquals("Resume loop", actionLoopResume.shortDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -62,6 +62,7 @@ public class ActionLoopResumeTest {
|
|||
public void prepareTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockStrings();
|
||||
AAPSMocker.mockBus();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockConfigBuilder();
|
||||
|
|
|
@ -36,7 +36,7 @@ public class ActionLoopSuspendTest {
|
|||
|
||||
@Test
|
||||
public void shortDescriptionTest() {
|
||||
Assert.assertEquals(R.string.suspendloop, actionLoopSuspend.friendlyName());
|
||||
Assert.assertEquals("Suspend loop", actionLoopSuspend.shortDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -77,6 +77,7 @@ public class ActionLoopSuspendTest {
|
|||
public void prepareTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockStrings();
|
||||
AAPSMocker.mockBus();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockConfigBuilder();
|
||||
|
|
|
@ -43,7 +43,7 @@ public class ActionStartTempTargetTest {
|
|||
|
||||
@Test
|
||||
public void shortDescriptionTest() {
|
||||
Assert.assertEquals(R.string.starttemptarget, actionStartTempTarget.friendlyName());
|
||||
Assert.assertEquals("Start temp target: null", actionStartTempTarget.shortDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -62,15 +62,6 @@ public class ActionStartTempTargetTest {
|
|||
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());
|
||||
|
@ -89,7 +80,7 @@ public class ActionStartTempTargetTest {
|
|||
@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\"");
|
||||
actionStartTempTarget.fromJSON("{\"reason\":\"Test\",\"valueInMg\":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);
|
||||
|
@ -99,6 +90,7 @@ public class ActionStartTempTargetTest {
|
|||
public void prepareTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockStrings();
|
||||
treatmentsPlugin = AAPSMocker.mockTreatmentPlugin();
|
||||
|
||||
Mockito.doAnswer(invocation -> {
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
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));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue