diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt index a41a0b5453..bfad5b3571 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt @@ -37,16 +37,6 @@ class Persistence @Inject constructor( } - // For mocking only - fun base64decode(str: String, flags: Int): ByteArray { - return Base64.decode(str, flags) - } - - // For mocking only - fun base64encodeToString(input: ByteArray, flags: Int): String { - return Base64.encodeToString(input, flags) - } - fun getString(key: String, defaultValue: String): String { return sp.getString(key, defaultValue) } @@ -177,7 +167,7 @@ class Persistence @Inject constructor( fun explodeSet(joined: String, separator: String): MutableSet { // special RegEx literal \\Q starts sequence we escape, \\E ends is // we use it to escape separator for use in RegEx - val items = joined.split("\\Q$separator\\E").toTypedArray() + val items = joined.split(Regex("\\Q$separator\\E")).toTypedArray() val set: MutableSet = HashSet() for (item in items) { val itemToAdd = item.trim { it <= ' ' } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.java index 5f22657035..38bb5b011e 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.java @@ -6,7 +6,6 @@ import android.os.PowerManager; import com.google.android.gms.wearable.DataMap; -import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -32,7 +31,6 @@ public class WearUtil { private final boolean debug_wakelocks = false; private final Map rateLimits = new HashMap<>(); - private final String TAG = WearUtil.class.getName(); //============================================================================================== // Time related util methods diff --git a/wear/src/test/java/info/nightscout/androidaps/TestBase.kt b/wear/src/test/java/info/nightscout/androidaps/TestBase.kt index 8dd48a7911..764f44687c 100644 --- a/wear/src/test/java/info/nightscout/androidaps/TestBase.kt +++ b/wear/src/test/java/info/nightscout/androidaps/TestBase.kt @@ -6,9 +6,9 @@ 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.androidaps.utils.DateUtil import info.nightscout.shared.logging.AAPSLoggerTest +import info.nightscout.shared.sharedPreferences.SP import org.junit.Before import org.junit.Rule import org.mockito.ArgumentMatchers @@ -21,9 +21,10 @@ import java.util.* open class TestBase { @Mock lateinit var context: Context + @Mock lateinit var sp: SP + @Mock lateinit var dateUtil: DateUtil val aapsLogger = AAPSLoggerTest() - val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() val wearUtil: WearUtil = Mockito.spy(WearUtil()) val wearUtilMocker = WearUtilMocker(wearUtil) @@ -47,21 +48,8 @@ open class TestBase { wearUtilMocker.prepareMockNoReal() wearUtil.aapsLogger = aapsLogger wearUtil.context = context - persistence = Mockito.spy(Persistence(context, aapsLogger, wearUtil)) + persistence = Mockito.spy(Persistence(aapsLogger, dateUtil, sp)) - Mockito.doAnswer { invocation -> - val payload = invocation.getArgument(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(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. diff --git a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PersistenceTest.java b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PersistenceTest.java deleted file mode 100644 index dcfbf5235e..0000000000 --- a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PersistenceTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package info.nightscout.androidaps.interaction.utils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import java.util.Set; - -import info.nightscout.androidaps.TestBase; - -@SuppressWarnings("SpellCheckingInspection") -public class PersistenceTest extends TestBase { - - @Test - public void putStringTest() { - // 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 - assertEquals(emptyGot, "default-value"); - assertEquals(updatedGot, "newValue"); - } - - @Test - public void putBooleanTest() { - // WHEN - final boolean emptyGot = persistence.getBoolean("test-key", false); - persistence.putBoolean("test-key", true); - final boolean updatedGot = persistence.getBoolean("test-key", false); - - // THEN - assertFalse(emptyGot); - assertTrue(updatedGot); - } - - @Test - public void setsTest() { - // WHEN - Set emptySet = persistence.getSetOf("some fake id"); - - persistence.addToSet("test-set", "element1"); - persistence.addToSet("test-set", "second-elem"); - persistence.addToSet("test-set", "3rd"); - persistence.addToSet("test-set", "czwarty"); - persistence.addToSet("test-set", "V"); - persistence.addToSet("test-set", "6"); - - Set initialSet = persistence.getSetOf("test-set"); - Set sameInitialSet = persistence.getSetOf("test-set"); - - persistence.addToSet("test-set", "second-elem"); - persistence.addToSet("test-set", "new-one"); - - Set extendedSet = persistence.getSetOf("test-set"); - - persistence.removeFromSet("test-set", "czwarty"); - persistence.removeFromSet("test-set", "6"); - persistence.removeFromSet("test-set", "3rd"); - - Set reducedSet = persistence.getSetOf("test-set"); - - // THEN - assertEquals(emptySet.size(), 0); - - assertEquals(initialSet.size(), 6); - assertTrue(initialSet.contains("element1")); - assertTrue(initialSet.contains("second-elem")); - assertTrue(initialSet.contains("3rd")); - assertTrue(initialSet.contains("czwarty")); - assertTrue(initialSet.contains("V")); - assertTrue(initialSet.contains("6")); - - assertEquals(initialSet, sameInitialSet); - - assertEquals(extendedSet.size(), 7); - assertTrue(extendedSet.contains("new-one")); - - assertEquals(reducedSet.size(), 4); - assertTrue(reducedSet.contains("element1")); - assertTrue(reducedSet.contains("second-elem")); - assertFalse(reducedSet.contains("3rd")); - assertFalse(reducedSet.contains("czwarty")); - assertTrue(reducedSet.contains("V")); - assertFalse(reducedSet.contains("6")); - assertTrue(reducedSet.contains("new-one")); - } - -}