diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt index 896a2181b5..c7ee4a5d6a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt @@ -14,7 +14,7 @@ class InputBg(injector: HasAndroidInjector) : Element(injector) { var units = Constants.MGDL var value = 0.0 - private var minValue = 0.0 + var minValue = 0.0 private var maxValue = 0.0 private var step = 0.0 private var decimalFormat: DecimalFormat? = null @@ -35,6 +35,11 @@ class InputBg(injector: HasAndroidInjector) : Element(injector) { root.addView(numberPicker) } + fun setValue(value: Double) : InputBg { + this.value = value + return this + } + fun setUnits(units: String): InputBg { if (units == Constants.MMOL) { minValue = MMOL_MIN diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.java deleted file mode 100644 index ad62bb2835..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.AAPSMocker; -import info.nightscout.androidaps.MainApp; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class}) -public class ComparatorExistsTest { - - @Test - public void labelsTest() { - Assert.assertEquals(2, ComparatorExists.Compare.labels().size()); - } - - @Test - public void getSetValueTest() { - ComparatorExists c = new ComparatorExists().setValue(ComparatorExists.Compare.NOT_EXISTS); - Assert.assertEquals(ComparatorExists.Compare.NOT_EXISTS, c.getValue()); - } - - @Before - public void prepare() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockStrings(); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt new file mode 100644 index 0000000000..99d71cdeab --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class ComparatorExistsTest : TriggerTestBase() { + + @Test fun labelsTest() { + Assert.assertEquals(2, ComparatorExists.Compare.labels(resourceHelper).size) + } + + @Test fun setValueTest() { + val c = ComparatorExists(injector) + c.value = ComparatorExists.Compare.NOT_EXISTS + Assert.assertEquals(ComparatorExists.Compare.NOT_EXISTS, c.value) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.java deleted file mode 100644 index ff340319ef..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.AAPSMocker; -import info.nightscout.androidaps.MainApp; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class}) -public class ComparatorTest { - - @Test - public void checkTest() { - Assert.assertTrue(Comparator.Compare.IS_EQUAL.check(1, 1)); - Assert.assertTrue(Comparator.Compare.IS_LESSER.check(1, 2)); - Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(1, 2)); - Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 2)); - Assert.assertTrue(Comparator.Compare.IS_GREATER.check(2, 1)); - Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 1)); - Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 2)); - - Assert.assertFalse(Comparator.Compare.IS_LESSER.check(2, 1)); - Assert.assertFalse(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 1)); - Assert.assertFalse(Comparator.Compare.IS_GREATER.check(1, 2)); - Assert.assertFalse(Comparator.Compare.IS_EQUAL_OR_GREATER.check(1, 2)); - - Assert.assertTrue(Comparator.Compare.IS_NOT_AVAILABLE.check(1, null)); - } - - @Test - public void labelsTest() { - Assert.assertEquals(6, Comparator.Compare.labels().size()); - } - - @Test - public void getSetValueTest() { - Comparator c = new Comparator().setValue(Comparator.Compare.IS_EQUAL_OR_GREATER); - Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_GREATER, c.getValue()); - } - - @Before - public void prepare() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockStrings(); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt new file mode 100644 index 0000000000..da8143e7f6 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt @@ -0,0 +1,38 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class ComparatorTest : TriggerTestBase() { + + @Test + fun checkTest() { + Assert.assertTrue(Comparator.Compare.IS_EQUAL.check(1, 1)) + Assert.assertTrue(Comparator.Compare.IS_LESSER.check(1, 2)) + Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(1, 2)) + Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 2)) + Assert.assertTrue(Comparator.Compare.IS_GREATER.check(2, 1)) + Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 1)) + Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 2)) + Assert.assertFalse(Comparator.Compare.IS_LESSER.check(2, 1)) + Assert.assertFalse(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 1)) + Assert.assertFalse(Comparator.Compare.IS_GREATER.check(1, 2)) + Assert.assertFalse(Comparator.Compare.IS_EQUAL_OR_GREATER.check(1, 2)) +// Assert.assertTrue(Comparator.Compare.IS_NOT_AVAILABLE.check(1, null)) + } + + @Test + fun labelsTest() { + Assert.assertEquals(6, Comparator.Compare.labels(resourceHelper).size) + } + + @Test + fun setValueTest() { + val c: Comparator = Comparator(injector).setValue(Comparator.Compare.IS_EQUAL_OR_GREATER) + Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_GREATER, c.value) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.java deleted file mode 100644 index dd2e335e86..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.AAPSMocker; -import info.nightscout.androidaps.Constants; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, ProfileFunctions.class}) -public class InputBgTest { - - @Test - public void getSetValueTest() { - InputBg i = new InputBg().setUnits(Constants.MMOL).setValue(5d); - Assert.assertEquals(5d, i.getValue(), 0.01d); - Assert.assertEquals(InputBg.MMOL_MIN, i.minValue, 0.01d); - i = new InputBg().setValue(100d).setUnits(Constants.MGDL); - Assert.assertEquals(100d, i.getValue(), 0.01d); - Assert.assertEquals(InputBg.MGDL_MIN, i.minValue, 0.01d); - Assert.assertEquals(Constants.MGDL, i.getUnits()); - } - - - @Before - public void prepare() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockStrings(); - AAPSMocker.mockProfileFunctions(); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt new file mode 100644 index 0000000000..848cb0b6c9 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt @@ -0,0 +1,33 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mockito.`when` +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest(ProfileFunctions::class) +class InputBgTest : TriggerTestBase() { + + @Test + fun setValueTest() { + var i: InputBg = InputBg(injector).setUnits(Constants.MMOL).setValue(5.0) + Assert.assertEquals(5.0, i.value, 0.01) + Assert.assertEquals(InputBg.MMOL_MIN, i.minValue, 0.01) + i = InputBg(injector).setValue(100.0).setUnits(Constants.MGDL) + Assert.assertEquals(100.0, i.value, 0.01) + Assert.assertEquals(InputBg.MGDL_MIN, i.minValue, 0.01) + Assert.assertEquals(Constants.MGDL, i.units) + } + + @Before + fun prepare() { + `when`(profileFunction.getUnits()).thenReturn(Constants.MGDL) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.java deleted file mode 100644 index 92ab51579c..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.AAPSMocker; -import info.nightscout.androidaps.Constants; -import info.nightscout.androidaps.MainApp; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class}) -public class InputDurationTest { - - @Test - public void getSetValueTest() { - InputDuration i = new InputDuration(5, InputDuration.TimeUnit.MINUTES); - Assert.assertEquals(5, i.getValue(), 0.01d); - Assert.assertEquals(InputDuration.TimeUnit.MINUTES, i.getUnit()); - i = i = new InputDuration(5, InputDuration.TimeUnit.HOURS); - Assert.assertEquals(5d, i.getValue(), 0.01d); - Assert.assertEquals(InputDuration.TimeUnit.HOURS, i.getUnit()); - Assert.assertEquals(5 * 60, i.getMinutes()); - i.setMinutes(60); - Assert.assertEquals(1, i.getValue(), 0.01d); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt new file mode 100644 index 0000000000..f52003e3f0 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class InputDurationTest : TriggerTestBase() { + + @Test fun setValueTest() { + var i = InputDuration(injector, 5, InputDuration.TimeUnit.MINUTES) + Assert.assertEquals(5, i.value) + Assert.assertEquals(InputDuration.TimeUnit.MINUTES, i.unit) + i = InputDuration(injector, 5, InputDuration.TimeUnit.HOURS) + Assert.assertEquals(5, i.value) + Assert.assertEquals(InputDuration.TimeUnit.HOURS, i.unit) + Assert.assertEquals(5 * 60, i.getMinutes()) + i.setMinutes(60) + Assert.assertEquals(1, i.value) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.java deleted file mode 100644 index e2e68ccc28..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.nightscout.androidaps.MainApp; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class}) -public class InputInsulinTest { - - @Test - public void textWatcherTest() { - InputInsulin t = new InputInsulin().setValue(30d); - t.textWatcher.beforeTextChanged(null, 0, 0, 0); - t.textWatcher.onTextChanged(null, 0, 0, 0); - t.textWatcher.afterTextChanged(null); - Assert.assertEquals(20d, t.getValue(), 0.01d); - } - - @Test - public void getSetValueTest() { - InputInsulin i = new InputInsulin().setValue(5d); - Assert.assertEquals(5d, i.getValue(), 0.01d); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt new file mode 100644 index 0000000000..97b09bfcd7 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt @@ -0,0 +1,17 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class InputInsulinTest : TriggerTestBase() { + + @Test fun setValueTest() { + val i = InputInsulin(injector) + i.value = 5.0 + Assert.assertEquals(5.0, i.value, 0.01) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.java deleted file mode 100644 index 73b06ad70a..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.nightscout.androidaps.MainApp; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class}) -public class InputPercentTest { - - @Test - public void textWatcherTest() { - InputPercent t = new InputPercent().setValue(530d); - t.textWatcher.beforeTextChanged(null, 0, 0, 0); - t.textWatcher.onTextChanged(null, 0, 0, 0); - t.textWatcher.afterTextChanged(null); - Assert.assertEquals(130d, t.getValue(), 0.01d); - } - - @Test - public void getSetValueTest() { - InputPercent i = new InputPercent().setValue(10d); - Assert.assertEquals(10d, i.getValue(), 0.01d); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt new file mode 100644 index 0000000000..3367bbdfa0 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt @@ -0,0 +1,17 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class InputPercentTest : TriggerTestBase() { + + @Test fun setValueTest() { + val i = InputPercent(injector) + i.value = 10.0 + Assert.assertEquals(10.0, i.value, 0.01) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.java deleted file mode 100644 index 7f257aa883..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; -import info.nightscout.androidaps.utils.SP; - -import static org.junit.Assert.*; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, TreatmentsPlugin.class, ProfileFunctions.class}) -public class InputProfileNameTest { - String profileName = "Test"; - InputProfileName inputProfileName = new InputProfileName(profileName); - - @Test - public void getSetValue() { - inputProfileName = new InputProfileName("Test"); - Assert.assertEquals("Test", inputProfileName.getValue()); - inputProfileName.setValue("Test2"); - Assert.assertEquals("Test2", inputProfileName.getValue()); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.kt new file mode 100644 index 0000000000..549e0c5ded --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.kt @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.SP +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class InputProfileNameTest : TriggerTestBase() { + + @Test fun setValue() { + val inputProfileName = InputProfileName(injector, "Test") + Assert.assertEquals("Test", inputProfileName.value) + inputProfileName.value = "Test2" + Assert.assertEquals("Test2", inputProfileName.value) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.java deleted file mode 100644 index 9d1601c497..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.java +++ /dev/null @@ -1,155 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import android.text.Editable; -import android.text.InputFilter; - -import androidx.annotation.NonNull; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.nightscout.androidaps.MainApp; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class}) -public class InputStringTest { - - @Test - public void textWatcherTest() { - InputString t = new InputString().setValue("asd"); - t.textWatcher.beforeTextChanged(null, 0, 0, 0); - t.textWatcher.onTextChanged(null, 0, 0, 0); - t.textWatcher.afterTextChanged(new Editable() { - @Override - public Editable replace(int st, int en, CharSequence source, int start, int end) { - return null; - } - - @Override - public Editable replace(int st, int en, CharSequence text) { - return null; - } - - @Override - public Editable insert(int where, CharSequence text, int start, int end) { - return null; - } - - @Override - public Editable insert(int where, CharSequence text) { - return null; - } - - @Override - public Editable delete(int st, int en) { - return null; - } - - @Override - public Editable append(CharSequence text) { - return null; - } - - @Override - public Editable append(CharSequence text, int start, int end) { - return null; - } - - @Override - public Editable append(char text) { - return null; - } - - @Override - public void clear() { - - } - - @Override - public void clearSpans() { - - } - - @Override - public void setFilters(InputFilter[] filters) { - - } - - @Override - public InputFilter[] getFilters() { - return new InputFilter[0]; - } - - @Override - public void getChars(int start, int end, char[] dest, int destoff) { - - } - - @Override - public void setSpan(Object what, int start, int end, int flags) { - - } - - @Override - public void removeSpan(Object what) { - - } - - @Override - public T[] getSpans(int start, int end, Class type) { - return null; - } - - @Override - public int getSpanStart(Object tag) { - return 0; - } - - @Override - public int getSpanEnd(Object tag) { - return 0; - } - - @Override - public int getSpanFlags(Object tag) { - return 0; - } - - @Override - public int nextSpanTransition(int start, int limit, Class type) { - return 0; - } - - @Override - public int length() { - return 0; - } - - @Override - public char charAt(int index) { - return 0; - } - - @Override - public CharSequence subSequence(int start, int end) { - return null; - } - - @NonNull - @Override - public String toString() { - return "qwerty"; - } - }); - Assert.assertEquals("qwerty", t.getValue()); - } - - @Test - public void getSetValueTest() { - InputString i = new InputString().setValue("asd"); - Assert.assertEquals("asd", i.getValue()); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt new file mode 100644 index 0000000000..686cf9047b --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt @@ -0,0 +1,17 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class InputStringTest : TriggerTestBase() { + + @Test fun setValueTest() { + val i = InputString(injector) + i.value = "asd" + Assert.assertEquals("asd", i.value) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.java deleted file mode 100644 index 008b7a6743..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.AAPSMocker; -import info.nightscout.androidaps.Constants; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, ProfileFunctions.class}) -public class InputTempTargetTest { - - @Test - public void getSetValueTest() { - InputTempTarget i = new InputTempTarget().setUnits(Constants.MMOL).setValue(5d); - Assert.assertEquals(5d, i.getValue(), 0.01d); - Assert.assertEquals(Constants.MIN_TT_MMOL, i.minValue, 0.01d); - i = new InputTempTarget().setValue(100d).setUnits(Constants.MGDL); - Assert.assertEquals(100d, i.getValue(), 0.01d); - Assert.assertEquals(Constants.MIN_TT_MGDL, i.minValue, 0.01d); - Assert.assertEquals(Constants.MGDL, i.getUnits()); - } - - - @Before - public void prepare() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockStrings(); - AAPSMocker.mockProfileFunctions(); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt new file mode 100644 index 0000000000..d98ca75f1c --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class InputTempTargetTest : TriggerTestBase() { + + @Test fun setValueTest() { + val i = InputTempTarget(injector) + i.units = Constants.MMOL + i.value = 5.0 + Assert.assertEquals(5.0, i.value, 0.01) + i.units = Constants.MGDL + i.value = 100.0 + Assert.assertEquals(100.0, i.value, 0.01) + Assert.assertEquals(Constants.MGDL, i.units) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.java deleted file mode 100644 index e3e85d8ae4..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -public class LabelWithElementTest { - - @Test - public void constructorTest() { - LabelWithElement l = new LabelWithElement("A", "B", new InputInsulin()); - Assert.assertEquals("A", l.textPre); - Assert.assertEquals("B", l.textPost); - Assert.assertEquals(InputInsulin.class, l.element.getClass()); - } - -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.kt new file mode 100644 index 0000000000..f0fcaafe56 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.kt @@ -0,0 +1,19 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class LabelWithElementTest : TriggerTestBase() { + + @Test + fun constructorTest() { + val l = LabelWithElement(injector, "A", "B", InputInsulin(injector)) + Assert.assertEquals("A", l.textPre) + Assert.assertEquals("B", l.textPost) + Assert.assertEquals(InputInsulin::class.java, l.element!!.javaClass) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabelTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabelTest.java deleted file mode 100644 index 669e5f8982..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabelTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.AAPSMocker; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class}) -public class StaticLabelTest { - - @Test - public void constructor() { - StaticLabel sl = new StaticLabel("any"); - Assert.assertEquals("any", sl.label); - - sl = new StaticLabel(R.string.pumplimit); - Assert.assertEquals(MainApp.gs(R.string.pumplimit), sl.label); - } - - @Before - public void prepareTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockStrings(); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabelTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabelTest.kt new file mode 100644 index 0000000000..4b85698d3c --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabelTest.kt @@ -0,0 +1,22 @@ +package info.nightscout.androidaps.plugins.general.automation.elements + +import info.nightscout.androidaps.R +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mockito.`when` +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class StaticLabelTest : TriggerTestBase() { + + @Test fun constructor() { + var sl = StaticLabel(injector, "any", TriggerDummy(injector)) + Assert.assertEquals("any", sl.label) + `when`(resourceHelper.gs(R.string.pumplimit)).thenReturn("pump limit") + sl = StaticLabel(injector, R.string.pumplimit, TriggerDummy(injector)) + Assert.assertEquals("pump limit", sl.label) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt index 2c8ea40f91..0b5d93d930 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt @@ -8,6 +8,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.general.automation.elements.InputBg +import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin @@ -52,6 +53,9 @@ open class TriggerTestBase : TestBase() { it.aapsLogger = aapsLogger it.iobCobCalculatorPlugin = iobCobCalculatorPlugin } + if (it is StaticLabel) { + it.resourceHelper = resourceHelper + } } }