more TriggerBg tests
This commit is contained in:
parent
a5979bb485
commit
a08f01e69b
2 changed files with 44 additions and 2 deletions
|
@ -42,7 +42,7 @@ public class TriggerBg extends Trigger {
|
||||||
private String units = ProfileFunctions.getInstance().getProfileUnits();
|
private String units = ProfileFunctions.getInstance().getProfileUnits();
|
||||||
private long lastRun;
|
private long lastRun;
|
||||||
|
|
||||||
final private TextWatcher textWatcher = new TextWatcher() {
|
final TextWatcher textWatcher = new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
if (units.equals(Constants.MMOL)) {
|
if (units.equals(Constants.MMOL)) {
|
||||||
|
@ -68,7 +68,7 @@ public class TriggerBg extends Trigger {
|
||||||
threshold = units.equals(Constants.MGDL) ? 100d : 5.5d;
|
threshold = units.equals(Constants.MGDL) ? 100d : 5.5d;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TriggerBg(TriggerBg triggerBg) {
|
TriggerBg(TriggerBg triggerBg) {
|
||||||
super();
|
super();
|
||||||
comparator = triggerBg.comparator;
|
comparator = triggerBg.comparator;
|
||||||
lastRun = triggerBg.lastRun;
|
lastRun = triggerBg.lastRun;
|
||||||
|
@ -88,6 +88,10 @@ public class TriggerBg extends Trigger {
|
||||||
return units;
|
return units;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getLastRun() {
|
||||||
|
return lastRun;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean shouldRun() {
|
public synchronized boolean shouldRun() {
|
||||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
|
@ -156,6 +160,7 @@ public class TriggerBg extends Trigger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executed(long time) {
|
public void executed(long time) {
|
||||||
|
lastRun = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.triggers;
|
package info.nightscout.androidaps.plugins.general.automation.triggers;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -18,6 +19,7 @@ import java.util.List;
|
||||||
import info.AAPSMocker;
|
import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSgv;
|
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSgv;
|
||||||
|
@ -66,6 +68,35 @@ public class TriggerBgTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void textWatcherTest() {
|
||||||
|
TriggerBg t = new TriggerBg().threshold(1d).units(Constants.MMOL);
|
||||||
|
t.textWatcher.beforeTextChanged(null, 0,0,0);
|
||||||
|
t.textWatcher.onTextChanged(null, 0,0,0);
|
||||||
|
t.textWatcher.afterTextChanged(null);
|
||||||
|
Assert.assertEquals(4d, t.getThreshold(), 0.01d);
|
||||||
|
|
||||||
|
t = new TriggerBg().threshold(300d).units(Constants.MGDL);
|
||||||
|
t.textWatcher.afterTextChanged(null);
|
||||||
|
Assert.assertEquals(270d, t.getThreshold(), 0.01d);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void copyConstructorTest() {
|
||||||
|
TriggerBg t = new TriggerBg().units(Constants.MGDL).threshold(213).comparator(Trigger.Comparator.IS_EQUAL_OR_LESSER);
|
||||||
|
TriggerBg t1 = (TriggerBg) t.duplicate();
|
||||||
|
Assert.assertEquals(213d, t.getThreshold(), 0.01d);
|
||||||
|
Assert.assertEquals(Constants.MGDL, t.getUnits());
|
||||||
|
Assert.assertEquals(Trigger.Comparator.IS_EQUAL_OR_LESSER, t.getComparator());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void executeTest() {
|
||||||
|
TriggerBg t = new TriggerBg().units(Constants.MGDL).threshold(213).comparator(Trigger.Comparator.IS_EQUAL_OR_LESSER);
|
||||||
|
t.executed(1);
|
||||||
|
Assert.assertEquals(1l, t.getLastRun());
|
||||||
|
}
|
||||||
|
|
||||||
String bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"lastRun\":0,\"threshold\":4.1,\"units\":\"mmol\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg\"}";
|
String bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"lastRun\":0,\"threshold\":4.1,\"units\":\"mmol\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg\"}";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -84,6 +115,12 @@ public class TriggerBgTest {
|
||||||
Assert.assertEquals(Constants.MMOL, t2.getUnits());
|
Assert.assertEquals(Constants.MMOL, t2.getUnits());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void iconTest() {
|
||||||
|
Assert.assertEquals(Optional.of(R.drawable.icon_cp_bgcheck), new TriggerBg().icon());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void mock() {
|
public void mock() {
|
||||||
AAPSMocker.mockMainApp();
|
AAPSMocker.mockMainApp();
|
||||||
|
|
Loading…
Reference in a new issue