tests lints

This commit is contained in:
Milos Kozak 2021-02-19 09:39:01 +01:00
parent 58f69dae6e
commit 5bf99ce8fc
5 changed files with 19 additions and 177 deletions

View file

@ -9,19 +9,21 @@ import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@Suppress("SpellCheckingInspection")
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
class TriggerBTDeviceTest : TriggerTestBase() { class TriggerBTDeviceTest : TriggerTestBase() {
var now = 1514766900000L var now = 1514766900000L
var someName = "Headset" private var someName = "Headset"
var btJson = "{\"data\":{\"comparator\":\"ON_CONNECT\",\"name\":\"Headset\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBTDevice\"}" private var btJson = "{\"data\":{\"comparator\":\"ON_CONNECT\",\"name\":\"Headset\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBTDevice\"}"
@Test fun shouldRun() { @Test fun shouldRun() {
val t: TriggerBTDevice = TriggerBTDevice(injector) @Suppress("UNUSED_VARIABLE")
val t = TriggerBTDevice(injector)
} }
@Test fun toJSON() { @Test fun toJSON() {
val t: TriggerBTDevice = TriggerBTDevice(injector) val t = TriggerBTDevice(injector)
t.btDevice.value = someName t.btDevice.value = someName
Assert.assertEquals(btJson, t.toJSON()) Assert.assertEquals(btJson, t.toJSON())
} }

View file

@ -6,7 +6,6 @@ import info.nightscout.androidaps.plugins.general.maintenance.formats.Prefs
import info.nightscout.androidaps.testing.utils.SingleStringStorage import info.nightscout.androidaps.testing.utils.SingleStringStorage
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.hamcrest.CoreMatchers
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -32,9 +31,9 @@ class ClassicPrefsFormatTest : TestBase() {
val classicFormat = ClassicPrefsFormat(resourceHelper, SingleStringStorage(test)) val classicFormat = ClassicPrefsFormat(resourceHelper, SingleStringStorage(test))
val prefs = classicFormat.loadPreferences(getMockedFile(), "") val prefs = classicFormat.loadPreferences(getMockedFile(), "")
Assert.assertThat(prefs.values.size, CoreMatchers.`is`(2)) Assert.assertEquals(prefs.values.size, 2)
Assert.assertThat(prefs.values["key1"], CoreMatchers.`is`("val1")) Assert.assertEquals(prefs.values["key1"], "val1")
Assert.assertThat(prefs.values["keyB"], CoreMatchers.`is`("valB")) Assert.assertEquals(prefs.values["keyB"], "valB")
Assert.assertNull(prefs.values["key3"]) Assert.assertNull(prefs.values["key3"])
} }

View file

@ -2,23 +2,22 @@ package info.nightscout.androidaps.plugins.pump.common.utils;
import android.util.Log; import android.util.Log;
import junit.framework.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
public class DateTimeUtilUTest { public class DateTimeUtilUTest {
@Test @Test
public void getATechDateDiferenceAsMinutes() { public void getATechDateDifferenceAsMinutes() {
long dt1 = 20191001182301L; long dt1 = 20191001182301L;
long dt2 = 20191001192805L; 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);
} }
} }

View file

@ -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<String, Object> 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<String> 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<String, ?> 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<String> getStringSet(String k, @Nullable Set<String> set) {
if (editor.innerMap.containsKey(k)) {
return (Set<String>) 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) {
}
}

View file

@ -2,11 +2,11 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.dana.DanaPump
import info.nightscout.androidaps.danar.comm.MsgSettingPumpTime import info.nightscout.androidaps.danar.comm.MsgSettingPumpTime
import org.joda.time.DateTime
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
class MsgSettingPumpTimeTest : DanaRTestBase() { class MsgSettingPumpTimeTest : DanaRTestBase() {
@ -16,14 +16,14 @@ class MsgSettingPumpTimeTest : DanaRTestBase() {
danaPump.units = DanaPump.UNITS_MGDL danaPump.units = DanaPump.UNITS_MGDL
// test message decoding // test message decoding
val bytes = createArray(34, 7.toByte()) val bytes = createArray(34, 7.toByte())
val time = GregorianCalendar( val time = DateTime(
100 + packet.intFromBuff(bytes, 5, 1), 2000 + packet.intFromBuff(bytes, 5, 1),
packet.intFromBuff(bytes, 4, 1) - 1, packet.intFromBuff(bytes, 4, 1),
packet.intFromBuff(bytes, 3, 1), packet.intFromBuff(bytes, 3, 1),
packet.intFromBuff(bytes, 2, 1), packet.intFromBuff(bytes, 2, 1),
packet.intFromBuff(bytes, 1, 1), packet.intFromBuff(bytes, 1, 1),
packet.intFromBuff(bytes, 0, 1) packet.intFromBuff(bytes, 0, 1)
).time ).millis
packet.handleMessage(bytes) packet.handleMessage(bytes)
Assert.assertEquals(time, danaPump.getPumpTime()) Assert.assertEquals(time, danaPump.getPumpTime())
} }