From c10963dcbdae432f414e27cfd9c60f111f59f71e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 27 Oct 2019 15:48:09 +0100 Subject: [PATCH 1/2] fix NPE --- .../constraints/objectives/ObjectivesFragment.kt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt index 70242d3433..aafd877672 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt @@ -104,17 +104,14 @@ class ObjectivesFragment : Fragment() { for (i in 0 until ObjectivesPlugin.objectives.size) { val objective = ObjectivesPlugin.objectives[i] if (!objective.isStarted || !objective.isAccomplished) { - val smoothScroller = object : LinearSmoothScroller(context!!) { - override fun getVerticalSnapPreference(): Int { - return SNAP_TO_START - } - - override fun calculateTimeForScrolling(dx: Int): Int { - return super.calculateTimeForScrolling(dx) * 4 + context?.let { + val smoothScroller = object : LinearSmoothScroller(it) { + override fun getVerticalSnapPreference(): Int = SNAP_TO_START + override fun calculateTimeForScrolling(dx: Int): Int = super.calculateTimeForScrolling(dx) * 4 } + smoothScroller.targetPosition = i + objectives_recyclerview.layoutManager?.startSmoothScroll(smoothScroller) } - smoothScroller.targetPosition = i - objectives_recyclerview.layoutManager?.startSmoothScroll(smoothScroller) break } } From 0da63776873c5a2a392cc925014991f91760927b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 28 Oct 2019 13:45:42 +0100 Subject: [PATCH 2/2] SignatureVerifierPluginTest --- .../SignatureVerifierPlugin.java | 5 +++-- .../SignatureVerifierPluginTest.kt | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.java index 89dbb56ca5..9c9e38bb46 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.java @@ -160,11 +160,12 @@ public class SignatureVerifierPlugin extends PluginBase implements ConstraintsIn return sb.toString(); } - private String singleCharUnMap(String shortHash) { + public String singleCharUnMap(String shortHash) { byte[] array = new byte[shortHash.length()]; StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { - sb.append(String.format("%02x",(int) map.charAt(map.indexOf(shortHash.charAt(i))))); + if (i != 0) sb.append(":"); + sb.append(String.format("%02X", 0xFF & map.charAt(map.indexOf(shortHash.charAt(i))))); } return sb.toString(); } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt new file mode 100644 index 0000000000..6d4a37882a --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.plugins.constraints.signatureVerifier + +import org.junit.Test + +import org.junit.Assert.* + +class SignatureVerifierPluginTest { + + @Test + fun singleCharUnMapTest() { + val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε" + val unmapped = SignatureVerifierPlugin.getPlugin().singleCharUnMap(key) + assertEquals("32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95", unmapped) + } +} \ No newline at end of file