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(
TriggerTime(),
TriggerRecurringTime(),
TriggerTimeOfDay(),
TriggerTimeRange(),
TriggerBg(),
TriggerDelta(),
TriggerIob(),

View file

@ -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);

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="loading">Loading ...</string>
<string name="snooze">Snooze</string>
<string name="time_of_day">Time range</string>
<string name="tod_value">Time is between %1$s and %2$s</string>
<string name="thanspecifiedtime">Between </string>
<string name="time_range">Time range</string>
<string name="timerange_value">Time is between %1$s and %2$s</string>
<string name="between">Between </string>
<plurals name="objective_days">
<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.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());
}