Wear: tests & cleanup
This commit is contained in:
parent
057d072e89
commit
fca58029a4
|
@ -29,4 +29,8 @@ dependencies {
|
|||
exclude group: "com.google.android", module: "android"
|
||||
}
|
||||
|
||||
//RxBus
|
||||
api "io.reactivex.rxjava2:rxjava:$rxjava_version"
|
||||
api "io.reactivex.rxjava2:rxkotlin:$rxkotlin_version"
|
||||
api "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
|
||||
}
|
|
@ -24,7 +24,6 @@ ext {
|
|||
wearableVersion = "2.8.1"
|
||||
// playServicesWearable 17.1.0 breaks test
|
||||
playServicesWearable = "17.0.0"
|
||||
powermockVersion = '2.0.9'
|
||||
}
|
||||
|
||||
def generateGitBuild = { ->
|
||||
|
@ -147,10 +146,6 @@ dependencies {
|
|||
testImplementation "net.bytebuddy:byte-buddy-android:$byteBuddyVersion"
|
||||
testImplementation "net.bytebuddy:byte-buddy-agent:$byteBuddyVersion"
|
||||
|
||||
testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}"
|
||||
testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}"
|
||||
testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}"
|
||||
testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}"
|
||||
testImplementation "joda-time:joda-time:$jodatime_version"
|
||||
testImplementation('com.google.truth:truth:1.1.3') {
|
||||
exclude group: "com.google.guava", module: "guava"
|
||||
|
|
|
@ -28,22 +28,34 @@ public class Persistence {
|
|||
|
||||
private Context context;
|
||||
private AAPSLogger aapsLogger;
|
||||
private WearUtil wearUtil;
|
||||
private SharedPreferences preferences;
|
||||
private final String COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY =
|
||||
"info.nightscout.androidaps.complications.COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY";
|
||||
|
||||
@Inject
|
||||
public Persistence(Context context, AAPSLogger aapsLogger) {
|
||||
public Persistence(Context context, AAPSLogger aapsLogger, WearUtil wearUtil) {
|
||||
this.context = context;
|
||||
this.aapsLogger = aapsLogger;
|
||||
this.wearUtil = wearUtil;
|
||||
preferences = context.getSharedPreferences(COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY, 0);
|
||||
}
|
||||
|
||||
// For mocking only
|
||||
public byte[] base64decode(String str, int flags) {
|
||||
return Base64.decode(str, flags);
|
||||
}
|
||||
|
||||
// For mocking only
|
||||
public String base64encodeToString(byte[] input, int flags) {
|
||||
return Base64.encodeToString(input, flags);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DataMap getDataMap(String key) {
|
||||
if (preferences.contains(key)) {
|
||||
final String rawB64Data = preferences.getString(key, null);
|
||||
byte[] rawData = Base64.decode(rawB64Data, Base64.DEFAULT);
|
||||
byte[] rawData = base64decode(rawB64Data, Base64.DEFAULT);
|
||||
try {
|
||||
return DataMap.fromByteArray(rawData);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
|
@ -54,7 +66,7 @@ public class Persistence {
|
|||
}
|
||||
|
||||
public void putDataMap(String key, DataMap dataMap) {
|
||||
preferences.edit().putString(key, Base64.encodeToString(dataMap.toByteArray(), Base64.DEFAULT)).apply();
|
||||
preferences.edit().putString(key, base64encodeToString(dataMap.toByteArray(), Base64.DEFAULT)).apply();
|
||||
}
|
||||
|
||||
public String getString(String key, String defaultValue) {
|
||||
|
@ -78,7 +90,7 @@ public class Persistence {
|
|||
}
|
||||
|
||||
private void markDataUpdated() {
|
||||
preferences.edit().putLong("data_updated_at", System.currentTimeMillis()).apply();
|
||||
preferences.edit().putLong("data_updated_at", wearUtil.timestamp()).apply();
|
||||
}
|
||||
|
||||
public Set<String> getSetOf(String key) {
|
||||
|
|
|
@ -3,7 +3,6 @@ package info.nightscout.androidaps.interaction.utils;
|
|||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
||||
|
@ -14,6 +13,9 @@ import java.util.Map;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import info.nightscout.shared.logging.AAPSLogger;
|
||||
import info.nightscout.shared.logging.LTag;
|
||||
|
||||
/**
|
||||
* Created by andy on 3/5/19.
|
||||
* Adapted by dlvoy on 2019-11-06 using code from jamorham JoH class
|
||||
|
@ -22,9 +24,11 @@ import javax.inject.Singleton;
|
|||
@Singleton
|
||||
public class WearUtil {
|
||||
|
||||
@Inject Context context;
|
||||
@Inject public Context context;
|
||||
@Inject public AAPSLogger aapsLogger;
|
||||
|
||||
@Inject WearUtil() {}
|
||||
@Inject public WearUtil() {
|
||||
}
|
||||
|
||||
private final boolean debug_wakelocks = false;
|
||||
private final Map<String, Long> rateLimits = new HashMap<>();
|
||||
|
@ -59,7 +63,7 @@ public class WearUtil {
|
|||
public synchronized boolean isBelowRateLimit(String named, int onceForSeconds) {
|
||||
// check if over limit
|
||||
if ((rateLimits.containsKey(named)) && (timestamp() - rateLimits.get(named) < (onceForSeconds * 1000))) {
|
||||
Log.d(TAG, named + " rate limited to one for " + onceForSeconds + " seconds");
|
||||
aapsLogger.debug(LTag.WEAR, named + " rate limited to one for " + onceForSeconds + " seconds");
|
||||
return false;
|
||||
}
|
||||
// not over limit
|
||||
|
@ -69,14 +73,15 @@ public class WearUtil {
|
|||
|
||||
public PowerManager.WakeLock getWakeLock(final String name, int millis) {
|
||||
final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AAPS::"+name);
|
||||
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AAPS::" + name);
|
||||
wl.acquire(millis);
|
||||
if (debug_wakelocks) Log.d(TAG, "getWakeLock: " + name + " " + wl.toString());
|
||||
if (debug_wakelocks)
|
||||
aapsLogger.debug(LTag.WEAR, "getWakeLock: " + name + " " + wl.toString());
|
||||
return wl;
|
||||
}
|
||||
|
||||
public void releaseWakeLock(PowerManager.WakeLock wl) {
|
||||
if (debug_wakelocks) Log.d(TAG, "releaseWakeLock: " + wl.toString());
|
||||
if (debug_wakelocks) aapsLogger.debug(LTag.WEAR, "releaseWakeLock: " + wl.toString());
|
||||
if (wl == null) return;
|
||||
if (wl.isHeld()) wl.release();
|
||||
}
|
||||
|
|
88
wear/src/test/java/info/nightscout/androidaps/TestBase.kt
Normal file
88
wear/src/test/java/info/nightscout/androidaps/TestBase.kt
Normal file
|
@ -0,0 +1,88 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import info.nightscout.androidaps.interaction.utils.Persistence
|
||||
import info.nightscout.androidaps.interaction.utils.WearUtil
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker
|
||||
import info.nightscout.androidaps.testing.mocks.SharedPreferencesMock
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.androidaps.utils.rx.TestAapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLoggerTest
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.junit.MockitoRule
|
||||
import java.util.*
|
||||
|
||||
open class TestBase {
|
||||
|
||||
@Mock lateinit var context: Context
|
||||
|
||||
val aapsLogger = AAPSLoggerTest()
|
||||
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
|
||||
|
||||
val wearUtil: WearUtil = Mockito.spy(WearUtil())
|
||||
val wearUtilMocker = WearUtilMocker(wearUtil)
|
||||
lateinit var persistence: Persistence
|
||||
|
||||
private val mockedSharedPrefs: HashMap<String, SharedPreferences> = HashMap()
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
Mockito.doAnswer { invocation ->
|
||||
val key = invocation.getArgument<String>(0)
|
||||
if (mockedSharedPrefs.containsKey(key)) {
|
||||
return@doAnswer mockedSharedPrefs[key]
|
||||
} else {
|
||||
val newPrefs = SharedPreferencesMock()
|
||||
mockedSharedPrefs[key] = newPrefs
|
||||
return@doAnswer newPrefs
|
||||
}
|
||||
}.`when`(context).getSharedPreferences(ArgumentMatchers.anyString(), ArgumentMatchers.anyInt())
|
||||
|
||||
wearUtilMocker.prepareMockNoReal()
|
||||
wearUtil.aapsLogger = aapsLogger
|
||||
wearUtil.context = context
|
||||
persistence = Mockito.spy(Persistence(context, aapsLogger, wearUtil))
|
||||
|
||||
Mockito.doAnswer { invocation ->
|
||||
val payload = invocation.getArgument<String>(0)
|
||||
try {
|
||||
return@doAnswer Base64.getDecoder().decode(payload)
|
||||
} catch (ex: IllegalArgumentException) {
|
||||
return@doAnswer null
|
||||
}
|
||||
}.`when`(persistence).base64decode(ArgumentMatchers.anyString(), ArgumentMatchers.anyInt())
|
||||
|
||||
Mockito.doAnswer { invocation ->
|
||||
val payload = invocation.getArgument<ByteArray>(0)
|
||||
Base64.getEncoder().encodeToString(payload)
|
||||
}.`when`(persistence).base64encodeToString(ArgumentMatchers.any(), ArgumentMatchers.anyInt())
|
||||
}
|
||||
|
||||
// Add a JUnit rule that will setup the @Mock annotated vars and log.
|
||||
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
|
||||
@get:Rule
|
||||
val mockitoRule: MockitoRule = MockitoJUnit.rule()
|
||||
|
||||
@Before
|
||||
fun setupLocale() {
|
||||
Locale.setDefault(Locale.ENGLISH)
|
||||
System.setProperty("disableFirebase", "true")
|
||||
}
|
||||
|
||||
// Workaround for Kotlin nullability.
|
||||
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
|
||||
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
|
||||
fun <T> anyObject(): T {
|
||||
Mockito.any<T>()
|
||||
return uninitialized()
|
||||
}
|
||||
|
||||
@Suppress("Unchecked_Cast")
|
||||
fun <T> uninitialized(): T = null as T
|
||||
}
|
|
@ -1,35 +1,20 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import org.junit.Before;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import info.nightscout.androidaps.TestBase;
|
||||
import info.nightscout.androidaps.interaction.utils.Constants;
|
||||
import info.nightscout.androidaps.interaction.utils.WearUtil;
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker;
|
||||
|
||||
import static org.hamcrest.number.OrderingComparison.comparesEqualTo;
|
||||
import static org.hamcrest.number.OrderingComparison.greaterThan;
|
||||
import static org.hamcrest.number.OrderingComparison.lessThan;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { WearUtil.class } )
|
||||
public class BgWatchDataTest {
|
||||
|
||||
@Before
|
||||
public void mock() throws Exception {
|
||||
WearUtilMocker.prepareMockNoReal();
|
||||
}
|
||||
public class BgWatchDataTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void bgWatchDataHashTest() {
|
||||
|
@ -41,6 +26,7 @@ public class BgWatchDataTest {
|
|||
Set<BgWatchData> set = new HashSet<>();
|
||||
|
||||
// THEN
|
||||
//noinspection ConstantConditions
|
||||
assertFalse(set.contains(inserted));
|
||||
set.add(inserted);
|
||||
assertTrue(set.contains(inserted));
|
||||
|
@ -68,15 +54,13 @@ public class BgWatchDataTest {
|
|||
);
|
||||
BgWatchData item4differentTime = new BgWatchData(
|
||||
88.0, 160.0, 90.0,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2, 1
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 2, 1
|
||||
);
|
||||
|
||||
// THEN
|
||||
assertEquals(item1, item2sameTimeSameColor);
|
||||
assertNotEquals(item1, item3sameTimeSameDiffColor);
|
||||
assertNotEquals(item1, item4differentTime);
|
||||
|
||||
assertNotEquals("aa bbb", item1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +71,7 @@ public class BgWatchDataTest {
|
|||
// GIVEN
|
||||
BgWatchData item1 = new BgWatchData(
|
||||
85, 160.0, 90.0,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2, 1
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 2, 1
|
||||
);
|
||||
|
||||
BgWatchData item2 = new BgWatchData(
|
||||
|
@ -97,7 +81,7 @@ public class BgWatchDataTest {
|
|||
|
||||
BgWatchData item3 = new BgWatchData(
|
||||
80, 190, 50.0,
|
||||
WearUtilMocker.REF_NOW + Constants.MINUTE_IN_MS*5, 0
|
||||
WearUtilMocker.REF_NOW + Constants.MINUTE_IN_MS * 5, 0
|
||||
);
|
||||
|
||||
BgWatchData item4 = new BgWatchData(
|
||||
|
@ -106,8 +90,8 @@ public class BgWatchDataTest {
|
|||
);
|
||||
|
||||
// THEN
|
||||
assertThat(item2, lessThan(item1));
|
||||
assertThat(item2, greaterThan(item3));
|
||||
assertThat(item2, comparesEqualTo(item4));
|
||||
assertTrue(item2.compareTo(item1) < 0);
|
||||
assertTrue(item2.compareTo(item3) > 0);
|
||||
assertEquals(0, item2.compareTo(item4));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,43 +1,21 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import android.content.Context;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
||||
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.nightscout.androidaps.Aaps;
|
||||
import info.nightscout.androidaps.TestBase;
|
||||
import info.nightscout.androidaps.interaction.utils.Constants;
|
||||
import info.nightscout.androidaps.interaction.utils.Persistence;
|
||||
import info.nightscout.androidaps.interaction.utils.WearUtil;
|
||||
import info.nightscout.androidaps.testing.mockers.AAPSMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.AndroidMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker;
|
||||
import info.nightscout.androidaps.testing.mocks.BundleMock;
|
||||
import info.nightscout.androidaps.testing.mocks.IntentMock;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, Aaps.class, android.util.Base64.class, Intent.class } )
|
||||
public class RawDataSgvDisplayDataTest {
|
||||
|
||||
@Before
|
||||
public void mock() throws Exception {
|
||||
AAPSMocker.prepareMock();
|
||||
AAPSMocker.resetMockedSharedPrefs();
|
||||
AndroidMocker.mockBase64();
|
||||
WearUtilMocker.prepareMockNoReal();
|
||||
}
|
||||
public class RawDataSgvDisplayDataTest extends TestBase {
|
||||
|
||||
//==============================================================================================
|
||||
// SGV DATA
|
||||
|
@ -56,30 +34,29 @@ public class RawDataSgvDisplayDataTest {
|
|||
}
|
||||
|
||||
private void assertDataEmpty(RawDisplayData newRaw) {
|
||||
assertThat(newRaw.sgvLevel, is(0L));
|
||||
assertThat(newRaw.datetime, is(0L));
|
||||
assertThat(newRaw.sSgv, is("---"));
|
||||
assertThat(newRaw.sDirection, is("--"));
|
||||
assertThat(newRaw.sDelta, is("--"));
|
||||
assertThat(newRaw.sAvgDelta, is("--"));
|
||||
assertThat(newRaw.sUnits, is("-"));
|
||||
assertEquals(newRaw.sgvLevel, 0L);
|
||||
assertEquals(newRaw.datetime, 0L);
|
||||
assertEquals(newRaw.sSgv, "---");
|
||||
assertEquals(newRaw.sDirection, "--");
|
||||
assertEquals(newRaw.sDelta, "--");
|
||||
assertEquals(newRaw.sAvgDelta, "--");
|
||||
assertEquals(newRaw.sUnits, "-");
|
||||
}
|
||||
|
||||
private void assertDataOk(RawDisplayData newRaw) {
|
||||
assertThat(newRaw.sgvLevel, is(1L));
|
||||
assertThat(newRaw.datetime, is(WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS));
|
||||
assertThat(newRaw.sSgv, is("106"));
|
||||
assertThat(newRaw.sDirection, is("↗"));
|
||||
assertThat(newRaw.sDelta, is("5.4"));
|
||||
assertThat(newRaw.sAvgDelta, is("3.7"));
|
||||
assertThat(newRaw.sUnits, is("mg/dl"));
|
||||
assertEquals(newRaw.sgvLevel, 1L);
|
||||
assertEquals(newRaw.datetime, WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS);
|
||||
assertEquals(newRaw.sSgv, "106");
|
||||
assertEquals(newRaw.sDirection, "↗");
|
||||
assertEquals(newRaw.sDelta, "5.4");
|
||||
assertEquals(newRaw.sAvgDelta, "3.7");
|
||||
assertEquals(newRaw.sUnits, "mg/dl");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDataFromEmptyPersistenceTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
newRaw.updateFromPersistence(persistence);
|
||||
|
@ -91,11 +68,10 @@ public class RawDataSgvDisplayDataTest {
|
|||
@Test
|
||||
public void updateDataFromPersistenceTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
Persistence.storeDataMap(RawDisplayData.DATA_PERSISTENCE_KEY, dataMapForData());
|
||||
persistence.storeDataMap(RawDisplayData.DATA_PERSISTENCE_KEY, dataMapForData());
|
||||
newRaw.updateFromPersistence(persistence);
|
||||
|
||||
// THEN
|
||||
|
@ -105,11 +81,10 @@ public class RawDataSgvDisplayDataTest {
|
|||
@Test
|
||||
public void partialUpdateDataFromPersistenceTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
Persistence.storeDataMap(RawDisplayData.DATA_PERSISTENCE_KEY, dataMapForData());
|
||||
persistence.storeDataMap(RawDisplayData.DATA_PERSISTENCE_KEY, dataMapForData());
|
||||
newRaw.updateForComplicationsFromPersistence(persistence);
|
||||
|
||||
// THEN
|
||||
|
@ -123,7 +98,7 @@ public class RawDataSgvDisplayDataTest {
|
|||
Bundle bundle = BundleMock.mock(dataMapForData());
|
||||
|
||||
intent.putExtra("data", bundle);
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
newRaw.updateDataFromMessage(intent, null);
|
||||
|
@ -136,7 +111,7 @@ public class RawDataSgvDisplayDataTest {
|
|||
public void updateDataFromEmptyMessageTest() {
|
||||
// GIVEN
|
||||
Intent intent = IntentMock.mock();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
newRaw.updateDataFromMessage(intent, null);
|
||||
|
|
|
@ -1,27 +1,18 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import android.content.Context;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
||||
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 java.util.ArrayList;
|
||||
|
||||
import info.nightscout.androidaps.Aaps;
|
||||
import info.nightscout.androidaps.TestBase;
|
||||
import info.nightscout.androidaps.interaction.utils.Constants;
|
||||
import info.nightscout.androidaps.interaction.utils.Persistence;
|
||||
import info.nightscout.androidaps.interaction.utils.WearUtil;
|
||||
import info.nightscout.androidaps.testing.mockers.AAPSMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.AndroidMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker;
|
||||
import info.nightscout.androidaps.testing.mocks.BundleMock;
|
||||
import info.nightscout.androidaps.testing.mocks.IntentMock;
|
||||
|
@ -30,20 +21,9 @@ import info.nightscout.androidaps.testing.utils.BgWatchDataExt;
|
|||
import info.nightscout.androidaps.testing.utils.BolusWatchDataExt;
|
||||
import info.nightscout.androidaps.testing.utils.TempWatchDataExt;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class RawDisplayDataBasalsTest extends TestBase {
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, Aaps.class, android.util.Base64.class, Intent.class } )
|
||||
public class RawDisplayDataBasalsTest {
|
||||
|
||||
@Before
|
||||
public void mock() throws Exception {
|
||||
AAPSMocker.prepareMock();
|
||||
AAPSMocker.resetMockedSharedPrefs();
|
||||
AndroidMocker.mockBase64();
|
||||
WearUtilMocker.prepareMockNoReal();
|
||||
}
|
||||
|
||||
//==============================================================================================
|
||||
// BASALS for chart
|
||||
|
@ -55,17 +35,17 @@ public class RawDisplayDataBasalsTest {
|
|||
|
||||
ArrayList<DataMap> temps = new ArrayList<>();
|
||||
DataMap temp = new DataMap();
|
||||
temp.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*20);
|
||||
temp.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 20);
|
||||
temp.putDouble("startBasal", 1.5);
|
||||
temp.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*10);
|
||||
temp.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 10);
|
||||
temp.putDouble("endbasal", 1.5);
|
||||
temp.putDouble("amount", 1.8);
|
||||
temps.add(temp);
|
||||
|
||||
DataMap temp2 = new DataMap();
|
||||
temp2.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*10);
|
||||
temp2.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 10);
|
||||
temp2.putDouble("startBasal", 1.3);
|
||||
temp2.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2);
|
||||
temp2.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 2);
|
||||
temp2.putDouble("endbasal", 1.3);
|
||||
temp2.putDouble("amount", 2.3);
|
||||
temps.add(temp2);
|
||||
|
@ -73,15 +53,15 @@ public class RawDisplayDataBasalsTest {
|
|||
|
||||
ArrayList<DataMap> basals = new ArrayList<>();
|
||||
DataMap basal = new DataMap();
|
||||
basal.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*20);
|
||||
basal.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2);
|
||||
basal.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 20);
|
||||
basal.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 2);
|
||||
basal.putDouble("amount", 1.2);
|
||||
basals.add(basal);
|
||||
dataMap.putDataMapArrayList("basals", basals);
|
||||
|
||||
ArrayList<DataMap> boluses = new ArrayList<>();
|
||||
DataMap bolus = new DataMap();
|
||||
bolus.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*17);
|
||||
bolus.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 17);
|
||||
bolus.putDouble("bolus", 5.5);
|
||||
bolus.putDouble("carbs", 20.0);
|
||||
bolus.putBoolean("isSMB", false);
|
||||
|
@ -89,7 +69,7 @@ public class RawDisplayDataBasalsTest {
|
|||
boluses.add(bolus);
|
||||
|
||||
DataMap bolus2 = new DataMap();
|
||||
bolus2.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*11);
|
||||
bolus2.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 11);
|
||||
bolus2.putDouble("bolus", 3.0);
|
||||
bolus2.putDouble("carbs", 0.0);
|
||||
bolus2.putBoolean("isSMB", false);
|
||||
|
@ -97,7 +77,7 @@ public class RawDisplayDataBasalsTest {
|
|||
boluses.add(bolus2);
|
||||
|
||||
DataMap bolus3 = new DataMap();
|
||||
bolus3.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*3);
|
||||
bolus3.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 3);
|
||||
bolus3.putDouble("bolus", 0.0);
|
||||
bolus3.putDouble("carbs", 15.0);
|
||||
bolus3.putBoolean("isSMB", true);
|
||||
|
@ -107,10 +87,10 @@ public class RawDisplayDataBasalsTest {
|
|||
dataMap.putDataMapArrayList("boluses", boluses);
|
||||
|
||||
ArrayList<DataMap> predictions = new ArrayList<>();
|
||||
for (int i=0; i<10; i++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
DataMap prediction = new DataMap();
|
||||
prediction.putLong("timestamp", WearUtilMocker.REF_NOW + Constants.MINUTE_IN_MS*i);
|
||||
prediction.putDouble("sgv", 160-4*i);
|
||||
prediction.putLong("timestamp", WearUtilMocker.REF_NOW + Constants.MINUTE_IN_MS * i);
|
||||
prediction.putDouble("sgv", 160 - 4 * i);
|
||||
prediction.putInt("color", 0);
|
||||
predictions.add(prediction);
|
||||
}
|
||||
|
@ -120,83 +100,82 @@ public class RawDisplayDataBasalsTest {
|
|||
}
|
||||
|
||||
private void assertBasalsEmpty(RawDisplayData newRaw) {
|
||||
assertThat(newRaw.tempWatchDataList.size(), is(0));
|
||||
assertThat(newRaw.basalWatchDataList.size(), is(0));
|
||||
assertThat(newRaw.bolusWatchDataList.size(), is(0));
|
||||
assertThat(newRaw.predictionList.size(), is(0));
|
||||
assertEquals(newRaw.tempWatchDataList.size(), 0);
|
||||
assertEquals(newRaw.basalWatchDataList.size(), 0);
|
||||
assertEquals(newRaw.bolusWatchDataList.size(), 0);
|
||||
assertEquals(newRaw.predictionList.size(), 0);
|
||||
}
|
||||
|
||||
private void assertBasalsOk(RawDisplayData newRaw) {
|
||||
assertThat(newRaw.tempWatchDataList.size(), is(2));
|
||||
assertThat(newRaw.basalWatchDataList.size(), is(1));
|
||||
assertThat(newRaw.bolusWatchDataList.size(), is(3));
|
||||
assertThat(newRaw.predictionList.size(), is(10));
|
||||
assertEquals(newRaw.tempWatchDataList.size(), 2);
|
||||
assertEquals(newRaw.basalWatchDataList.size(), 1);
|
||||
assertEquals(newRaw.bolusWatchDataList.size(), 3);
|
||||
assertEquals(newRaw.predictionList.size(), 10);
|
||||
|
||||
assertThat(new TempWatchDataExt(newRaw.tempWatchDataList.get(0)), is(TempWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*20,
|
||||
assertEquals(new TempWatchDataExt(newRaw.tempWatchDataList.get(0)), TempWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 20,
|
||||
1.5,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*10,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 10,
|
||||
1.5,
|
||||
1.8
|
||||
)));
|
||||
));
|
||||
|
||||
assertThat(new TempWatchDataExt(newRaw.tempWatchDataList.get(1)), is(TempWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*10,
|
||||
assertEquals(new TempWatchDataExt(newRaw.tempWatchDataList.get(1)), TempWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 10,
|
||||
1.3,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 2,
|
||||
1.3,
|
||||
2.3
|
||||
)));
|
||||
));
|
||||
|
||||
assertThat(new BasalWatchDataExt(newRaw.basalWatchDataList.get(0)), is(BasalWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*20,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2,
|
||||
assertEquals(new BasalWatchDataExt(newRaw.basalWatchDataList.get(0)), BasalWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 20,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 2,
|
||||
1.2
|
||||
)));
|
||||
));
|
||||
|
||||
assertThat(new BolusWatchDataExt(newRaw.bolusWatchDataList.get(0)), is(BolusWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*17,
|
||||
assertEquals(new BolusWatchDataExt(newRaw.bolusWatchDataList.get(0)), BolusWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 17,
|
||||
5.5,
|
||||
20,
|
||||
false,
|
||||
true
|
||||
)));
|
||||
));
|
||||
|
||||
assertThat(new BolusWatchDataExt(newRaw.bolusWatchDataList.get(1)), is(BolusWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*11,
|
||||
assertEquals(new BolusWatchDataExt(newRaw.bolusWatchDataList.get(1)), BolusWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 11,
|
||||
3,
|
||||
0,
|
||||
false,
|
||||
true
|
||||
)));
|
||||
));
|
||||
|
||||
assertThat(new BolusWatchDataExt(newRaw.bolusWatchDataList.get(2)), is(BolusWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*3,
|
||||
assertEquals(new BolusWatchDataExt(newRaw.bolusWatchDataList.get(2)), BolusWatchDataExt.build(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 3,
|
||||
0,
|
||||
15,
|
||||
true,
|
||||
false
|
||||
)));
|
||||
));
|
||||
|
||||
|
||||
assertThat(new BgWatchDataExt(newRaw.predictionList.get(3)), is(BgWatchDataExt.build(
|
||||
160-4*3,
|
||||
WearUtilMocker.REF_NOW + Constants.MINUTE_IN_MS*3,
|
||||
assertEquals(new BgWatchDataExt(newRaw.predictionList.get(3)), BgWatchDataExt.build(
|
||||
160 - 4 * 3,
|
||||
WearUtilMocker.REF_NOW + Constants.MINUTE_IN_MS * 3,
|
||||
0
|
||||
)));
|
||||
));
|
||||
|
||||
assertThat(new BgWatchDataExt(newRaw.predictionList.get(7)), is(BgWatchDataExt.build(
|
||||
160-4*7,
|
||||
WearUtilMocker.REF_NOW + Constants.MINUTE_IN_MS*7,
|
||||
assertEquals(new BgWatchDataExt(newRaw.predictionList.get(7)), BgWatchDataExt.build(
|
||||
160 - 4 * 7,
|
||||
WearUtilMocker.REF_NOW + Constants.MINUTE_IN_MS * 7,
|
||||
0
|
||||
)));
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBasalsFromEmptyPersistenceTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
newRaw.updateFromPersistence(persistence);
|
||||
|
@ -208,11 +187,10 @@ public class RawDisplayDataBasalsTest {
|
|||
@Test
|
||||
public void updateBasalsFromPersistenceTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
Persistence.storeDataMap(RawDisplayData.BASALS_PERSISTENCE_KEY, dataMapForBasals());
|
||||
persistence.storeDataMap(RawDisplayData.BASALS_PERSISTENCE_KEY, dataMapForBasals());
|
||||
newRaw.updateFromPersistence(persistence);
|
||||
|
||||
// THEN
|
||||
|
@ -222,11 +200,10 @@ public class RawDisplayDataBasalsTest {
|
|||
@Test
|
||||
public void partialUpdateBasalsFromPersistenceTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
Persistence.storeDataMap(RawDisplayData.BASALS_PERSISTENCE_KEY, dataMapForBasals());
|
||||
persistence.storeDataMap(RawDisplayData.BASALS_PERSISTENCE_KEY, dataMapForBasals());
|
||||
newRaw.updateForComplicationsFromPersistence(persistence);
|
||||
|
||||
// THEN
|
||||
|
@ -240,7 +217,7 @@ public class RawDisplayDataBasalsTest {
|
|||
Bundle bundle = BundleMock.mock(dataMapForBasals());
|
||||
|
||||
intent.putExtra("basals", bundle);
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
newRaw.updateBasalsFromMessage(intent, null);
|
||||
|
@ -253,7 +230,7 @@ public class RawDisplayDataBasalsTest {
|
|||
public void updateBasalsFromEmptyMessageTest() {
|
||||
// GIVEN
|
||||
Intent intent = IntentMock.mock();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
newRaw.updateBasalsFromMessage(intent, null);
|
||||
|
|
|
@ -1,31 +1,20 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
||||
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 java.util.ArrayList;
|
||||
|
||||
import info.nightscout.androidaps.TestBase;
|
||||
import info.nightscout.androidaps.interaction.utils.Constants;
|
||||
import info.nightscout.androidaps.interaction.utils.WearUtil;
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker;
|
||||
import info.nightscout.androidaps.testing.utils.BgWatchDataExt;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { WearUtil.class } )
|
||||
public class RawDisplayDataBgEntriesTest {
|
||||
|
||||
@Before
|
||||
public void mock() throws Exception {
|
||||
WearUtilMocker.prepareMockNoReal();
|
||||
}
|
||||
@SuppressWarnings("PointlessArithmeticExpression")
|
||||
public class RawDisplayDataBgEntriesTest extends TestBase {
|
||||
|
||||
//==============================================================================================
|
||||
// ENTRIES for chart
|
||||
|
@ -35,10 +24,10 @@ public class RawDisplayDataBgEntriesTest {
|
|||
|
||||
DataMap dataMap = new DataMap();
|
||||
ArrayList<DataMap> entries = new ArrayList<>();
|
||||
for (int i=0; i<12; i++) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
DataMap entry = new DataMap();
|
||||
entry.putLong("timestamp", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*4*(16-i));
|
||||
entry.putDouble("sgvDouble", 145.0-5*i);
|
||||
entry.putLong("timestamp", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 4 * (16 - i));
|
||||
entry.putDouble("sgvDouble", 145.0 - 5 * i);
|
||||
entry.putDouble("high", 170.0);
|
||||
entry.putDouble("low", 80.0);
|
||||
entry.putInt("color", 0);
|
||||
|
@ -62,85 +51,85 @@ public class RawDisplayDataBgEntriesTest {
|
|||
@Test
|
||||
public void addToWatchSetTest() {
|
||||
// GIVEN
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
DataMap multipleEntries = dataMapForEntries();
|
||||
DataMap singleEntry1 = dataMapForEntries(WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*4*2,92);
|
||||
DataMap singleEntry2 = dataMapForEntries(WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*4*1,88);
|
||||
DataMap singleEntry1 = dataMapForEntries(WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 4 * 2, 92);
|
||||
DataMap singleEntry2 = dataMapForEntries(WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 4 * 1, 88);
|
||||
|
||||
// WHEN, THEN
|
||||
// add list
|
||||
newRaw.addToWatchSet(multipleEntries);
|
||||
assertThat(newRaw.bgDataList.size(), is(12));
|
||||
assertEquals(newRaw.bgDataList.size(), 12);
|
||||
|
||||
assertThat(new BgWatchDataExt(newRaw.bgDataList.get(5)),
|
||||
is(new BgWatchDataExt(new BgWatchData(
|
||||
assertEquals(new BgWatchDataExt(newRaw.bgDataList.get(5)),
|
||||
new BgWatchDataExt(new BgWatchData(
|
||||
120.0, 170.0, 80.0,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*4*(16-5), 0
|
||||
))));
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 4 * (16 - 5), 0
|
||||
)));
|
||||
|
||||
assertThat(new BgWatchDataExt(newRaw.bgDataList.get(11)),
|
||||
is(new BgWatchDataExt(new BgWatchData(
|
||||
assertEquals(new BgWatchDataExt(newRaw.bgDataList.get(11)),
|
||||
new BgWatchDataExt(new BgWatchData(
|
||||
90.0, 170.0, 80.0,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*4*(16-11), 0
|
||||
))));
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 4 * (16 - 11), 0
|
||||
)));
|
||||
|
||||
// add single entries
|
||||
newRaw.addToWatchSet(singleEntry1);
|
||||
newRaw.addToWatchSet(singleEntry2);
|
||||
assertThat(newRaw.bgDataList.size(), is(14));
|
||||
assertEquals(newRaw.bgDataList.size(), 14);
|
||||
|
||||
assertThat(new BgWatchDataExt(newRaw.bgDataList.get(12)),
|
||||
is(new BgWatchDataExt(new BgWatchData(
|
||||
assertEquals(new BgWatchDataExt(newRaw.bgDataList.get(12)),
|
||||
new BgWatchDataExt(new BgWatchData(
|
||||
92.0, 160.0, 90.0,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*4*2, 1
|
||||
))));
|
||||
assertThat(new BgWatchDataExt(newRaw.bgDataList.get(13)),
|
||||
is(new BgWatchDataExt(new BgWatchData(
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 4 * 2, 1
|
||||
)));
|
||||
assertEquals(new BgWatchDataExt(newRaw.bgDataList.get(13)),
|
||||
new BgWatchDataExt(new BgWatchData(
|
||||
88.0, 160.0, 90.0,
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*4*1, 1
|
||||
))));
|
||||
WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 4 * 1, 1
|
||||
)));
|
||||
|
||||
// ignore duplicates
|
||||
newRaw.addToWatchSet(singleEntry2);
|
||||
assertThat(newRaw.bgDataList.size(), is(14));
|
||||
assertEquals(newRaw.bgDataList.size(), 14);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addToWatchSetCleanupOldTest() {
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
newRaw.addToWatchSet(dataMapForEntries(WearUtil.timestamp(),125));
|
||||
assertThat(newRaw.bgDataList.size(), is(1));
|
||||
newRaw.addToWatchSet(dataMapForEntries(getWearUtil().timestamp(), 125));
|
||||
assertEquals(newRaw.bgDataList.size(), 1);
|
||||
|
||||
WearUtilMocker.progressClock(Constants.HOUR_IN_MS*2);
|
||||
newRaw.addToWatchSet(dataMapForEntries(WearUtil.timestamp(),140));
|
||||
assertThat(newRaw.bgDataList.size(), is(2));
|
||||
getWearUtilMocker().progressClock(Constants.HOUR_IN_MS * 2);
|
||||
newRaw.addToWatchSet(dataMapForEntries(getWearUtil().timestamp(), 140));
|
||||
assertEquals(newRaw.bgDataList.size(), 2);
|
||||
|
||||
WearUtilMocker.progressClock(Constants.HOUR_IN_MS*1);
|
||||
newRaw.addToWatchSet(dataMapForEntries(WearUtil.timestamp(),150));
|
||||
WearUtilMocker.progressClock(Constants.HOUR_IN_MS*1 +Constants.MINUTE_IN_MS*30);
|
||||
newRaw.addToWatchSet(dataMapForEntries(WearUtil.timestamp(),101));
|
||||
assertThat(newRaw.bgDataList.size(), is(4));
|
||||
getWearUtilMocker().progressClock(Constants.HOUR_IN_MS * 1);
|
||||
newRaw.addToWatchSet(dataMapForEntries(getWearUtil().timestamp(), 150));
|
||||
getWearUtilMocker().progressClock(Constants.HOUR_IN_MS * 1 + Constants.MINUTE_IN_MS * 30);
|
||||
newRaw.addToWatchSet(dataMapForEntries(getWearUtil().timestamp(), 101));
|
||||
assertEquals(newRaw.bgDataList.size(), 4);
|
||||
|
||||
WearUtilMocker.progressClock(Constants.MINUTE_IN_MS*30);
|
||||
newRaw.addToWatchSet(dataMapForEntries(WearUtil.timestamp(),90));
|
||||
assertThat(newRaw.bgDataList.size(), is(5));
|
||||
getWearUtilMocker().progressClock(Constants.MINUTE_IN_MS * 30);
|
||||
newRaw.addToWatchSet(dataMapForEntries(getWearUtil().timestamp(), 90));
|
||||
assertEquals(newRaw.bgDataList.size(), 5);
|
||||
|
||||
WearUtilMocker.progressClock(Constants.HOUR_IN_MS*1 +Constants.MINUTE_IN_MS*30);
|
||||
newRaw.addToWatchSet(dataMapForEntries(WearUtil.timestamp(),80));
|
||||
assertThat(newRaw.bgDataList.size(), is(5));
|
||||
getWearUtilMocker().progressClock(Constants.HOUR_IN_MS * 1 + Constants.MINUTE_IN_MS * 30);
|
||||
newRaw.addToWatchSet(dataMapForEntries(getWearUtil().timestamp(), 80));
|
||||
assertEquals(newRaw.bgDataList.size(), 5);
|
||||
|
||||
WearUtilMocker.progressClock(Constants.HOUR_IN_MS*4);
|
||||
newRaw.addToWatchSet(dataMapForEntries(WearUtil.timestamp(),92));
|
||||
assertThat(newRaw.bgDataList.size(), is(2));
|
||||
getWearUtilMocker().progressClock(Constants.HOUR_IN_MS * 4);
|
||||
newRaw.addToWatchSet(dataMapForEntries(getWearUtil().timestamp(), 92));
|
||||
assertEquals(newRaw.bgDataList.size(), 2);
|
||||
|
||||
WearUtilMocker.progressClock(Constants.HOUR_IN_MS*5 +Constants.MINUTE_IN_MS*30);
|
||||
newRaw.addToWatchSet(dataMapForEntries(WearUtil.timestamp(),107));
|
||||
assertThat(newRaw.bgDataList.size(), is(1));
|
||||
getWearUtilMocker().progressClock(Constants.HOUR_IN_MS * 5 + Constants.MINUTE_IN_MS * 30);
|
||||
newRaw.addToWatchSet(dataMapForEntries(getWearUtil().timestamp(), 107));
|
||||
assertEquals(newRaw.bgDataList.size(), 1);
|
||||
|
||||
WearUtilMocker.progressClock(Constants.HOUR_IN_MS*6 +Constants.MINUTE_IN_MS*30);
|
||||
newRaw.addToWatchSet(dataMapForEntries(WearUtil.timestamp()-Constants.HOUR_IN_MS*6,138));
|
||||
assertThat(newRaw.bgDataList.size(), is(0));
|
||||
getWearUtilMocker().progressClock(Constants.HOUR_IN_MS * 6 + Constants.MINUTE_IN_MS * 30);
|
||||
newRaw.addToWatchSet(dataMapForEntries(getWearUtil().timestamp() - Constants.HOUR_IN_MS * 6, 138));
|
||||
assertEquals(newRaw.bgDataList.size(), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,53 +1,40 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import android.content.Context;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
||||
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.nightscout.androidaps.Aaps;
|
||||
import info.nightscout.androidaps.TestBase;
|
||||
import info.nightscout.androidaps.interaction.utils.Constants;
|
||||
import info.nightscout.androidaps.interaction.utils.Persistence;
|
||||
import info.nightscout.androidaps.interaction.utils.WearUtil;
|
||||
import info.nightscout.androidaps.testing.mockers.AAPSMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.AndroidMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.RawDataMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker;
|
||||
import info.nightscout.androidaps.testing.mocks.BundleMock;
|
||||
import info.nightscout.androidaps.testing.mocks.IntentMock;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@SuppressWarnings("SimplifiableAssertion")
|
||||
public class RawDisplayDataStatusTest extends TestBase {
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, Aaps.class, android.util.Base64.class, Intent.class } )
|
||||
public class RawDisplayDataStatusTest {
|
||||
private RawDataMocker rawDataMocker;
|
||||
|
||||
@Before
|
||||
public void mock() throws Exception {
|
||||
AAPSMocker.prepareMock();
|
||||
AAPSMocker.resetMockedSharedPrefs();
|
||||
AndroidMocker.mockBase64();
|
||||
WearUtilMocker.prepareMockNoReal();
|
||||
public void mock() {
|
||||
rawDataMocker = new RawDataMocker(getWearUtil());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("AssertBetweenInconvertibleTypes") @Test
|
||||
public void toDebugStringTest() {
|
||||
RawDisplayData raw = RawDataMocker.rawDelta(5, "1.5");
|
||||
RawDisplayData raw = rawDataMocker.rawDelta(5, "1.5");
|
||||
raw.externalStatusString = "placeholder-here";
|
||||
|
||||
assertThat(raw.datetime, is(WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*5));
|
||||
assertThat(raw.toDebugString(), containsString("placeholder-here"));
|
||||
assertEquals(raw.datetime, WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 5);
|
||||
assertTrue(raw.toDebugString().contains("placeholder-here"));
|
||||
}
|
||||
|
||||
//==============================================================================================
|
||||
|
@ -60,54 +47,53 @@ public class RawDisplayDataStatusTest {
|
|||
dataMap.putString("battery", "76");
|
||||
dataMap.putString("rigBattery", "40%");
|
||||
dataMap.putBoolean("detailedIob", true);
|
||||
dataMap.putString("iobSum", "12.5") ;
|
||||
dataMap.putString("iobDetail","(11,2|1,3)");
|
||||
dataMap.putString("cob","5(10)g");
|
||||
dataMap.putString("iobSum", "12.5");
|
||||
dataMap.putString("iobDetail", "(11,2|1,3)");
|
||||
dataMap.putString("cob", "5(10)g");
|
||||
dataMap.putString("bgi", "13");
|
||||
dataMap.putBoolean("showBgi", false);
|
||||
dataMap.putString("externalStatusString", "");
|
||||
dataMap.putInt("batteryLevel", 1);
|
||||
dataMap.putLong("openApsStatus", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2);
|
||||
dataMap.putLong("openApsStatus", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 2);
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
private void assertStatusEmpty(RawDisplayData newRaw) {
|
||||
assertThat(newRaw.sBasalRate, is("-.--U/h"));
|
||||
assertThat(newRaw.sUploaderBattery, is("--"));
|
||||
assertThat(newRaw.sRigBattery, is("--"));
|
||||
assertThat(newRaw.detailedIOB, is(false));
|
||||
assertThat(newRaw.sIOB1, is("IOB"));
|
||||
assertThat(newRaw.sIOB2, is("-.--"));
|
||||
assertThat(newRaw.sCOB1, is("Carb"));
|
||||
assertThat(newRaw.sCOB2, is("--g"));
|
||||
assertThat(newRaw.sBgi, is("--"));
|
||||
assertThat(newRaw.showBGI, is(false));
|
||||
assertThat(newRaw.externalStatusString, is("no status"));
|
||||
assertThat(newRaw.batteryLevel, is(1));
|
||||
assertThat(newRaw.openApsStatus, is(-1L));
|
||||
assertEquals(newRaw.sBasalRate, "-.--U/h");
|
||||
assertEquals(newRaw.sUploaderBattery, "--");
|
||||
assertEquals(newRaw.sRigBattery, "--");
|
||||
assertEquals(newRaw.detailedIOB, false);
|
||||
assertEquals(newRaw.sIOB1, "IOB");
|
||||
assertEquals(newRaw.sIOB2, "-.--");
|
||||
assertEquals(newRaw.sCOB1, "Carb");
|
||||
assertEquals(newRaw.sCOB2, "--g");
|
||||
assertEquals(newRaw.sBgi, "--");
|
||||
assertEquals(newRaw.showBGI, false);
|
||||
assertEquals(newRaw.externalStatusString, "no status");
|
||||
assertEquals(newRaw.batteryLevel, 1);
|
||||
assertEquals(newRaw.openApsStatus, -1L);
|
||||
}
|
||||
|
||||
private void assertStatusOk(RawDisplayData newRaw) {
|
||||
assertThat(newRaw.sBasalRate, is("120%"));
|
||||
assertThat(newRaw.sUploaderBattery, is("76"));
|
||||
assertThat(newRaw.sRigBattery, is("40%"));
|
||||
assertThat(newRaw.detailedIOB, is(true));
|
||||
assertThat(newRaw.sIOB1, is("12.5U"));
|
||||
assertThat(newRaw.sIOB2, is("(11,2|1,3)"));
|
||||
assertThat(newRaw.sCOB1, is("Carb"));
|
||||
assertThat(newRaw.sCOB2, is("5(10)g"));
|
||||
assertThat(newRaw.sBgi, is("13"));
|
||||
assertThat(newRaw.showBGI, is(false));
|
||||
assertThat(newRaw.externalStatusString, is(""));
|
||||
assertThat(newRaw.batteryLevel, is(1));
|
||||
assertThat(newRaw.openApsStatus, is(WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2));
|
||||
assertEquals(newRaw.sBasalRate, "120%");
|
||||
assertEquals(newRaw.sUploaderBattery, "76");
|
||||
assertEquals(newRaw.sRigBattery, "40%");
|
||||
assertEquals(newRaw.detailedIOB, true);
|
||||
assertEquals(newRaw.sIOB1, "12.5U");
|
||||
assertEquals(newRaw.sIOB2, "(11,2|1,3)");
|
||||
assertEquals(newRaw.sCOB1, "Carb");
|
||||
assertEquals(newRaw.sCOB2, "5(10)g");
|
||||
assertEquals(newRaw.sBgi, "13");
|
||||
assertEquals(newRaw.showBGI, false);
|
||||
assertEquals(newRaw.externalStatusString, "");
|
||||
assertEquals(newRaw.batteryLevel, 1);
|
||||
assertEquals(newRaw.openApsStatus, WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS * 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateStatusFromEmptyPersistenceTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
newRaw.updateFromPersistence(persistence);
|
||||
|
@ -119,11 +105,10 @@ public class RawDisplayDataStatusTest {
|
|||
@Test
|
||||
public void updateStatusFromPersistenceTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
Persistence.storeDataMap(RawDisplayData.STATUS_PERSISTENCE_KEY, dataMapForStatus());
|
||||
persistence.storeDataMap(RawDisplayData.STATUS_PERSISTENCE_KEY, dataMapForStatus());
|
||||
newRaw.updateFromPersistence(persistence);
|
||||
|
||||
// THEN
|
||||
|
@ -133,11 +118,10 @@ public class RawDisplayDataStatusTest {
|
|||
@Test
|
||||
public void partialUpdateStatusFromPersistenceTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
Persistence.storeDataMap(RawDisplayData.STATUS_PERSISTENCE_KEY, dataMapForStatus());
|
||||
persistence.storeDataMap(RawDisplayData.STATUS_PERSISTENCE_KEY, dataMapForStatus());
|
||||
newRaw.updateForComplicationsFromPersistence(persistence);
|
||||
|
||||
// THEN
|
||||
|
@ -151,7 +135,7 @@ public class RawDisplayDataStatusTest {
|
|||
Bundle bundle = BundleMock.mock(dataMapForStatus());
|
||||
|
||||
intent.putExtra("status", bundle);
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
newRaw.updateStatusFromMessage(intent, null);
|
||||
|
@ -164,7 +148,7 @@ public class RawDisplayDataStatusTest {
|
|||
public void updateStatusFromEmptyMessageTest() {
|
||||
// GIVEN
|
||||
Intent intent = IntentMock.mock();
|
||||
RawDisplayData newRaw = new RawDisplayData();
|
||||
RawDisplayData newRaw = new RawDisplayData(getWearUtil());
|
||||
|
||||
// WHEN
|
||||
newRaw.updateStatusFromMessage(intent, null);
|
||||
|
|
|
@ -1,204 +1,206 @@
|
|||
package info.nightscout.androidaps.interaction.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
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 org.mockito.Mock;
|
||||
|
||||
import info.nightscout.androidaps.Aaps;
|
||||
import info.nightscout.androidaps.TestBase;
|
||||
import info.nightscout.androidaps.data.RawDisplayData;
|
||||
import info.nightscout.androidaps.testing.mockers.AAPSMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.RawDataMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker;
|
||||
|
||||
import static info.nightscout.androidaps.testing.mockers.RawDataMocker.rawCob;
|
||||
import static info.nightscout.androidaps.testing.mockers.RawDataMocker.rawCobIobBr;
|
||||
import static info.nightscout.androidaps.testing.mockers.RawDataMocker.rawDelta;
|
||||
import static info.nightscout.androidaps.testing.mockers.RawDataMocker.rawIob;
|
||||
import static info.nightscout.androidaps.testing.mockers.RawDataMocker.rawSgv;
|
||||
import static info.nightscout.androidaps.testing.mockers.WearUtilMocker.backInTime;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import info.nightscout.shared.sharedPreferences.SP;
|
||||
|
||||
/**
|
||||
* This test covers DisplayFormat class (directly)
|
||||
* but also SmallestDoubleString - due to carefully chosen input data to format
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, Aaps.class } )
|
||||
public class DisplayFormatTest {
|
||||
public class DisplayFormatTest extends TestBase {
|
||||
|
||||
private DisplayFormat displayFormat;
|
||||
private RawDataMocker rawDataMocker;
|
||||
|
||||
private WearUtil wearUtil;
|
||||
private WearUtilMocker wearUtilMocker;
|
||||
@Mock SP sp;
|
||||
|
||||
@Before
|
||||
public void mock() throws Exception {
|
||||
WearUtilMocker.prepareMock();
|
||||
AAPSMocker.prepareMock();
|
||||
AAPSMocker.resetMockedSharedPrefs();
|
||||
public void mock() {
|
||||
wearUtil = spy(new WearUtil());
|
||||
rawDataMocker = new RawDataMocker(wearUtil);
|
||||
wearUtilMocker = new WearUtilMocker(wearUtil);
|
||||
wearUtilMocker.prepareMock();
|
||||
|
||||
displayFormat = new DisplayFormat();
|
||||
displayFormat.wearUtil = wearUtil;
|
||||
displayFormat.sp = sp;
|
||||
|
||||
when(sp.getBoolean("complication_unicode", true)).thenReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortTimeSinceTest() {
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,0,0)), is("0'"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,0,5)), is("0'"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,0,55)), is("0'"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 0, 0)), "0'");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 0, 5)), "0'");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 0, 55)), "0'");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,1,0)), is("1'"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,1,59)), is("1'"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 1, 0)), "1'");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 1, 59)), "1'");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,2,0)), is("2'"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,3,0)), is("3'"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,4,0)), is("4'"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 2, 0)), "2'");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 3, 0)), "3'");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 4, 0)), "4'");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,10,0)), is("10'"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,30,0)), is("30'"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,59,0)), is("59'"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,0,59,59)), is("59'"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 10, 0)), "10'");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 30, 0)), "30'");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 59, 0)), "59'");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 59, 59)), "59'");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,1,0,0)), is("1h"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,1,30,0)), is("1h"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,1,59,59)), is("1h"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 1, 0, 0)), "1h");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 1, 30, 0)), "1h");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 1, 59, 59)), "1h");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,2,0,0)), is("2h"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,3,0,0)), is("3h"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,4,0,0)), is("4h"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,5,0,0)), is("5h"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 2, 0, 0)), "2h");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 3, 0, 0)), "3h");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 4, 0, 0)), "4h");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 5, 0, 0)), "5h");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,12,0,0)), is("12h"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,18,0,0)), is("18h"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(0,23,59,59)), is("23h"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 12, 0, 0)), "12h");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 18, 0, 0)), "18h");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 23, 59, 59)), "23h");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(1,0,0,0)), is("1d"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(1,12,0,0)), is("1d"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(1,23,59,59)), is("1d"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(1, 0, 0, 0)), "1d");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(1, 12, 0, 0)), "1d");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(1, 23, 59, 59)), "1d");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(2,0,0,0)), is("2d"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(3,0,0,0)), is("3d"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(4,0,0,0)), is("4d"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(5,0,0,0)), is("5d"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(6,0,0,0)), is("6d"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(6,23,59,59)), is("6d"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(2, 0, 0, 0)), "2d");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(3, 0, 0, 0)), "3d");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(4, 0, 0, 0)), "4d");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(5, 0, 0, 0)), "5d");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(6, 0, 0, 0)), "6d");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(6, 23, 59, 59)), "6d");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(7,0,0,0)), is("1w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(8,0,0,0)), is("1w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(9,0,0,0)), is("1w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(13,23,59,59)), is("1w"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(7, 0, 0, 0)), "1w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(8, 0, 0, 0)), "1w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(9, 0, 0, 0)), "1w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(13, 23, 59, 59)), "1w");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(14,0,0,0)), is("2w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(21,0,0,0)), is("3w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(28,0,0,0)), is("4w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(31,0,0,0)), is("4w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(32,0,0,0)), is("4w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(35,0,0,0)), is("5w"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(14, 0, 0, 0)), "2w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(21, 0, 0, 0)), "3w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(28, 0, 0, 0)), "4w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(31, 0, 0, 0)), "4w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(32, 0, 0, 0)), "4w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(35, 0, 0, 0)), "5w");
|
||||
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(100,0,0,0)), is("14w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(200,0,0,0)), is("28w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(365,0,0,0)), is("52w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(366,0,0,0)), is("52w"));
|
||||
assertThat(DisplayFormat.shortTimeSince(backInTime(367,0,0,0)), is("52w"));
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(100, 0, 0, 0)), "14w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(200, 0, 0, 0)), "28w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(365, 0, 0, 0)), "52w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(366, 0, 0, 0)), "52w");
|
||||
assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(367, 0, 0, 0)), "52w");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortTrendTest() {
|
||||
RawDisplayData raw = new RawDisplayData();
|
||||
assertThat(DisplayFormat.shortTrend(raw), is("-- Δ--"));
|
||||
RawDisplayData raw = new RawDisplayData(wearUtil);
|
||||
assertEquals(displayFormat.shortTrend(raw), "-- Δ--");
|
||||
|
||||
raw.datetime = backInTime(0, 0, 2, 0);
|
||||
assertThat(DisplayFormat.shortTrend(raw), is("2' Δ--"));
|
||||
raw.datetime = wearUtilMocker.backInTime(0, 0, 2, 0);
|
||||
assertEquals(displayFormat.shortTrend(raw), "2' Δ--");
|
||||
|
||||
AAPSMocker.setMockedUnicodeComplicationsOn(true);
|
||||
when(sp.getBoolean("complication_unicode", true)).thenReturn(true);
|
||||
|
||||
// shortening
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(2, "1.2")), is("2' Δ1.2"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(11,"1.2")), is("11' 1.2"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(12,"0.7")), is("12' Δ.7"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(10,"1.0")), is("10' Δ1"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(14,"-5.0")), is("14' Δ-5"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(13,"-5.1")), is("13' -5"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(15,"0.87")), is("15' .87"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(10,"-1.78")), is("10' -2"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(3, "2.549")), is("3' 2.55"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(1, "-1.563")), is("1' -1.6"));
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1.2")), "2' Δ1.2");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(11, "1.2")), "11' 1.2");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(12, "0.7")), "12' Δ.7");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "1.0")), "10' Δ1");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(14, "-5.0")), "14' Δ-5");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(13, "-5.1")), "13' -5");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(15, "0.87")), "15' .87");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "-1.78")), "10' -2");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(3, "2.549")), "3' 2.55");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(1, "-1.563")), "1' -1.6");
|
||||
|
||||
// preserving separator
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(2, "1,2")), is("2' Δ1,2"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(15,"0,87")), is("15' ,87"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(3, "+2,549")), is("3' 2,55"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(1, "-1,563")), is("1' -1,6"));
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1,2")), "2' Δ1,2");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(15, "0,87")), "15' ,87");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(3, "+2,549")), "3' 2,55");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(1, "-1,563")), "1' -1,6");
|
||||
|
||||
// UTF-off mode - without delta symbol
|
||||
AAPSMocker.setMockedUnicodeComplicationsOn(false);
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(2, "1.2")), is("2' 1.2"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(12,"0.7")), is("12' 0.7"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(10,"1.0")), is("10' 1.0"));
|
||||
assertThat(DisplayFormat.shortTrend(rawDelta(14,"-5.0")), is("14' -5"));
|
||||
when(sp.getBoolean("complication_unicode", true)).thenReturn(false);
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1.2")), "2' 1.2");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(12, "0.7")), "12' 0.7");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "1.0")), "10' 1.0");
|
||||
assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(14, "-5.0")), "14' -5");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longGlucoseLine() {
|
||||
assertThat(DisplayFormat.longGlucoseLine(rawSgv("125",2, "1.2")), is("125→ Δ1.2 (2')"));
|
||||
assertThat(DisplayFormat.longGlucoseLine(rawSgv("97",11, "5.2")), is("97↗ Δ5.2 (11')"));
|
||||
assertThat(DisplayFormat.longGlucoseLine(rawSgv("110",12,"0.7")), is("110→ Δ.7 (12')"));
|
||||
assertThat(DisplayFormat.longGlucoseLine(rawSgv("65",10,"7.0")), is("65↗ Δ7 (10')"));
|
||||
assertThat(DisplayFormat.longGlucoseLine(rawSgv("215",14,"-5.0")), is("215↘ Δ-5 (14')"));
|
||||
assertThat(DisplayFormat.longGlucoseLine(rawSgv("8.3",13,"-5.1")), is("8.3↘ Δ-5.1 (13')"));
|
||||
assertThat(DisplayFormat.longGlucoseLine(rawSgv("6.8",15,"10.83")), is("6.8↑ Δ10.83 (15')"));
|
||||
assertThat(DisplayFormat.longGlucoseLine(rawSgv("13.2",10,"-11.78")), is("13.2↓ Δ-11.78 (10')"));
|
||||
assertThat(DisplayFormat.longGlucoseLine(rawSgv("3.9",3, "2.549")), is("3.9→ Δ2.549 (3')"));
|
||||
assertThat(DisplayFormat.longGlucoseLine(rawSgv("11.1",1, "-15.563")), is("11.1↓ Δ-15.563 (1')"));
|
||||
assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("125", 2, "1.2")), "125→ Δ1.2 (2')");
|
||||
assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("97", 11, "5.2")), "97↗ Δ5.2 (11')");
|
||||
assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("110", 12, "0.7")), "110→ Δ.7 (12')");
|
||||
assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("65", 10, "7.0")), "65↗ Δ7 (10')");
|
||||
assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("215", 14, "-5.0")), "215↘ Δ-5 (14')");
|
||||
assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("8.3", 13, "-5.1")), "8.3↘ Δ-5.1 (13')");
|
||||
assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("6.8", 15, "10.83")), "6.8↑ Δ10.83 (15')");
|
||||
assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("13.2", 10, "-11.78")), "13.2↓ Δ-11.78 (10')");
|
||||
assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("3.9", 3, "2.549")), "3.9→ Δ2.549 (3')");
|
||||
assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("11.1", 1, "-15.563")), "11.1↓ Δ-15.563 (1')");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longDetailsLineTest() {
|
||||
AAPSMocker.setMockedUnicodeComplicationsOn(true);
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("0g", "0U", "3.5U/h")), is("0g ⁞ 0U ⁞ ⎍ 3.5U/h"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("50g", "7.56U", "0%")), is("50g ⁞ 7.56U ⁞ ⎍ 0%"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("12g", "3.23U", "120%")), is("12g ⁞ 3.23U ⁞ 120%"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("2(40)g", "-1.5U", "0.55U/h")), is("2(40)g ⁞ -2U ⁞ 0.55U/h"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("0(24)g", "0.05U", "160%")), is("0(24)g ⁞ 0.05U ⁞ 160%"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("47g", "13.87U", "220%")), is("47g ⁞ 13.87U ⁞ 220%"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("13(5)g", "5.90U", "300%")), is("13(5)g ⁞ 5.90U ⁞ 300%"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("11(50)g", "0U", "70%")), is("11(50)g ⁞ 0U ⁞ 70%"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("7g", "0.54U", "30%")), is("7g ⁞ 0.54U ⁞ ⎍ 30%"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("19(38)g", "35.545U", "12.9U/h")), is("19g ⁞ 36U ⁞ 12.9U/h"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("100(1)g", "12.345U", "6.98647U/h")), is("100g 12U 6.98647U/h"));
|
||||
when(sp.getBoolean("complication_unicode", true)).thenReturn(true);
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0g", "0U", "3.5U/h")), "0g ⁞ 0U ⁞ ⎍ 3.5U/h");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("50g", "7.56U", "0%")), "50g ⁞ 7.56U ⁞ ⎍ 0%");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("12g", "3.23U", "120%")), "12g ⁞ 3.23U ⁞ 120%");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("2(40)g", "-1.5U", "0.55U/h")), "2(40)g ⁞ -2U ⁞ 0.55U/h");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0(24)g", "0.05U", "160%")), "0(24)g ⁞ 0.05U ⁞ 160%");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("47g", "13.87U", "220%")), "47g ⁞ 13.87U ⁞ 220%");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("13(5)g", "5.90U", "300%")), "13(5)g ⁞ 5.90U ⁞ 300%");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("11(50)g", "0U", "70%")), "11(50)g ⁞ 0U ⁞ 70%");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("7g", "0.54U", "30%")), "7g ⁞ 0.54U ⁞ ⎍ 30%");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("19(38)g", "35.545U", "12.9U/h")), "19g ⁞ 36U ⁞ 12.9U/h");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("100(1)g", "12.345U", "6.98647U/h")), "100g 12U 6.98647U/h");
|
||||
|
||||
AAPSMocker.setMockedUnicodeComplicationsOn(false);
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("0g", "0U", "3.5U/h")), is("0g | 0U | 3.5U/h"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("50g", "7.56U", "0%")), is("50g | 7.56U | 0%"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("12g", "3.23U", "120%")), is("12g | 3.23U | 120%"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("7g", "0.54U", "30%")), is("7g | 0.54U | 30%"));
|
||||
assertThat(DisplayFormat.longDetailsLine(rawCobIobBr("19(38)g", "35.545U", "12.9U/h")), is("19g | 36U | 12.9U/h"));
|
||||
when(sp.getBoolean("complication_unicode", true)).thenReturn(false);
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0g", "0U", "3.5U/h")), "0g | 0U | 3.5U/h");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("50g", "7.56U", "0%")), "50g | 7.56U | 0%");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("12g", "3.23U", "120%")), "12g | 3.23U | 120%");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("7g", "0.54U", "30%")), "7g | 0.54U | 30%");
|
||||
assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("19(38)g", "35.545U", "12.9U/h")), "19g | 36U | 12.9U/h");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detailedIobTest() {
|
||||
assertThat(DisplayFormat.detailedIob(rawIob("-1.29U", "(0,910|-2,20)")), is(Pair.create("-1.29U", ",91 -2")));
|
||||
assertThat(DisplayFormat.detailedIob(rawIob("3.50U", "")), is(Pair.create("3.50U", "")));
|
||||
assertThat(DisplayFormat.detailedIob(rawIob("12.5U", "(+1,4|-4.78)")), is(Pair.create("12.5U", "1,4 -5")));
|
||||
assertThat(DisplayFormat.detailedIob(rawIob("0.67U", "some junks")), is(Pair.create(".67U", "")));
|
||||
assertThat(DisplayFormat.detailedIob(rawIob("-11.0U", "(broken|data)")), is(Pair.create("-11U", "-- --")));
|
||||
assertThat(DisplayFormat.detailedIob(rawIob("5.52U", "(0,5439|wrong)")), is(Pair.create("5.52U", ",54 --")));
|
||||
assertThat(DisplayFormat.detailedIob(rawIob("-8.1U", "(|-8,1)")), is(Pair.create("-8.1U", "-- -8")));
|
||||
assertThat(DisplayFormat.detailedIob(rawIob("-8.1U", "(|-8,1)")), is(Pair.create("-8.1U", "-- -8")));
|
||||
assertThat(DisplayFormat.detailedIob(rawIob("7.6U", "(malformed)")), is(Pair.create("7.6U", "")));
|
||||
assertThat(DisplayFormat.detailedIob(rawIob("-4.26U", "(6,97|1,3422|too much)")), is(Pair.create("-4.26U", "7 1,3")));
|
||||
assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-1.29U", "(0,910|-2,20)")), Pair.create("-1.29U", ",91 -2"));
|
||||
assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("3.50U", "")), Pair.create("3.50U", ""));
|
||||
assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("12.5U", "(+1,4|-4.78)")), Pair.create("12.5U", "1,4 -5"));
|
||||
assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("0.67U", "some junks")), Pair.create(".67U", ""));
|
||||
assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-11.0U", "(broken|data)")), Pair.create("-11U", "-- --"));
|
||||
assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("5.52U", "(0,5439|wrong)")), Pair.create("5.52U", ",54 --"));
|
||||
assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-8.1U", "(|-8,1)")), Pair.create("-8.1U", "-- -8"));
|
||||
assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-8.1U", "(|-8,1)")), Pair.create("-8.1U", "-- -8"));
|
||||
assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("7.6U", "(malformed)")), Pair.create("7.6U", ""));
|
||||
assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-4.26U", "(6,97|1,3422|too much)")), Pair.create("-4.26U", "7 1,3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detailedCobTest() {
|
||||
assertThat(DisplayFormat.detailedCob(rawCob("0g")), is(Pair.create("0g", "")));
|
||||
assertThat(DisplayFormat.detailedCob(rawCob("50g")), is(Pair.create("50g", "")));
|
||||
assertThat(DisplayFormat.detailedCob(rawCob("2(40)g")), is(Pair.create("2g", "40g")));
|
||||
assertThat(DisplayFormat.detailedCob(rawCob("0(24)g")), is(Pair.create("0g", "24g")));
|
||||
assertThat(DisplayFormat.detailedCob(rawCob("13(5)g")), is(Pair.create("13g", "5g")));
|
||||
assertThat(DisplayFormat.detailedCob(rawCob("11(50)g")), is(Pair.create("11g", "50g")));
|
||||
assertThat(DisplayFormat.detailedCob(rawCob("19(38)g")), is(Pair.create("19g", "38g")));
|
||||
assertThat(DisplayFormat.detailedCob(rawCob("100(1)g")), is(Pair.create("100g", "1g")));
|
||||
assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("0g")), Pair.create("0g", ""));
|
||||
assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("50g")), Pair.create("50g", ""));
|
||||
assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("2(40)g")), Pair.create("2g", "40g"));
|
||||
assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("0(24)g")), Pair.create("0g", "24g"));
|
||||
assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("13(5)g")), Pair.create("13g", "5g"));
|
||||
assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("11(50)g")), Pair.create("11g", "50g"));
|
||||
assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("19(38)g")), Pair.create("19g", "38g"));
|
||||
assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("100(1)g")), Pair.create("100g", "1g"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package info.nightscout.androidaps.interaction.utils;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -12,6 +10,7 @@ import org.junit.Test;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "SpellCheckingInspection"})
|
||||
public class PairTest {
|
||||
|
||||
@Test
|
||||
|
@ -36,7 +35,7 @@ public class PairTest {
|
|||
assertNotEquals(no1, no3);
|
||||
assertEquals(no1, no4);
|
||||
|
||||
assertNotEquals("aa bbb", left);
|
||||
assertNotEquals("aa bbb", left.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -57,10 +56,9 @@ public class PairTest {
|
|||
// GIVEN
|
||||
Pair pair = Pair.create("the-first", "2nd");
|
||||
|
||||
assertThat(pair.toString(), containsString("the-first"));
|
||||
assertThat(pair+"", containsString("2nd"));
|
||||
assertTrue(pair.toString().contains("the-first"));
|
||||
assertTrue(pair.toString().contains("2nd"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,66 +1,37 @@
|
|||
package info.nightscout.androidaps.interaction.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
||||
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 java.util.Set;
|
||||
|
||||
import info.nightscout.androidaps.Aaps;
|
||||
import info.nightscout.androidaps.testing.mockers.AAPSMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.AndroidMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.LogMocker;
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker;
|
||||
|
||||
import static info.nightscout.androidaps.testing.mockers.WearUtilMocker.REF_NOW;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static info.nightscout.androidaps.testing.mockers.WearUtilMocker.REF_NOW;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, Aaps.class, android.util.Base64.class} )
|
||||
public class PersistenceTest {
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
||||
@Before
|
||||
public void mock() throws Exception {
|
||||
WearUtilMocker.prepareMock();
|
||||
LogMocker.prepareMock();
|
||||
AAPSMocker.prepareMock();
|
||||
AAPSMocker.resetMockedSharedPrefs();
|
||||
AndroidMocker.mockBase64();
|
||||
}
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import info.nightscout.androidaps.TestBase;
|
||||
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class PersistenceTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void putStringTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
|
||||
// WHEN
|
||||
final String emptyGot = persistence.getString("test-key", "default-value");
|
||||
persistence.putString("test-key", "newValue");
|
||||
final String updatedGot = persistence.getString("test-key", "another-default-value");
|
||||
|
||||
// THEN
|
||||
assertThat(emptyGot, is("default-value"));
|
||||
assertThat(updatedGot, is("newValue"));
|
||||
assertEquals(emptyGot, "default-value");
|
||||
assertEquals(updatedGot, "newValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putBooleanTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
|
||||
// WHEN
|
||||
final boolean emptyGot = persistence.getBoolean("test-key", false);
|
||||
persistence.putBoolean("test-key", true);
|
||||
|
@ -74,36 +45,35 @@ public class PersistenceTest {
|
|||
@Test
|
||||
public void whenDataUpdatedTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
DataMap map = new DataMap();
|
||||
|
||||
// WHEN
|
||||
final long whenNotUpdated = persistence.whenDataUpdated();
|
||||
|
||||
Persistence.storeDataMap("data-map", map);
|
||||
persistence.storeDataMap("data-map", map);
|
||||
final long whenUpdatedFirst = persistence.whenDataUpdated();
|
||||
|
||||
WearUtilMocker.progressClock(60000);
|
||||
Persistence.storeDataMap("data-map", map);
|
||||
getWearUtilMocker().progressClock(60000);
|
||||
persistence.storeDataMap("data-map", map);
|
||||
final long whenUpdatedNext = persistence.whenDataUpdated();
|
||||
|
||||
// THEN
|
||||
assertThat(whenNotUpdated, is(0L));
|
||||
assertThat(whenUpdatedFirst, is(REF_NOW));
|
||||
assertThat(whenUpdatedNext, is(REF_NOW + 60000));
|
||||
assertEquals(whenNotUpdated, 0L);
|
||||
assertEquals(whenUpdatedFirst, REF_NOW);
|
||||
assertEquals(whenUpdatedNext, REF_NOW + 60000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDataMapTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
DataMap map = new DataMap();
|
||||
map.putByteArray("test-key", new byte[]{9, 42, 127, -5});
|
||||
|
||||
// WHEN
|
||||
DataMap notExisting = persistence.getDataMap("not-there");
|
||||
Persistence.storeDataMap("data-map", map);
|
||||
persistence.storeDataMap("data-map", map);
|
||||
DataMap restoredMap = persistence.getDataMap("data-map");
|
||||
assert restoredMap != null;
|
||||
byte[] restoredMapContents = restoredMap.getByteArray("test-key");
|
||||
|
||||
// THEN
|
||||
|
@ -111,18 +81,15 @@ public class PersistenceTest {
|
|||
assertNotNull(restoredMap);
|
||||
assertTrue(restoredMap.containsKey("test-key"));
|
||||
|
||||
assertThat(restoredMapContents.length, is(4));
|
||||
assertThat(restoredMapContents[0], is((byte)9));
|
||||
assertThat(restoredMapContents[1], is((byte)42));
|
||||
assertThat(restoredMapContents[2], is((byte)127));
|
||||
assertThat(restoredMapContents[3], is((byte)-5));
|
||||
assertEquals(restoredMapContents.length, 4);
|
||||
assertEquals(restoredMapContents[0], (byte) 9);
|
||||
assertEquals(restoredMapContents[1], (byte) 42);
|
||||
assertEquals(restoredMapContents[2], (byte) 127);
|
||||
assertEquals(restoredMapContents[3], (byte) -5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void brokenDataMapTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
|
||||
// WHEN
|
||||
persistence.putString("data-map", "ZmFrZSBkYXRh");
|
||||
DataMap restoredMap = persistence.getDataMap("data-map");
|
||||
|
@ -133,9 +100,6 @@ public class PersistenceTest {
|
|||
|
||||
@Test
|
||||
public void setsTest() {
|
||||
// GIVEN
|
||||
Persistence persistence = new Persistence();
|
||||
|
||||
// WHEN
|
||||
Set<String> emptySet = persistence.getSetOf("some fake id");
|
||||
|
||||
|
@ -147,7 +111,7 @@ public class PersistenceTest {
|
|||
persistence.addToSet("test-set", "6");
|
||||
|
||||
Set<String> initialSet = persistence.getSetOf("test-set");
|
||||
Set<String> sameInitialSet = Persistence.setOf("test-set");
|
||||
Set<String> sameInitialSet = persistence.getSetOf("test-set");
|
||||
|
||||
persistence.addToSet("test-set", "second-elem");
|
||||
persistence.addToSet("test-set", "new-one");
|
||||
|
@ -161,9 +125,9 @@ public class PersistenceTest {
|
|||
Set<String> reducedSet = persistence.getSetOf("test-set");
|
||||
|
||||
// THEN
|
||||
assertThat(emptySet.size(), is(0));
|
||||
assertEquals(emptySet.size(), 0);
|
||||
|
||||
assertThat(initialSet.size(), is(6));
|
||||
assertEquals(initialSet.size(), 6);
|
||||
assertTrue(initialSet.contains("element1"));
|
||||
assertTrue(initialSet.contains("second-elem"));
|
||||
assertTrue(initialSet.contains("3rd"));
|
||||
|
@ -171,12 +135,12 @@ public class PersistenceTest {
|
|||
assertTrue(initialSet.contains("V"));
|
||||
assertTrue(initialSet.contains("6"));
|
||||
|
||||
assertThat(initialSet, is(sameInitialSet));
|
||||
assertEquals(initialSet, sameInitialSet);
|
||||
|
||||
assertThat(extendedSet.size(), is(7));
|
||||
assertEquals(extendedSet.size(), 7);
|
||||
assertTrue(extendedSet.contains("new-one"));
|
||||
|
||||
assertThat(reducedSet.size(), is(4));
|
||||
assertEquals(reducedSet.size(), 4);
|
||||
assertTrue(reducedSet.contains("element1"));
|
||||
assertTrue(reducedSet.contains("second-elem"));
|
||||
assertFalse(reducedSet.contains("3rd"));
|
||||
|
|
|
@ -1,41 +1,29 @@
|
|||
package info.nightscout.androidaps.interaction.utils
|
||||
|
||||
import android.util.Log
|
||||
import com.google.android.gms.wearable.DataMap
|
||||
import info.nightscout.androidaps.testing.mockers.LogMocker
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker
|
||||
import info.nightscout.androidaps.testing.mocks.BundleMock
|
||||
import org.hamcrest.CoreMatchers
|
||||
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 java.util.*
|
||||
|
||||
/**
|
||||
* Created by dlvoy on 22.11.2019.
|
||||
*/
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(WearUtil::class, Log::class)
|
||||
class WearUtilTest {
|
||||
|
||||
@Before @Throws(Exception::class) fun mock() {
|
||||
WearUtilMocker.prepareMock()
|
||||
LogMocker.prepareMock()
|
||||
}
|
||||
@Suppress("SpellCheckingInspection") class WearUtilTest : TestBase() {
|
||||
|
||||
@Test fun timestampAndTimeDiffsTest() {
|
||||
|
||||
// smoke for mocks - since we freeze "now" to get stable tests
|
||||
Assert.assertThat(WearUtilMocker.REF_NOW, CoreMatchers.`is`(WearUtil.timestamp()))
|
||||
Assert.assertThat(0L, CoreMatchers.`is`(WearUtil.msTill(WearUtilMocker.REF_NOW)))
|
||||
Assert.assertThat(3456L, CoreMatchers.`is`(WearUtil.msTill(WearUtilMocker.REF_NOW + 3456L)))
|
||||
Assert.assertThat(-6294L, CoreMatchers.`is`(WearUtil.msTill(WearUtilMocker.REF_NOW - 6294L)))
|
||||
Assert.assertThat(0L, CoreMatchers.`is`(WearUtil.msTill(WearUtilMocker.REF_NOW)))
|
||||
Assert.assertThat(-3456L, CoreMatchers.`is`(WearUtil.msSince(WearUtilMocker.REF_NOW + 3456L)))
|
||||
Assert.assertThat(6294L, CoreMatchers.`is`(WearUtil.msSince(WearUtilMocker.REF_NOW - 6294L)))
|
||||
Assert.assertEquals(WearUtilMocker.REF_NOW, wearUtil.timestamp())
|
||||
Assert.assertEquals(0L, wearUtil.msTill(WearUtilMocker.REF_NOW))
|
||||
Assert.assertEquals(3456L, wearUtil.msTill(WearUtilMocker.REF_NOW + 3456L))
|
||||
Assert.assertEquals(-6294L, wearUtil.msTill(WearUtilMocker.REF_NOW - 6294L))
|
||||
Assert.assertEquals(0L, wearUtil.msTill(WearUtilMocker.REF_NOW))
|
||||
Assert.assertEquals(-3456L, wearUtil.msSince(WearUtilMocker.REF_NOW + 3456L))
|
||||
Assert.assertEquals(6294L, wearUtil.msSince(WearUtilMocker.REF_NOW - 6294L))
|
||||
}
|
||||
|
||||
@Test fun joinSetTest() {
|
||||
|
@ -46,15 +34,15 @@ class WearUtilTest {
|
|||
refSet.add("3rd")
|
||||
|
||||
// WHEN
|
||||
val joined = WearUtil.joinSet(refSet, "|")
|
||||
val joined = persistence.joinSet(refSet, "|")
|
||||
|
||||
// THEN
|
||||
// we cannot guarantee order of items in joined string
|
||||
// but all items have to be there
|
||||
Assert.assertThat(joined.length, CoreMatchers.`is`("element1".length + "second-elem".length + "3rd".length + "|".length * 2))
|
||||
Assert.assertThat("|$joined|", CoreMatchers.containsString("|" + "element1" + "|"))
|
||||
Assert.assertThat("|$joined|", CoreMatchers.containsString("|" + "second-elem" + "|"))
|
||||
Assert.assertThat("|$joined|", CoreMatchers.containsString("|" + "3rd" + "|"))
|
||||
Assert.assertEquals(joined.length, "element1".length + "second-elem".length + "3rd".length + "|".length * 2)
|
||||
Assert.assertTrue("|$joined|".contains("|" + "element1" + "|"))
|
||||
Assert.assertTrue("|$joined|".contains("|" + "second-elem" + "|"))
|
||||
Assert.assertTrue("|$joined|".contains("|" + "3rd" + "|"))
|
||||
}
|
||||
|
||||
@Test fun explodeSetTest() {
|
||||
|
@ -62,10 +50,10 @@ class WearUtilTest {
|
|||
val serializedSet = "second-elem:element1:3rd"
|
||||
|
||||
// WHEN
|
||||
val set = WearUtil.explodeSet(serializedSet, ":")
|
||||
val set = persistence.explodeSet(serializedSet, ":")
|
||||
|
||||
// THEN
|
||||
Assert.assertThat(set.size, CoreMatchers.`is`(3))
|
||||
Assert.assertEquals(set.size, 3)
|
||||
Assert.assertTrue(set.contains("element1"))
|
||||
Assert.assertTrue(set.contains("second-elem"))
|
||||
Assert.assertTrue(set.contains("3rd"))
|
||||
|
@ -76,12 +64,12 @@ class WearUtilTest {
|
|||
val serializedSet = ",,,,real,,,another,,,"
|
||||
|
||||
// WHEN
|
||||
val set = WearUtil.explodeSet(serializedSet, ",")
|
||||
val set = persistence.explodeSet(serializedSet, ",")
|
||||
|
||||
// THEN
|
||||
Assert.assertThat(set.size, CoreMatchers.`is`(2))
|
||||
Assert.assertThat(true, CoreMatchers.`is`(set.contains("real")))
|
||||
Assert.assertThat(true, CoreMatchers.`is`(set.contains("another")))
|
||||
Assert.assertEquals(set.size, 2)
|
||||
Assert.assertEquals(true, set.contains("real"))
|
||||
Assert.assertEquals(true, set.contains("another"))
|
||||
}
|
||||
|
||||
@Test fun joinExplodeStabilityTest() {
|
||||
|
@ -95,37 +83,39 @@ class WearUtilTest {
|
|||
refSet.add("6")
|
||||
|
||||
// WHEN
|
||||
val joinedSet = WearUtil.joinSet(refSet, "#")
|
||||
val explodedSet = WearUtil.explodeSet(joinedSet, "#")
|
||||
val joinedSet = persistence.joinSet(refSet, "#")
|
||||
val explodedSet = persistence.explodeSet(joinedSet, "#")
|
||||
|
||||
// THEN
|
||||
Assert.assertThat(explodedSet, CoreMatchers.`is`(refSet))
|
||||
Assert.assertEquals(explodedSet, refSet)
|
||||
}
|
||||
/* Mike: failing with new mockito
|
||||
@Test fun threadSleepTest() {
|
||||
// GIVEN
|
||||
val testStart = System.currentTimeMillis()
|
||||
val requestedSleepDuration = 85L
|
||||
val measuringMargin = 100L
|
||||
|
||||
// WHEN
|
||||
WearUtil.threadSleep(requestedSleepDuration)
|
||||
val measuredSleepDuration = System.currentTimeMillis() - testStart
|
||||
/* Mike: failing with new mockito
|
||||
@Test fun threadSleepTest() {
|
||||
// GIVEN
|
||||
val testStart = System.currentTimeMillis()
|
||||
val requestedSleepDuration = 85L
|
||||
val measuringMargin = 100L
|
||||
|
||||
// THEN
|
||||
// we cannot guarantee to be exact to the millisecond - we add some margin of error
|
||||
Assert.assertTrue(60L > measuredSleepDuration)
|
||||
Assert.assertTrue(requestedSleepDuration + measuringMargin < measuredSleepDuration)
|
||||
}
|
||||
*/
|
||||
// WHEN
|
||||
WearUtil.threadSleep(requestedSleepDuration)
|
||||
val measuredSleepDuration = System.currentTimeMillis() - testStart
|
||||
|
||||
// THEN
|
||||
// we cannot guarantee to be exact to the millisecond - we add some margin of error
|
||||
Assert.assertTrue(60L > measuredSleepDuration)
|
||||
Assert.assertTrue(requestedSleepDuration + measuringMargin < measuredSleepDuration)
|
||||
}
|
||||
*/
|
||||
@Test fun rateLimitTest() {
|
||||
wearUtilMocker.prepareMockNoReal()
|
||||
// WHEN
|
||||
val firstCall = WearUtil.isBelowRateLimit("test-limit", 3)
|
||||
val callAfterward = WearUtil.isBelowRateLimit("test-limit", 3)
|
||||
WearUtilMocker.progressClock(500L)
|
||||
val callTooSoon = WearUtil.isBelowRateLimit("test-limit", 3)
|
||||
WearUtilMocker.progressClock(3100L)
|
||||
val callAfterRateLimit = WearUtil.isBelowRateLimit("test-limit", 3)
|
||||
val firstCall = wearUtil.isBelowRateLimit("test-limit", 3)
|
||||
val callAfterward = wearUtil.isBelowRateLimit("test-limit", 3)
|
||||
wearUtilMocker.progressClock(500L)
|
||||
val callTooSoon = wearUtil.isBelowRateLimit("test-limit", 3)
|
||||
wearUtilMocker.progressClock(3100L)
|
||||
val callAfterRateLimit = wearUtil.isBelowRateLimit("test-limit", 3)
|
||||
|
||||
// THEN
|
||||
Assert.assertTrue(firstCall)
|
||||
|
@ -139,7 +129,8 @@ class WearUtilTest {
|
|||
* because original impl. of bundleToDataMap
|
||||
* uses DataMap.fromBundle which need Android SDK runtime
|
||||
*/
|
||||
@Test @Throws(Exception::class) fun bundleToDataMapTest() {
|
||||
@Test
|
||||
fun bundleToDataMapTest() {
|
||||
// GIVEN
|
||||
val refMap = DataMap()
|
||||
refMap.putString("ala", "ma kota")
|
||||
|
@ -147,11 +138,11 @@ class WearUtilTest {
|
|||
refMap.putFloatArray("list", floatArrayOf(0.45f, 3.2f, 6.8f))
|
||||
|
||||
// WHEN
|
||||
WearUtilMocker.prepareMockNoReal()
|
||||
wearUtilMocker.prepareMockNoReal()
|
||||
val bundle = BundleMock.mock(refMap)
|
||||
val gotMap = WearUtil.bundleToDataMap(bundle)
|
||||
val gotMap = wearUtil.bundleToDataMap(bundle)
|
||||
|
||||
// THEN
|
||||
Assert.assertThat(gotMap, CoreMatchers.`is`(refMap))
|
||||
Assert.assertEquals(gotMap, refMap)
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package info.nightscout.androidaps.testing.mockers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import info.nightscout.androidaps.Aaps;
|
||||
import info.nightscout.androidaps.testing.mocks.SharedPreferencesMock;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
|
||||
public class AAPSMocker {
|
||||
|
||||
private static final Map<String, SharedPreferences> mockedSharedPrefs = new HashMap<>();
|
||||
private static boolean unicodeComplicationsOn = true;
|
||||
|
||||
public static void prepareMock() throws Exception {
|
||||
Context mockedContext = mock(Context.class);
|
||||
mockStatic(Aaps.class, InvocationOnMock::callRealMethod);
|
||||
|
||||
PowerMockito.when(Aaps.class, "getAppContext").thenReturn(mockedContext);
|
||||
PowerMockito.when(mockedContext, "getSharedPreferences", ArgumentMatchers.anyString(), ArgumentMatchers.anyInt()).thenAnswer(invocation -> {
|
||||
|
||||
final String key = invocation.getArgument(0);
|
||||
if (mockedSharedPrefs.containsKey(key)) {
|
||||
return mockedSharedPrefs.get(key);
|
||||
} else {
|
||||
SharedPreferencesMock newPrefs = new SharedPreferencesMock();
|
||||
mockedSharedPrefs.put(key, newPrefs);
|
||||
return newPrefs;
|
||||
}
|
||||
});
|
||||
PowerMockito.when(Aaps.class, "areComplicationsUnicode").thenAnswer(invocation -> unicodeComplicationsOn);
|
||||
|
||||
setMockedUnicodeComplicationsOn(true);
|
||||
resetMockedSharedPrefs();
|
||||
}
|
||||
|
||||
public static void resetMockedSharedPrefs() {
|
||||
mockedSharedPrefs.clear();
|
||||
}
|
||||
|
||||
public static void resetMockedSharedPrefs(String forKey) {
|
||||
mockedSharedPrefs.remove(forKey);
|
||||
}
|
||||
|
||||
public static void setMockedUnicodeComplicationsOn(boolean setUnicodeOn) {
|
||||
unicodeComplicationsOn = setUnicodeOn;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package info.nightscout.androidaps.testing.mockers;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
public class AndroidMocker {
|
||||
|
||||
public static void mockBase64() throws Exception {
|
||||
mockStatic(android.util.Base64.class);
|
||||
|
||||
PowerMockito.when(android.util.Base64.class, "decode", anyString(), anyInt()).thenAnswer(invocation -> {
|
||||
|
||||
final String payload = invocation.getArgument(0);
|
||||
try {
|
||||
return Base64.getDecoder().decode(payload);
|
||||
} catch (java.lang.IllegalArgumentException ex) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
PowerMockito.when(android.util.Base64.class, "encodeToString", any(), anyInt()).thenAnswer(invocation -> {
|
||||
|
||||
final byte[] payload = invocation.getArgument(0);
|
||||
return Base64.getEncoder().encodeToString(payload);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package info.nightscout.androidaps.testing.mockers;
|
||||
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class LogMocker {
|
||||
public static void prepareMock() {
|
||||
mockStatic(Log.class);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,23 @@
|
|||
package info.nightscout.androidaps.testing.mockers;
|
||||
|
||||
import info.nightscout.androidaps.data.RawDisplayData;
|
||||
import info.nightscout.androidaps.interaction.utils.WearUtil;
|
||||
import info.nightscout.shared.SafeParse;
|
||||
|
||||
import static info.nightscout.androidaps.testing.mockers.WearUtilMocker.backInTime;
|
||||
|
||||
@SuppressWarnings("PointlessArithmeticExpression")
|
||||
public class RawDataMocker {
|
||||
|
||||
public static RawDisplayData rawSgv(String sgv, int m, String deltaString) {
|
||||
RawDisplayData raw = new RawDisplayData();
|
||||
raw.datetime = backInTime(0, 0, m, 0);
|
||||
private final WearUtil wearUtil;
|
||||
private final WearUtilMocker wearUtilMocker;
|
||||
|
||||
public RawDataMocker(WearUtil wearUtil) {
|
||||
this.wearUtil = wearUtil;
|
||||
wearUtilMocker = new WearUtilMocker(wearUtil);
|
||||
}
|
||||
|
||||
public RawDisplayData rawSgv(String sgv, int m, String deltaString) {
|
||||
RawDisplayData raw = new RawDisplayData(wearUtil);
|
||||
raw.datetime = wearUtilMocker.backInTime(0, 0, m, 0);
|
||||
raw.sDelta = deltaString;
|
||||
raw.sSgv = sgv;
|
||||
|
||||
|
@ -34,30 +42,30 @@ public class RawDataMocker {
|
|||
return raw;
|
||||
}
|
||||
|
||||
public static RawDisplayData rawDelta(int m, String delta) {
|
||||
RawDisplayData raw = new RawDisplayData();
|
||||
raw.datetime = backInTime(0, 0, m, 0);
|
||||
public RawDisplayData rawDelta(int m, String delta) {
|
||||
RawDisplayData raw = new RawDisplayData(wearUtil);
|
||||
raw.datetime = wearUtilMocker.backInTime(0, 0, m, 0);
|
||||
raw.sDelta = delta;
|
||||
return raw;
|
||||
}
|
||||
|
||||
public static RawDisplayData rawCobIobBr(String cob, String iob, String br) {
|
||||
RawDisplayData raw = new RawDisplayData();
|
||||
public RawDisplayData rawCobIobBr(String cob, String iob, String br) {
|
||||
RawDisplayData raw = new RawDisplayData(wearUtil);
|
||||
raw.sCOB2 = cob;
|
||||
raw.sIOB1 = iob;
|
||||
raw.sBasalRate = br;
|
||||
return raw;
|
||||
}
|
||||
|
||||
public static RawDisplayData rawIob(String iob, String iob2) {
|
||||
RawDisplayData raw = new RawDisplayData();
|
||||
public RawDisplayData rawIob(String iob, String iob2) {
|
||||
RawDisplayData raw = new RawDisplayData(wearUtil);
|
||||
raw.sIOB1 = iob;
|
||||
raw.sIOB2 = iob2;
|
||||
return raw;
|
||||
}
|
||||
|
||||
public static RawDisplayData rawCob(String cob) {
|
||||
RawDisplayData raw = new RawDisplayData();
|
||||
public RawDisplayData rawCob(String cob) {
|
||||
RawDisplayData raw = new RawDisplayData(wearUtil);
|
||||
raw.sCOB2 = cob;
|
||||
return raw;
|
||||
}
|
||||
|
|
|
@ -3,90 +3,95 @@ package info.nightscout.androidaps.testing.mockers;
|
|||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.google.android.gms.wearable.Asset;
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import info.nightscout.androidaps.interaction.utils.Constants;
|
||||
import info.nightscout.androidaps.interaction.utils.WearUtil;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class WearUtilMocker {
|
||||
|
||||
public static final long REF_NOW = 1572610530000L;
|
||||
private static long clockMsDiff = 0L;
|
||||
private final WearUtil wearUtil;
|
||||
|
||||
public static void prepareMock() throws Exception {
|
||||
public WearUtilMocker(WearUtil wearUtil) {
|
||||
this.wearUtil = wearUtil;
|
||||
}
|
||||
|
||||
public static final long REF_NOW = 1572610530000L;
|
||||
private long clockMsDiff = 0L;
|
||||
|
||||
public void prepareMock() {
|
||||
resetClock();
|
||||
mockStatic(WearUtil.class, InvocationOnMock::callRealMethod);
|
||||
|
||||
// because we cleverly used timestamp() by implementation, we can mock it
|
||||
// and control the time in tests
|
||||
PowerMockito.when(WearUtil.class, "timestamp").then(invocation -> (REF_NOW + clockMsDiff));
|
||||
when(wearUtil.timestamp()).thenReturn(REF_NOW + clockMsDiff);
|
||||
}
|
||||
|
||||
public static void prepareMockNoReal() throws Exception {
|
||||
public void prepareMockNoReal() {
|
||||
resetClock();
|
||||
mockStatic(WearUtil.class);
|
||||
|
||||
PowerMockito.when(WearUtil.class, "timestamp").then(invocation -> REF_NOW + clockMsDiff);
|
||||
PowerMockito.when(WearUtil.class, "getWakeLock", anyString(), anyInt()).then(invocation -> null);
|
||||
PowerMockito.when(WearUtil.class, "bundleToDataMap", any(Bundle.class)).then(bundleToDataMapMock);
|
||||
Mockito.doAnswer(invocation -> REF_NOW + clockMsDiff).when(wearUtil).timestamp();
|
||||
Mockito.doReturn(null).when(wearUtil).getWakeLock(anyString(), anyInt());
|
||||
Mockito.doAnswer(bundleToDataMapMock).when(wearUtil).bundleToDataMap(any());
|
||||
}
|
||||
|
||||
public static void resetClock() {
|
||||
public void resetClock() {
|
||||
clockMsDiff = 0L;
|
||||
}
|
||||
|
||||
public static void progressClock(long byMilliseconds) {
|
||||
public void progressClock(long byMilliseconds) {
|
||||
clockMsDiff = clockMsDiff + byMilliseconds;
|
||||
}
|
||||
|
||||
public static void setClock(long atMillisecondsSinceEpoch) {
|
||||
@SuppressWarnings("unused")
|
||||
public void setClock(long atMillisecondsSinceEpoch) {
|
||||
clockMsDiff = atMillisecondsSinceEpoch - REF_NOW;
|
||||
}
|
||||
|
||||
public static long backInTime(int d, int h, int m, int s) {
|
||||
public long backInTime(int d, int h, int m, int s) {
|
||||
return REF_NOW - (Constants.DAY_IN_MS * d + Constants.HOUR_IN_MS * h + Constants.MINUTE_IN_MS * m + Constants.SECOND_IN_MS * s);
|
||||
}
|
||||
|
||||
private static final Answer bundleToDataMapMock = invocation -> {
|
||||
private final Answer bundleToDataMapMock = invocation -> {
|
||||
DataMap map = new DataMap();
|
||||
Bundle bundle = invocation.getArgument(0);
|
||||
for(String key: bundle.keySet()) {
|
||||
for (String key : bundle.keySet()) {
|
||||
Object v = bundle.get(key);
|
||||
if (v instanceof Asset) map.putAsset(key, (Asset)v);
|
||||
if (v instanceof Boolean) map.putBoolean(key, (Boolean)v);
|
||||
if (v instanceof Byte) map.putByte(key, (Byte)v);
|
||||
if (v instanceof byte[]) map.putByteArray(key, (byte[])v);
|
||||
if (v instanceof DataMap) map.putDataMap(key, (DataMap)v);
|
||||
if (v instanceof Double) map.putDouble(key, (Double)v);
|
||||
if (v instanceof Float) map.putFloat(key, (Float)v);
|
||||
if (v instanceof float[]) map.putFloatArray(key, (float[])v);
|
||||
if (v instanceof Integer) map.putInt(key, (Integer)v);
|
||||
if (v instanceof Long) map.putLong(key, (Long)v);
|
||||
if (v instanceof long[]) map.putLongArray(key, (long[])v);
|
||||
if (v instanceof String) map.putString(key, (String)v);
|
||||
if (v instanceof String[]) map.putStringArray(key, (String[])v);
|
||||
if (v instanceof Asset) map.putAsset(key, (Asset) v);
|
||||
if (v instanceof Boolean) map.putBoolean(key, (Boolean) v);
|
||||
if (v instanceof Byte) map.putByte(key, (Byte) v);
|
||||
if (v instanceof byte[]) map.putByteArray(key, (byte[]) v);
|
||||
if (v instanceof DataMap) map.putDataMap(key, (DataMap) v);
|
||||
if (v instanceof Double) map.putDouble(key, (Double) v);
|
||||
if (v instanceof Float) map.putFloat(key, (Float) v);
|
||||
if (v instanceof float[]) map.putFloatArray(key, (float[]) v);
|
||||
if (v instanceof Integer) map.putInt(key, (Integer) v);
|
||||
if (v instanceof Long) map.putLong(key, (Long) v);
|
||||
if (v instanceof long[]) map.putLongArray(key, (long[]) v);
|
||||
if (v instanceof String) map.putString(key, (String) v);
|
||||
if (v instanceof String[]) map.putStringArray(key, (String[]) v);
|
||||
|
||||
if (v instanceof ArrayList) {
|
||||
if (!((ArrayList)v).isEmpty()) {
|
||||
if (!((ArrayList) v).isEmpty()) {
|
||||
if (((ArrayList) v).get(0) instanceof Integer) {
|
||||
map.putIntegerArrayList(key, (ArrayList<Integer>)v);
|
||||
map.putIntegerArrayList(key, (ArrayList<Integer>) v);
|
||||
}
|
||||
if (((ArrayList) v).get(0) instanceof String) {
|
||||
map.putStringArrayList(key, (ArrayList<String>)v);
|
||||
map.putStringArrayList(key, (ArrayList<String>) v);
|
||||
}
|
||||
if (((ArrayList) v).get(0) instanceof DataMap) {
|
||||
map.putDataMapArrayList(key, (ArrayList<DataMap>)v);
|
||||
map.putDataMapArrayList(key, (ArrayList<DataMap>) v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,5 @@
|
|||
package info.nightscout.androidaps.testing.mocks;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyByte;
|
||||
|
@ -27,10 +13,24 @@ import static org.mockito.Matchers.anyString;
|
|||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
@SuppressWarnings({"unused", "rawtypes", "SuspiciousMethodCalls", "unchecked"})
|
||||
public final class BundleMock {
|
||||
|
||||
public static Bundle mock() {
|
||||
return mock(new HashMap<String, Object>());
|
||||
return mock(new HashMap<>());
|
||||
}
|
||||
|
||||
public static Bundle mock(DataMap dataMap) {
|
||||
|
@ -43,85 +43,35 @@ public final class BundleMock {
|
|||
|
||||
public static Bundle mock(final HashMap<String, Object> map) {
|
||||
|
||||
Answer unsupported = new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
Answer unsupported = invocation -> {
|
||||
throw new UnsupportedOperationException();
|
||||
};
|
||||
Answer put = new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
map.put((String)invocation.getArguments()[0], invocation.getArguments()[1]);
|
||||
return null;
|
||||
}
|
||||
Answer put = invocation -> {
|
||||
map.put((String) invocation.getArguments()[0], invocation.getArguments()[1]);
|
||||
return null;
|
||||
};
|
||||
Answer<Object> get = new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return map.get(invocation.getArguments()[0]);
|
||||
}
|
||||
};
|
||||
Answer<Object> getOrDefault = new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object key = invocation.getArguments()[0];
|
||||
return map.containsKey(key) ? map.get(key) : invocation.getArguments()[1];
|
||||
}
|
||||
Answer<Object> get = invocation -> map.get(invocation.getArguments()[0]);
|
||||
Answer<Object> getOrDefault = invocation -> {
|
||||
Object key = invocation.getArguments()[0];
|
||||
return map.containsKey(key) ? map.get(key) : invocation.getArguments()[1];
|
||||
};
|
||||
|
||||
Bundle bundle = Mockito.mock(Bundle.class);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return map.size();
|
||||
}
|
||||
}).when(bundle).size();
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return map.isEmpty();
|
||||
}
|
||||
}).when(bundle).isEmpty();
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
map.clear();
|
||||
return null;
|
||||
}
|
||||
doAnswer(invocation -> map.size()).when(bundle).size();
|
||||
doAnswer(invocation -> map.isEmpty()).when(bundle).isEmpty();
|
||||
doAnswer(invocation -> {
|
||||
map.clear();
|
||||
return null;
|
||||
}).when(bundle).clear();
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return map.containsKey(invocation.getArguments()[0]);
|
||||
}
|
||||
}).when(bundle).containsKey(anyString());
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return map.get(invocation.getArguments()[0]);
|
||||
}
|
||||
}).when(bundle).get(anyString());
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
map.remove(invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
doAnswer(invocation -> map.containsKey(invocation.getArguments()[0])).when(bundle).containsKey(anyString());
|
||||
doAnswer(invocation -> map.get(invocation.getArguments()[0])).when(bundle).get(anyString());
|
||||
doAnswer(invocation -> {
|
||||
map.remove(invocation.getArguments()[0]);
|
||||
return null;
|
||||
}).when(bundle).remove(anyString());
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return map.keySet();
|
||||
}
|
||||
}).when(bundle).keySet();
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return BundleMock.class.getSimpleName() + "{map=" + map.toString() + "}";
|
||||
}
|
||||
}).when(bundle).toString();
|
||||
doAnswer(invocation -> map.keySet()).when(bundle).keySet();
|
||||
doAnswer(invocation -> BundleMock.class.getSimpleName() + "{map=" + map.toString() + "}").when(bundle).toString();
|
||||
|
||||
doAnswer(put).when(bundle).putBoolean(anyString(), anyBoolean());
|
||||
when(bundle.getBoolean(anyString())).thenAnswer(get);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package info.nightscout.androidaps.testing.mocks;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
|
@ -8,21 +13,17 @@ import org.mockito.stubbing.Answer;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@SuppressWarnings({"SuspiciousMethodCalls", "rawtypes"})
|
||||
public final class IntentMock {
|
||||
|
||||
public static Intent mock() {
|
||||
return mock(new HashMap<String, Object>());
|
||||
return mock(new HashMap<>());
|
||||
}
|
||||
|
||||
public static Intent mock(final HashMap<String, Object> map) {
|
||||
|
||||
Answer put = invocation -> {
|
||||
map.put((String)invocation.getArguments()[0], invocation.getArguments()[1]);
|
||||
map.put((String) invocation.getArguments()[0], invocation.getArguments()[1]);
|
||||
return null;
|
||||
};
|
||||
Answer<Object> get = invocation -> map.get(invocation.getArguments()[0]);
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"ConstantConditions", "unchecked"})
|
||||
public class SharedPreferencesMock implements SharedPreferences {
|
||||
|
||||
private final EditorInternals editor = new EditorInternals();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package info.nightscout.androidaps.testing.utils;
|
||||
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
|
@ -7,8 +9,6 @@ import java.util.Objects;
|
|||
|
||||
import info.nightscout.androidaps.data.BasalWatchData;
|
||||
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
public class BasalWatchDataExt extends BasalWatchData {
|
||||
|
||||
private BasalWatchDataExt() {
|
||||
|
@ -39,8 +39,8 @@ public class BasalWatchDataExt extends BasalWatchData {
|
|||
public boolean equals(@Nullable Object obj) {
|
||||
if (obj instanceof BasalWatchData) {
|
||||
return (this.startTime == ((BasalWatchData) obj).startTime)
|
||||
&& (this.endTime == ((BasalWatchData) obj).endTime)
|
||||
&& (this.amount == ((BasalWatchData) obj).amount);
|
||||
&& (this.endTime == ((BasalWatchData) obj).endTime)
|
||||
&& (this.amount == ((BasalWatchData) obj).amount);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class BasalWatchDataExt extends BasalWatchData {
|
|||
|
||||
@NonNull @Override
|
||||
public String toString() {
|
||||
return startTime+", "+endTime+", "+amount;
|
||||
return startTime + ", " + endTime + ", " + amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package info.nightscout.androidaps.testing.utils;
|
||||
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
|
@ -7,8 +9,7 @@ import java.util.Objects;
|
|||
|
||||
import info.nightscout.androidaps.data.BgWatchData;
|
||||
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class BgWatchDataExt extends BgWatchData {
|
||||
|
||||
private BgWatchDataExt() {
|
||||
|
@ -56,7 +57,7 @@ public class BgWatchDataExt extends BgWatchData {
|
|||
|
||||
@Override @NonNull
|
||||
public String toString() {
|
||||
return sgv+", "+high+", "+low+", "+timestamp+", "+color;
|
||||
return sgv + ", " + high + ", " + low + ", " + timestamp + ", " + color;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package info.nightscout.androidaps.testing.utils;
|
||||
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import info.nightscout.androidaps.data.BolusWatchData;
|
||||
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
public class BolusWatchDataExt extends BolusWatchData {
|
||||
|
||||
private BolusWatchDataExt() {
|
||||
|
@ -40,7 +41,7 @@ public class BolusWatchDataExt extends BolusWatchData {
|
|||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if ((obj instanceof BolusWatchData)||(obj instanceof BolusWatchDataExt)) {
|
||||
if (obj instanceof BolusWatchData) {
|
||||
return (this.date == ((BolusWatchData) obj).date)
|
||||
&& (this.bolus == ((BolusWatchData) obj).bolus)
|
||||
&& (this.carbs == ((BolusWatchData) obj).carbs)
|
||||
|
@ -51,9 +52,9 @@ public class BolusWatchDataExt extends BolusWatchData {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull @Override
|
||||
public String toString() {
|
||||
return date+", "+bolus+", "+carbs+", "+isSMB+", "+isValid;
|
||||
return date + ", " + bolus + ", " + carbs + ", " + isSMB + ", " + isValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
package info.nightscout.androidaps.testing.utils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
class ExtUtil {
|
||||
|
||||
static <T> void assertClassHaveSameFields(Class<T> checkedClass, String commaSeparatedFieldList) {
|
||||
static <T> void assertClassHaveSameFields(Class<T> checkedClass, String commaSeparatedFieldList) {
|
||||
Set<String> parentFields = new HashSet<>();
|
||||
for (Field f : checkedClass.getDeclaredFields()) {
|
||||
final String fieldName = f.getName();
|
||||
|
@ -22,7 +21,7 @@ class ExtUtil {
|
|||
}
|
||||
|
||||
Set<String> knownFields = new HashSet<>(Arrays.asList(commaSeparatedFieldList.split(",")));
|
||||
assertThat(parentFields, is(knownFields));
|
||||
assertEquals(parentFields, knownFields);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package info.nightscout.androidaps.testing.utils;
|
||||
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import info.nightscout.androidaps.data.TempWatchData;
|
||||
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
|
||||
public class TempWatchDataExt extends TempWatchData {
|
||||
|
||||
|
@ -42,20 +43,20 @@ public class TempWatchDataExt extends TempWatchData {
|
|||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if ((obj instanceof TempWatchData)||(obj instanceof TempWatchDataExt)) {
|
||||
if (obj instanceof TempWatchData) {
|
||||
return (this.startTime == ((TempWatchData) obj).startTime)
|
||||
&& (this.startBasal == ((TempWatchData) obj).startBasal)
|
||||
&& (this.endTime == ((TempWatchData) obj).endTime)
|
||||
&& (this.endBasal == ((TempWatchData) obj).endBasal)
|
||||
&& (this.amount == ((TempWatchData) obj).amount);
|
||||
&& (this.startBasal == ((TempWatchData) obj).startBasal)
|
||||
&& (this.endTime == ((TempWatchData) obj).endTime)
|
||||
&& (this.endBasal == ((TempWatchData) obj).endBasal)
|
||||
&& (this.amount == ((TempWatchData) obj).amount);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull @Override
|
||||
public String toString() {
|
||||
return startTime+", "+startBasal+", "+endTime+", "+endBasal+", "+amount;
|
||||
return startTime + ", " + startBasal + ", " + endTime + ", " + endBasal + ", " + amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue