diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDeviceTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDeviceTest.kt index f4665f4938..d2d3d77168 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDeviceTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDeviceTest.kt @@ -9,19 +9,21 @@ import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner +@Suppress("SpellCheckingInspection") @RunWith(PowerMockRunner::class) class TriggerBTDeviceTest : TriggerTestBase() { var now = 1514766900000L - var someName = "Headset" - var btJson = "{\"data\":{\"comparator\":\"ON_CONNECT\",\"name\":\"Headset\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBTDevice\"}" + private var someName = "Headset" + private var btJson = "{\"data\":{\"comparator\":\"ON_CONNECT\",\"name\":\"Headset\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBTDevice\"}" @Test fun shouldRun() { - val t: TriggerBTDevice = TriggerBTDevice(injector) + @Suppress("UNUSED_VARIABLE") + val t = TriggerBTDevice(injector) } @Test fun toJSON() { - val t: TriggerBTDevice = TriggerBTDevice(injector) + val t = TriggerBTDevice(injector) t.btDevice.value = someName Assert.assertEquals(btJson, t.toJSON()) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/ClassicPrefsFormatTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/ClassicPrefsFormatTest.kt index 2e27046f5b..eb5064e66a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/ClassicPrefsFormatTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/ClassicPrefsFormatTest.kt @@ -6,7 +6,6 @@ import info.nightscout.androidaps.plugins.general.maintenance.formats.Prefs import info.nightscout.androidaps.testing.utils.SingleStringStorage import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP -import org.hamcrest.CoreMatchers import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -32,9 +31,9 @@ class ClassicPrefsFormatTest : TestBase() { val classicFormat = ClassicPrefsFormat(resourceHelper, SingleStringStorage(test)) val prefs = classicFormat.loadPreferences(getMockedFile(), "") - Assert.assertThat(prefs.values.size, CoreMatchers.`is`(2)) - Assert.assertThat(prefs.values["key1"], CoreMatchers.`is`("val1")) - Assert.assertThat(prefs.values["keyB"], CoreMatchers.`is`("valB")) + Assert.assertEquals(prefs.values.size, 2) + Assert.assertEquals(prefs.values["key1"], "val1") + Assert.assertEquals(prefs.values["keyB"], "valB") Assert.assertNull(prefs.values["key3"]) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtilUTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtilUTest.java index 7b79c62e82..d190631ae5 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtilUTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtilUTest.java @@ -2,23 +2,22 @@ package info.nightscout.androidaps.plugins.pump.common.utils; import android.util.Log; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.Test; public class DateTimeUtilUTest { @Test - public void getATechDateDiferenceAsMinutes() { + public void getATechDateDifferenceAsMinutes() { long dt1 = 20191001182301L; long dt2 = 20191001192805L; - int aTechDateDiferenceAsMinutes = DateTimeUtil.getATechDateDiferenceAsMinutes(dt1, dt2); + int aTechDateDifferenceAsMinutes = DateTimeUtil.getATechDateDiferenceAsMinutes(dt1, dt2); - Assert.assertEquals(65, aTechDateDiferenceAsMinutes); + Assert.assertEquals(65, aTechDateDifferenceAsMinutes); - Log.d("DateTimeUtilUTest", "Time difference: " + aTechDateDiferenceAsMinutes); + Log.d("DateTimeUtilUTest", "Time difference: " + aTechDateDifferenceAsMinutes); } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/testing/mocks/SharedPreferencesMock.java b/app/src/test/java/info/nightscout/androidaps/testing/mocks/SharedPreferencesMock.java deleted file mode 100644 index 5b0736a450..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/testing/mocks/SharedPreferencesMock.java +++ /dev/null @@ -1,158 +0,0 @@ -package info.nightscout.androidaps.testing.mocks; - -import android.content.SharedPreferences; - -import androidx.annotation.Nullable; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -public class SharedPreferencesMock implements SharedPreferences { - - private final EditorInternals editor = new EditorInternals(); - - class EditorInternals implements Editor { - - Map innerMap = new HashMap<>(); - - @Override - public Editor putString(String k, @Nullable String v) { - innerMap.put(k, v); - return this; - } - - @Override - public Editor putStringSet(String k, @Nullable Set set) { - innerMap.put(k, set); - return this; - } - - @Override - public Editor putInt(String k, int i) { - innerMap.put(k, i); - return this; - } - - @Override - public Editor putLong(String k, long l) { - innerMap.put(k, l); - return this; - } - - @Override - public Editor putFloat(String k, float v) { - innerMap.put(k, v); - return this; - } - - @Override - public Editor putBoolean(String k, boolean b) { - innerMap.put(k, b); - return this; - } - - @Override - public Editor remove(String k) { - innerMap.remove(k); - return this; - } - - @Override - public Editor clear() { - innerMap.clear(); - return this; - } - - @Override - public boolean commit() { - return true; - } - - @Override - public void apply() { - - } - } - - @Override - public Map getAll() { - return editor.innerMap; - } - - @Nullable - @Override - public String getString(String k, @Nullable String s) { - if (editor.innerMap.containsKey(k)) { - return (String) editor.innerMap.get(k); - } else { - return s; - } - } - - @Nullable - @Override - public Set getStringSet(String k, @Nullable Set set) { - if (editor.innerMap.containsKey(k)) { - return (Set) editor.innerMap.get(k); - } else { - return set; - } - } - - @Override - public int getInt(String k, int i) { - if (editor.innerMap.containsKey(k)) { - return (Integer) editor.innerMap.get(k); - } else { - return i; - } - } - - @Override - public long getLong(String k, long l) { - if (editor.innerMap.containsKey(k)) { - return (Long) editor.innerMap.get(k); - } else { - return l; - } - } - - @Override - public float getFloat(String k, float v) { - if (editor.innerMap.containsKey(k)) { - return (Float) editor.innerMap.get(k); - } else { - return v; - } - } - - @Override - public boolean getBoolean(String k, boolean b) { - if (editor.innerMap.containsKey(k)) { - return (Boolean) editor.innerMap.get(k); - } else { - return b; - } - } - - @Override - public boolean contains(String k) { - return editor.innerMap.containsKey(k); - } - - @Override - public Editor edit() { - return editor; - } - - @Override - public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener onSharedPreferenceChangeListener) { - - } - - @Override - public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener onSharedPreferenceChangeListener) { - - } -} diff --git a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt index c7bed1eebb..4bed4e080e 100644 --- a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt +++ b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt @@ -2,11 +2,11 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.comm.MsgSettingPumpTime +import org.joda.time.DateTime import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner -import java.util.* @RunWith(PowerMockRunner::class) class MsgSettingPumpTimeTest : DanaRTestBase() { @@ -16,14 +16,14 @@ class MsgSettingPumpTimeTest : DanaRTestBase() { danaPump.units = DanaPump.UNITS_MGDL // test message decoding val bytes = createArray(34, 7.toByte()) - val time = GregorianCalendar( - 100 + packet.intFromBuff(bytes, 5, 1), - packet.intFromBuff(bytes, 4, 1) - 1, + val time = DateTime( + 2000 + packet.intFromBuff(bytes, 5, 1), + packet.intFromBuff(bytes, 4, 1), packet.intFromBuff(bytes, 3, 1), packet.intFromBuff(bytes, 2, 1), packet.intFromBuff(bytes, 1, 1), packet.intFromBuff(bytes, 0, 1) - ).time + ).millis packet.handleMessage(bytes) Assert.assertEquals(time, danaPump.getPumpTime()) }