From e3d7d4cb679a4369e34f9818e3f6ef8ed89481c0 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Tue, 10 Sep 2019 10:01:36 +0300 Subject: [PATCH] fixed name and tests --- .../general/automation/AutomationPlugin.kt | 2 +- ...erTimeOfDay.java => TriggerTimeRange.java} | 33 ++++++++++--------- app/src/main/res/values/strings.xml | 6 ++-- ...DayTest.java => TriggerTimeRangeTest.java} | 32 +++++++++--------- 4 files changed, 37 insertions(+), 36 deletions(-) rename app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/{TriggerTimeOfDay.java => TriggerTimeRange.java} (89%) rename app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/{TriggerTimeOfDayTest.java => TriggerTimeRangeTest.java} (64%) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt index 475c072a02..6c7850f6f2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt @@ -209,7 +209,7 @@ object AutomationPlugin : PluginBase(PluginDescription() return listOf( TriggerTime(), TriggerRecurringTime(), - TriggerTimeOfDay(), + TriggerTimeRange(), TriggerBg(), TriggerDelta(), TriggerIob(), diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeOfDay.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRange.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeOfDay.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRange.java index b047feff85..8c622fc5f6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeOfDay.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRange.java @@ -30,28 +30,28 @@ import info.nightscout.androidaps.utils.JsonHelper; import info.nightscout.androidaps.utils.T; -// Trigger for time range ( Time of day actually ) +// Trigger for time range ( from 10:00AM till 13:00PM ) -public class TriggerTimeOfDay extends Trigger { +public class TriggerTimeRange extends Trigger { private static Logger log = LoggerFactory.getLogger(L.AUTOMATION); - // in minutes since midnight 6- means 1AM + // in minutes since midnight 60 means 1AM private int start; private int end; private Comparator comparator = new Comparator(); - public TriggerTimeOfDay() { + public TriggerTimeRange() { start = getMinSinceMidnight(DateUtil.now()); end = getMinSinceMidnight(DateUtil.now()); } - private TriggerTimeOfDay(TriggerTimeOfDay triggerTimeOfDay) { + private TriggerTimeRange(TriggerTimeRange triggerTimeRange) { super(); - lastRun = triggerTimeOfDay.lastRun; - start = triggerTimeOfDay.start; - end = triggerTimeOfDay.end; + lastRun = triggerTimeRange.lastRun; + start = triggerTimeRange.start; + end = triggerTimeRange.end; } @Override @@ -92,7 +92,7 @@ public class TriggerTimeOfDay extends Trigger { data.put("start", getMinSinceMidnight(start)); data.put("end", getMinSinceMidnight(end)); data.put("lastRun", lastRun); - object.put("type", TriggerTimeOfDay.class.getName()); + object.put("type", TriggerTimeRange.class.getName()); object.put("data", data); } catch (JSONException e) { e.printStackTrace(); @@ -102,7 +102,7 @@ public class TriggerTimeOfDay extends Trigger { } @Override - TriggerTimeOfDay fromJSON(String data) { + TriggerTimeRange fromJSON(String data) { JSONObject o; try { o = new JSONObject(data); @@ -117,12 +117,12 @@ public class TriggerTimeOfDay extends Trigger { @Override public int friendlyName() { - return R.string.time_of_day; + return R.string.time_range; } @Override public String friendlyDescription() { - return MainApp.gs(R.string.tod_value, DateUtil.timeString(toMilis(start)), DateUtil.timeString(toMilis(end))); + return MainApp.gs(R.string.timerange_value, DateUtil.timeString(toMilis(start)), DateUtil.timeString(toMilis(end))); } @Override @@ -130,19 +130,20 @@ public class TriggerTimeOfDay extends Trigger { return Optional.of(R.drawable.ic_access_alarm_24dp); } - TriggerTimeOfDay start(int start) { + TriggerTimeRange period(int start, int end) { this.start = start; + this.end = end; return this; } - TriggerTimeOfDay lastRun(long lastRun) { + TriggerTimeRange lastRun(long lastRun) { this.lastRun = lastRun; return this; } @Override public Trigger duplicate() { - return new TriggerTimeOfDay(this); + return new TriggerTimeRange(this); } long toMilis(long minutesSinceMidnight) { @@ -220,7 +221,7 @@ public class TriggerTimeOfDay extends Trigger { }); int px = MainApp.dpToPx(10); - label.setText(MainApp.gs(R.string.thanspecifiedtime)); + label.setText(MainApp.gs(R.string.between)); label.setTypeface(label.getTypeface(), Typeface.BOLD); startButton.setPadding(px, px, px, px); endButton.setPadding(px, px, px, px); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b55fda39db..7b5a66b7b8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1605,9 +1605,9 @@ Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm. Loading ... Snooze - Time range - Time is between %1$s and %2$s - Between + Time range + Time is between %1$s and %2$s + Between %1$d day diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeOfDayTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRangeTest.java similarity index 64% rename from app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeOfDayTest.java rename to app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRangeTest.java index 8f49366954..f270964d65 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeOfDayTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRangeTest.java @@ -19,69 +19,69 @@ import info.AAPSMocker; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.T; import static org.powermock.api.mockito.PowerMockito.when; @RunWith(PowerMockRunner.class) @PrepareForTest({MainApp.class, Bus.class, DateUtil.class, GregorianCalendar.class}) -public class TriggerTimeOfDayTest { +public class TriggerTimeRangeTest { int now = 754; - String timeJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"lastRun\":0,\"minSinceMidnight\":753},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTimeOfDay\"}"; + String timeJson = "{\"data\":{\"lastRun\":0,\"start\":753,\"end\":784},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTimeRange\"}"; @Test public void shouldRunTest() { // scheduled 1 min before - TriggerTimeOfDay t = new TriggerTimeOfDay().minSinceMidnight(753); + TriggerTimeRange t; // scheduled 1 min in the future - t = new TriggerTimeOfDay().minSinceMidnight(now + 1); + t = new TriggerTimeRange().period(now + 1, now + 30); Assert.assertFalse(t.shouldRun()); // already run - t = new TriggerTimeOfDay().minSinceMidnight(now - 1).lastRun(now - 1); + t = new TriggerTimeRange().period(now - 1, now + 30).lastRun(now - 1); Assert.assertFalse(t.shouldRun()); } @Test public void toJSONTest() { - TriggerTimeOfDay t = new TriggerTimeOfDay().minSinceMidnight(now - 1); + TriggerTimeRange t = new TriggerTimeRange().period(now - 1, now + 30); Assert.assertEquals(timeJson, t.toJSON()); } @Test public void fromJSONTest() throws JSONException { - TriggerTimeOfDay t = new TriggerTimeOfDay().minSinceMidnight(120); + TriggerTimeRange t = new TriggerTimeRange().period(120 , 180); - TriggerTimeOfDay t2 = (TriggerTimeOfDay) Trigger.instantiate(new JSONObject(t.toJSON())); - Assert.assertEquals(now - 1, t2.minSinceMidnight(753).getMinSinceMidnight()); + TriggerTimeRange t2 = (TriggerTimeRange) Trigger.instantiate(new JSONObject(t.toJSON())); + Assert.assertEquals(now - 1, t2.period(753 , 360).getStart()); + Assert.assertEquals(360, t2.period(753 , 360).getEnd()); } @Test public void copyConstructorTest() { - TriggerTimeOfDay t = new TriggerTimeOfDay(); - t.minSinceMidnight(now); + TriggerTimeRange t = new TriggerTimeRange(); + t.period(now, now + 30); - TriggerTimeOfDay t1 = (TriggerTimeOfDay) t.duplicate(); + TriggerTimeRange t1 = (TriggerTimeRange) t.duplicate(); // Assert.assertEquals(now, t1.getRunAt(), 0.01d); } @Test public void friendlyNameTest() { - Assert.assertEquals(R.string.time_of_day, new TriggerTimeOfDay().friendlyName()); + Assert.assertEquals(R.string.time_range, new TriggerTimeRange().friendlyName()); } @Test public void friendlyDescriptionTest() { - Assert.assertEquals(null, new TriggerTimeOfDay().friendlyDescription()); //not mocked } + Assert.assertEquals(null, new TriggerTimeRange().friendlyDescription()); //not mocked } } @Test public void iconTest() { - Assert.assertEquals(Optional.of(R.drawable.ic_access_alarm_24dp), new TriggerTimeOfDay().icon()); + Assert.assertEquals(Optional.of(R.drawable.ic_access_alarm_24dp), new TriggerTimeRange().icon()); }