From 1c8c51841cd37fe5e3254cc31e361ebca4464be3 Mon Sep 17 00:00:00 2001 From: Nico Schmitz Date: Thu, 25 Oct 2018 00:27:51 +0200 Subject: [PATCH] Outsource DummyTrigger --- .../automation/triggers/DummyTrigger.java | 38 ++++++++++++ .../triggers/TriggerConnectorTest.java | 61 +++++-------------- 2 files changed, 52 insertions(+), 47 deletions(-) create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.java new file mode 100644 index 0000000000..56ca4a7b95 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.java @@ -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; + } +} diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnectorTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnectorTest.java index 86dbcb47fc..a5ba819b18 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnectorTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnectorTest.java @@ -12,39 +12,6 @@ import org.powermock.modules.junit4.PowerMockRunner; @PrepareForTest({}) 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 public void testTriggerList() { TriggerConnector t = new TriggerConnector(); @@ -72,40 +39,40 @@ public class TriggerConnectorTest { @Test public void testListTriggerOR() { TriggerConnector t = new TriggerConnector(TriggerConnector.Type.OR); - t.add(new TriggerBoolean(false)); - t.add(new TriggerBoolean(false)); + t.add(new DummyTrigger(false)); + t.add(new DummyTrigger(false)); Assert.assertFalse(t.shouldRun()); - t.add(new TriggerBoolean(true)); - t.add(new TriggerBoolean(false)); + t.add(new DummyTrigger(true)); + t.add(new DummyTrigger(false)); Assert.assertTrue(t.shouldRun()); } @Test public void testListTriggerXOR() { TriggerConnector t = new TriggerConnector(TriggerConnector.Type.XOR); - t.add(new TriggerBoolean(false)); - t.add(new TriggerBoolean(false)); + t.add(new DummyTrigger(false)); + t.add(new DummyTrigger(false)); Assert.assertFalse(t.shouldRun()); - t.add(new TriggerBoolean(true)); - t.add(new TriggerBoolean(false)); + t.add(new DummyTrigger(true)); + t.add(new DummyTrigger(false)); Assert.assertTrue(t.shouldRun()); - t.add(new TriggerBoolean(true)); - t.add(new TriggerBoolean(false)); + t.add(new DummyTrigger(true)); + t.add(new DummyTrigger(false)); Assert.assertFalse(t.shouldRun()); } @Test public void testListTriggerAND() { TriggerConnector t = new TriggerConnector(TriggerConnector.Type.AND); - t.add(new TriggerBoolean(true)); - t.add(new TriggerBoolean(true)); + t.add(new DummyTrigger(true)); + t.add(new DummyTrigger(true)); Assert.assertTrue(t.shouldRun()); - t.add(new TriggerBoolean(true)); - t.add(new TriggerBoolean(false)); + t.add(new DummyTrigger(true)); + t.add(new DummyTrigger(false)); Assert.assertFalse(t.shouldRun()); }