Action:applyTest

This commit is contained in:
Milos Kozak 2019-03-30 23:08:25 +01:00
parent e5dc655c64
commit bad6edfb8b
2 changed files with 38 additions and 0 deletions

View file

@ -2,6 +2,9 @@ package info.nightscout.androidaps.plugins.general.automation.actions;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import org.json.JSONException;
import org.json.JSONObject;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
@ -34,4 +37,30 @@ public class ActionLoopSuspend extends Action {
public Optional<Integer> icon() { public Optional<Integer> icon() {
return Optional.of(R.drawable.ic_pause_circle_outline_24dp); return Optional.of(R.drawable.ic_pause_circle_outline_24dp);
} }
@Override
public String toJSON() {
JSONObject o = new JSONObject();
JSONObject data = new JSONObject();
try {
data.put("minutes", minutes);
o.put("type", this.getClass().getName());
o.put("data", data);
} catch (JSONException e) {
e.printStackTrace();
}
return o.toString();
}
@Override
public Action fromJSON(String data) {
try {
JSONObject o = new JSONObject(data);
minutes = o.getInt("minutes");
} catch (JSONException e) {
e.printStackTrace();
}
return this;
}
} }

View file

@ -59,6 +59,15 @@ public class ActionLoopSuspendTest {
Assert.assertEquals(true, LoopPlugin.getPlugin().isSuspended()); Assert.assertEquals(true, LoopPlugin.getPlugin().isSuspended());
} }
@Test
public void applyTest() {
ActionLoopSuspend a = new ActionLoopSuspend();
a.minutes = 20;
ActionLoopSuspend b = new ActionLoopSuspend();
b.apply(a);
Assert.assertEquals(20, b.minutes);
}
@Before @Before
public void prepareTest() { public void prepareTest() {
AAPSMocker.mockMainApp(); AAPSMocker.mockMainApp();