Outsource DummyTrigger

This commit is contained in:
Nico Schmitz 2018-10-25 00:27:51 +02:00
parent 8dc40fb795
commit 1c8c51841c
2 changed files with 52 additions and 47 deletions

View file

@ -0,0 +1,38 @@
package info.nightscout.androidaps.plugins.general.automation.triggers;
public class DummyTrigger extends Trigger {
private boolean result;
public DummyTrigger() {
this.result = false;
}
public DummyTrigger(boolean result) {
this.result = result;
}
@Override
public boolean shouldRun() {
return result;
}
@Override
String toJSON() {
return null;
}
@Override
Trigger fromJSON(String data) {
return null;
}
@Override
public int friendlyName() {
return 0;
}
@Override
public String friendlyDescription() {
return null;
}
}

View file

@ -12,39 +12,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
@PrepareForTest({}) @PrepareForTest({})
public class TriggerConnectorTest { public class TriggerConnectorTest {
private static class TriggerBoolean extends Trigger {
private boolean result;
TriggerBoolean(boolean result) {
this.result = result;
}
@Override
public boolean shouldRun() {
return result;
}
@Override
String toJSON() {
return null;
}
@Override
Trigger fromJSON(String data) {
return null;
}
@Override
public int friendlyName() {
return 0;
}
@Override
public String friendlyDescription() {
return null;
}
}
@Test @Test
public void testTriggerList() { public void testTriggerList() {
TriggerConnector t = new TriggerConnector(); TriggerConnector t = new TriggerConnector();
@ -72,40 +39,40 @@ public class TriggerConnectorTest {
@Test @Test
public void testListTriggerOR() { public void testListTriggerOR() {
TriggerConnector t = new TriggerConnector(TriggerConnector.Type.OR); TriggerConnector t = new TriggerConnector(TriggerConnector.Type.OR);
t.add(new TriggerBoolean(false)); t.add(new DummyTrigger(false));
t.add(new TriggerBoolean(false)); t.add(new DummyTrigger(false));
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());
t.add(new TriggerBoolean(true)); t.add(new DummyTrigger(true));
t.add(new TriggerBoolean(false)); t.add(new DummyTrigger(false));
Assert.assertTrue(t.shouldRun()); Assert.assertTrue(t.shouldRun());
} }
@Test @Test
public void testListTriggerXOR() { public void testListTriggerXOR() {
TriggerConnector t = new TriggerConnector(TriggerConnector.Type.XOR); TriggerConnector t = new TriggerConnector(TriggerConnector.Type.XOR);
t.add(new TriggerBoolean(false)); t.add(new DummyTrigger(false));
t.add(new TriggerBoolean(false)); t.add(new DummyTrigger(false));
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());
t.add(new TriggerBoolean(true)); t.add(new DummyTrigger(true));
t.add(new TriggerBoolean(false)); t.add(new DummyTrigger(false));
Assert.assertTrue(t.shouldRun()); Assert.assertTrue(t.shouldRun());
t.add(new TriggerBoolean(true)); t.add(new DummyTrigger(true));
t.add(new TriggerBoolean(false)); t.add(new DummyTrigger(false));
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());
} }
@Test @Test
public void testListTriggerAND() { public void testListTriggerAND() {
TriggerConnector t = new TriggerConnector(TriggerConnector.Type.AND); TriggerConnector t = new TriggerConnector(TriggerConnector.Type.AND);
t.add(new TriggerBoolean(true)); t.add(new DummyTrigger(true));
t.add(new TriggerBoolean(true)); t.add(new DummyTrigger(true));
Assert.assertTrue(t.shouldRun()); Assert.assertTrue(t.shouldRun());
t.add(new TriggerBoolean(true)); t.add(new DummyTrigger(true));
t.add(new TriggerBoolean(false)); t.add(new DummyTrigger(false));
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());
} }