fixed name and tests

This commit is contained in:
Roumen Georgiev 2019-09-10 10:01:36 +03:00
parent 8ad35dcc45
commit e3d7d4cb67
4 changed files with 37 additions and 36 deletions

View file

@ -209,7 +209,7 @@ object AutomationPlugin : PluginBase(PluginDescription()
return listOf( return listOf(
TriggerTime(), TriggerTime(),
TriggerRecurringTime(), TriggerRecurringTime(),
TriggerTimeOfDay(), TriggerTimeRange(),
TriggerBg(), TriggerBg(),
TriggerDelta(), TriggerDelta(),
TriggerIob(), TriggerIob(),

View file

@ -30,28 +30,28 @@ import info.nightscout.androidaps.utils.JsonHelper;
import info.nightscout.androidaps.utils.T; 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); 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 start;
private int end; private int end;
private Comparator comparator = new Comparator(); private Comparator comparator = new Comparator();
public TriggerTimeOfDay() { public TriggerTimeRange() {
start = getMinSinceMidnight(DateUtil.now()); start = getMinSinceMidnight(DateUtil.now());
end = getMinSinceMidnight(DateUtil.now()); end = getMinSinceMidnight(DateUtil.now());
} }
private TriggerTimeOfDay(TriggerTimeOfDay triggerTimeOfDay) { private TriggerTimeRange(TriggerTimeRange triggerTimeRange) {
super(); super();
lastRun = triggerTimeOfDay.lastRun; lastRun = triggerTimeRange.lastRun;
start = triggerTimeOfDay.start; start = triggerTimeRange.start;
end = triggerTimeOfDay.end; end = triggerTimeRange.end;
} }
@Override @Override
@ -92,7 +92,7 @@ public class TriggerTimeOfDay extends Trigger {
data.put("start", getMinSinceMidnight(start)); data.put("start", getMinSinceMidnight(start));
data.put("end", getMinSinceMidnight(end)); data.put("end", getMinSinceMidnight(end));
data.put("lastRun", lastRun); data.put("lastRun", lastRun);
object.put("type", TriggerTimeOfDay.class.getName()); object.put("type", TriggerTimeRange.class.getName());
object.put("data", data); object.put("data", data);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@ -102,7 +102,7 @@ public class TriggerTimeOfDay extends Trigger {
} }
@Override @Override
TriggerTimeOfDay fromJSON(String data) { TriggerTimeRange fromJSON(String data) {
JSONObject o; JSONObject o;
try { try {
o = new JSONObject(data); o = new JSONObject(data);
@ -117,12 +117,12 @@ public class TriggerTimeOfDay extends Trigger {
@Override @Override
public int friendlyName() { public int friendlyName() {
return R.string.time_of_day; return R.string.time_range;
} }
@Override @Override
public String friendlyDescription() { 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 @Override
@ -130,19 +130,20 @@ public class TriggerTimeOfDay extends Trigger {
return Optional.of(R.drawable.ic_access_alarm_24dp); return Optional.of(R.drawable.ic_access_alarm_24dp);
} }
TriggerTimeOfDay start(int start) { TriggerTimeRange period(int start, int end) {
this.start = start; this.start = start;
this.end = end;
return this; return this;
} }
TriggerTimeOfDay lastRun(long lastRun) { TriggerTimeRange lastRun(long lastRun) {
this.lastRun = lastRun; this.lastRun = lastRun;
return this; return this;
} }
@Override @Override
public Trigger duplicate() { public Trigger duplicate() {
return new TriggerTimeOfDay(this); return new TriggerTimeRange(this);
} }
long toMilis(long minutesSinceMidnight) { long toMilis(long minutesSinceMidnight) {
@ -220,7 +221,7 @@ public class TriggerTimeOfDay extends Trigger {
}); });
int px = MainApp.dpToPx(10); 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); label.setTypeface(label.getTypeface(), Typeface.BOLD);
startButton.setPadding(px, px, px, px); startButton.setPadding(px, px, px, px);
endButton.setPadding(px, px, px, px); endButton.setPadding(px, px, px, px);

View file

@ -1605,9 +1605,9 @@
<string name="deliverpartofboluswizard">Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm.</string> <string name="deliverpartofboluswizard">Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm.</string>
<string name="loading">Loading ...</string> <string name="loading">Loading ...</string>
<string name="snooze">Snooze</string> <string name="snooze">Snooze</string>
<string name="time_of_day">Time range</string> <string name="time_range">Time range</string>
<string name="tod_value">Time is between %1$s and %2$s</string> <string name="timerange_value">Time is between %1$s and %2$s</string>
<string name="thanspecifiedtime">Between </string> <string name="between">Between </string>
<plurals name="objective_days"> <plurals name="objective_days">
<item quantity="one">%1$d day</item> <item quantity="one">%1$d day</item>

View file

@ -19,69 +19,69 @@ import info.AAPSMocker;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.T;
import static org.powermock.api.mockito.PowerMockito.when; import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, Bus.class, DateUtil.class, GregorianCalendar.class}) @PrepareForTest({MainApp.class, Bus.class, DateUtil.class, GregorianCalendar.class})
public class TriggerTimeOfDayTest { public class TriggerTimeRangeTest {
int now = 754; 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 @Test
public void shouldRunTest() { public void shouldRunTest() {
// scheduled 1 min before // scheduled 1 min before
TriggerTimeOfDay t = new TriggerTimeOfDay().minSinceMidnight(753); TriggerTimeRange t;
// scheduled 1 min in the future // scheduled 1 min in the future
t = new TriggerTimeOfDay().minSinceMidnight(now + 1); t = new TriggerTimeRange().period(now + 1, now + 30);
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());
// already run // 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()); Assert.assertFalse(t.shouldRun());
} }
@Test @Test
public void toJSONTest() { public void toJSONTest() {
TriggerTimeOfDay t = new TriggerTimeOfDay().minSinceMidnight(now - 1); TriggerTimeRange t = new TriggerTimeRange().period(now - 1, now + 30);
Assert.assertEquals(timeJson, t.toJSON()); Assert.assertEquals(timeJson, t.toJSON());
} }
@Test @Test
public void fromJSONTest() throws JSONException { 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())); TriggerTimeRange t2 = (TriggerTimeRange) Trigger.instantiate(new JSONObject(t.toJSON()));
Assert.assertEquals(now - 1, t2.minSinceMidnight(753).getMinSinceMidnight()); Assert.assertEquals(now - 1, t2.period(753 , 360).getStart());
Assert.assertEquals(360, t2.period(753 , 360).getEnd());
} }
@Test @Test
public void copyConstructorTest() { public void copyConstructorTest() {
TriggerTimeOfDay t = new TriggerTimeOfDay(); TriggerTimeRange t = new TriggerTimeRange();
t.minSinceMidnight(now); t.period(now, now + 30);
TriggerTimeOfDay t1 = (TriggerTimeOfDay) t.duplicate(); TriggerTimeRange t1 = (TriggerTimeRange) t.duplicate();
// Assert.assertEquals(now, t1.getRunAt(), 0.01d); // Assert.assertEquals(now, t1.getRunAt(), 0.01d);
} }
@Test @Test
public void friendlyNameTest() { public void friendlyNameTest() {
Assert.assertEquals(R.string.time_of_day, new TriggerTimeOfDay().friendlyName()); Assert.assertEquals(R.string.time_range, new TriggerTimeRange().friendlyName());
} }
@Test @Test
public void friendlyDescriptionTest() { public void friendlyDescriptionTest() {
Assert.assertEquals(null, new TriggerTimeOfDay().friendlyDescription()); //not mocked } Assert.assertEquals(null, new TriggerTimeRange().friendlyDescription()); //not mocked }
} }
@Test @Test
public void iconTest() { 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());
} }