From 9958028990d2336e2a201c62615800c9e7d8911a Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:04:55 -0700 Subject: [PATCH 01/16] Rewrites ConstraintTest with matchers Issue #2745 --- .../nightscout/core/data/ConstraintTest.kt | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/data/ConstraintTest.kt b/core/main/src/test/java/info/nightscout/core/data/ConstraintTest.kt index e23021118f..7cca04c37b 100644 --- a/core/main/src/test/java/info/nightscout/core/data/ConstraintTest.kt +++ b/core/main/src/test/java/info/nightscout/core/data/ConstraintTest.kt @@ -1,8 +1,8 @@ package info.nightscout.core.data +import com.google.common.truth.Truth.assertThat import info.nightscout.core.constraints.ConstraintObject import info.nightscout.sharedtests.TestBase -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -13,43 +13,39 @@ class ConstraintTest : TestBase() { @Test fun doTests() { val b = ConstraintObject(true, aapsLogger) - Assertions.assertEquals(true, b.value()) - Assertions.assertEquals("", b.getReasons()) - Assertions.assertEquals("", b.getMostLimitedReasons()) + assertThat(b.value()).isTrue() + assertThat(b.getReasons()).isEmpty() + assertThat(b.getMostLimitedReasons()).isEmpty() b.set(false) - Assertions.assertEquals(false, b.value()) - Assertions.assertEquals("", b.getReasons()) - Assertions.assertEquals("", b.getMostLimitedReasons()) + assertThat(b.value()).isFalse() + assertThat(b.getReasons()).isEmpty() + assertThat(b.getMostLimitedReasons()).isEmpty() b.set(true, "Set true", this) - Assertions.assertEquals(true, b.value()) - Assertions.assertEquals("ConstraintTest: Set true", b.getReasons()) - Assertions.assertEquals("ConstraintTest: Set true", b.getMostLimitedReasons()) + assertThat(b.value()).isTrue() + assertThat(b.getReasons()).isEqualTo("ConstraintTest: Set true") + assertThat(b.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set true") b.set(false, "Set false", this) - Assertions.assertEquals(false, b.value()) - Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getReasons()) - Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getMostLimitedReasons()) + assertThat(b.value()).isFalse() + assertThat(b.getReasons()).isEqualTo("ConstraintTest: Set true\nConstraintTest: Set false") + assertThat(b.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set true\nConstraintTest: Set false") val d = ConstraintObject(10.0, aapsLogger) d.set(5.0, "Set 5d", this) - Assertions.assertEquals(5.0, d.value(), 0.01) - Assertions.assertEquals("ConstraintTest: Set 5d", d.getReasons()) - Assertions.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons()) + assertThat(d.value()).isWithin(0.01).of(5.0) + assertThat(d.getReasons()).isEqualTo("ConstraintTest: Set 5d") + assertThat(d.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set 5d") d.setIfSmaller(6.0, "Set 6d", this) - Assertions.assertEquals(5.0, d.value(), 0.01) - Assertions.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d", d.getReasons()) - Assertions.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons()) + assertThat(d.value()).isWithin(0.01).of(5.0) + assertThat(d.getReasons()).isEqualTo("ConstraintTest: Set 5d\nConstraintTest: Set 6d") + assertThat(d.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set 5d") d.setIfSmaller(4.0, "Set 4d", this) - Assertions.assertEquals(4.0, d.value(), 0.01) - Assertions.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d", d.getReasons()) - Assertions.assertEquals("ConstraintTest: Set 4d", d.getMostLimitedReasons()) - Assertions.assertEquals(10.0, d.originalValue(), 0.01) + assertThat(d.value()).isWithin(0.01).of(4.0) + assertThat(d.getReasons()).isEqualTo("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d") + assertThat(d.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set 4d") + assertThat(d.originalValue()).isWithin(0.01).of(10.0) d.setIfDifferent(7.0, "Set 7d", this) - Assertions.assertEquals(7.0, d.value(), 0.01) - Assertions.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getReasons()) - Assertions.assertEquals("ConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getMostLimitedReasons()) - Assertions.assertEquals(10.0, d.originalValue(), 0.01) + assertThat(d.value()).isWithin(0.01).of(7.0) + assertThat(d.getReasons()).isEqualTo("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d\nConstraintTest: Set 7d") + assertThat(d.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set 4d\nConstraintTest: Set 7d") + assertThat(d.originalValue()).isWithin(0.01).of(10.0) } - - @BeforeEach - fun prepareMock() { - } -} \ No newline at end of file +} From 62c5c53304ac799997aae2dffe457758f6d57b0b Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:08:25 -0700 Subject: [PATCH 02/16] Rewrites DetailedBolusInfoTest with matchers Issue #2745 --- .../core/data/DetailedBolusInfoTest.kt | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/data/DetailedBolusInfoTest.kt b/core/main/src/test/java/info/nightscout/core/data/DetailedBolusInfoTest.kt index 1f08b86191..dfb995168b 100644 --- a/core/main/src/test/java/info/nightscout/core/data/DetailedBolusInfoTest.kt +++ b/core/main/src/test/java/info/nightscout/core/data/DetailedBolusInfoTest.kt @@ -1,5 +1,6 @@ package info.nightscout.core.data +import com.google.common.truth.Truth.assertThat import android.content.Context import com.google.gson.Gson import info.nightscout.database.entities.Bolus @@ -8,7 +9,6 @@ import info.nightscout.database.entities.TherapyEvent import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.sharedtests.TestBase import org.apache.commons.lang3.builder.EqualsBuilder -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import org.mockito.Mock @@ -18,14 +18,14 @@ class DetailedBolusInfoTest : TestBase() { @Test fun toStringShouldBeOverloaded() { val detailedBolusInfo = DetailedBolusInfo() - Assertions.assertEquals(true, detailedBolusInfo.toJsonString().contains("insulin")) + assertThat(detailedBolusInfo.toJsonString()).contains("insulin") } @Test fun copyShouldCopyAllProperties() { val d1 = DetailedBolusInfo() d1.deliverAtTheLatest = 123 val d2 = d1.copy() - Assertions.assertTrue(EqualsBuilder.reflectionEquals(d2, d1, arrayListOf("id"))) + assertThat(EqualsBuilder.reflectionEquals(d2, d1, arrayListOf("id"))).isTrue() } private fun fromJsonString(json: String): DetailedBolusInfo = @@ -41,10 +41,10 @@ class DetailedBolusInfoTest : TestBase() { detailedBolusInfo.eventType = DetailedBolusInfo.EventType.BOLUS_WIZARD val serialized = detailedBolusInfo.toJsonString() val deserialized = fromJsonString(serialized) - Assertions.assertEquals(1L, deserialized.bolusCalculatorResult?.timestamp) - Assertions.assertEquals(DetailedBolusInfo.EventType.BOLUS_WIZARD, deserialized.eventType) + assertThat(deserialized.bolusCalculatorResult?.timestamp).isEqualTo(1L) + assertThat(deserialized.eventType).isEqualTo(DetailedBolusInfo.EventType.BOLUS_WIZARD) // Context should be excluded - Assertions.assertNull(deserialized.context) + assertThat(deserialized.context).isNull() } @Test @@ -56,12 +56,12 @@ class DetailedBolusInfoTest : TestBase() { detailedBolusInfo.glucoseType = DetailedBolusInfo.MeterType.FINGER val therapyEvent = detailedBolusInfo.createTherapyEvent() - Assertions.assertEquals(1000L, therapyEvent.timestamp) - Assertions.assertEquals(TherapyEvent.Type.MEAL_BOLUS, therapyEvent.type) - Assertions.assertEquals(TherapyEvent.GlucoseUnit.MGDL, therapyEvent.glucoseUnit) - Assertions.assertEquals("note", therapyEvent.note) - Assertions.assertEquals(180.0, therapyEvent.glucose) - Assertions.assertEquals(TherapyEvent.MeterType.FINGER, therapyEvent.glucoseType) + assertThat(therapyEvent.timestamp).isEqualTo(1000L) + assertThat(therapyEvent.type).isEqualTo(TherapyEvent.Type.MEAL_BOLUS) + assertThat(therapyEvent.glucoseUnit).isEqualTo(TherapyEvent.GlucoseUnit.MGDL) + assertThat(therapyEvent.note).isEqualTo("note") + assertThat(therapyEvent.glucose).isEqualTo(180.0) + assertThat(therapyEvent.glucoseType).isEqualTo(TherapyEvent.MeterType.FINGER) } @Test @@ -72,9 +72,9 @@ class DetailedBolusInfoTest : TestBase() { detailedBolusInfo.insulin = 7.0 val bolus = detailedBolusInfo.createBolus() - Assertions.assertEquals(1000L, bolus.timestamp) - Assertions.assertEquals(Bolus.Type.SMB, bolus.type) - Assertions.assertEquals(7.0, bolus.amount, 0.01) + assertThat(bolus.timestamp).isEqualTo(1000L) + assertThat(bolus.type).isEqualTo(Bolus.Type.SMB) + assertThat(bolus.amount).isWithin(0.01).of(7.0) } @Test @@ -84,8 +84,8 @@ class DetailedBolusInfoTest : TestBase() { detailedBolusInfo.carbs = 6.0 val carbs = detailedBolusInfo.createCarbs() - Assertions.assertEquals(1000L, carbs.timestamp) - Assertions.assertEquals(6.0, carbs.amount, 0.01) + assertThat(carbs.timestamp).isEqualTo(1000L) + assertThat(carbs.amount).isWithin(0.01).of(6.0) } private fun createBolusCalculatorResult(): BolusCalculatorResult = @@ -121,4 +121,4 @@ class DetailedBolusInfoTest : TestBase() { profileName = "profile", note = "" ) -} \ No newline at end of file +} From cfb003af01a73d5686641d936cc79a6538f1ef36 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:14:01 -0700 Subject: [PATCH 03/16] Rewrites IobTotalTest with matchers Issue #2745 --- .../info/nightscout/core/data/IobTotalTest.kt | 90 +++++++++---------- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/data/IobTotalTest.kt b/core/main/src/test/java/info/nightscout/core/data/IobTotalTest.kt index 8067daef2a..2779034469 100644 --- a/core/main/src/test/java/info/nightscout/core/data/IobTotalTest.kt +++ b/core/main/src/test/java/info/nightscout/core/data/IobTotalTest.kt @@ -1,6 +1,7 @@ package info.nightscout.core.data import android.content.Context +import com.google.common.truth.Truth.assertThat import info.nightscout.core.iob.combine import info.nightscout.core.iob.copy import info.nightscout.core.iob.determineBasalJson @@ -11,7 +12,6 @@ import info.nightscout.interfaces.iob.IobTotal import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtilImpl import info.nightscout.sharedtests.TestBase -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -34,7 +34,7 @@ class IobTotalTest : TestBase() { val a = IobTotal(now) a.iob = 10.0 val b = a.copy() - Assertions.assertEquals(a.iob, b.iob, 0.01) + assertThat(b.iob).isWithin(0.01).of(a.iob) } @Test fun plusTest() { @@ -48,14 +48,14 @@ class IobTotalTest : TestBase() { a.netInsulin = 10.0 a.extendedBolusInsulin = 10.0 a.plus(a.copy()) - Assertions.assertEquals(20.0, a.iob, 0.01) - Assertions.assertEquals(20.0, a.activity, 0.01) - Assertions.assertEquals(20.0, a.bolussnooze, 0.01) - Assertions.assertEquals(20.0, a.basaliob, 0.01) - Assertions.assertEquals(20.0, a.netbasalinsulin, 0.01) - Assertions.assertEquals(20.0, a.hightempinsulin, 0.01) - Assertions.assertEquals(20.0, a.netInsulin, 0.01) - Assertions.assertEquals(20.0, a.extendedBolusInsulin, 0.01) + assertThat(a.iob).isWithin(0.01).of(20.0) + assertThat(a.activity).isWithin(0.01).of(20.0) + assertThat(a.bolussnooze).isWithin(0.01).of(20.0) + assertThat(a.basaliob).isWithin(0.01).of(20.0) + assertThat(a.netbasalinsulin).isWithin(0.01).of(20.0) + assertThat(a.hightempinsulin).isWithin(0.01).of(20.0) + assertThat(a.netInsulin).isWithin(0.01).of(20.0) + assertThat(a.extendedBolusInsulin).isWithin(0.01).of(20.0) } @Test fun combineTest() { @@ -70,15 +70,15 @@ class IobTotalTest : TestBase() { a.extendedBolusInsulin = 17.0 val b = a.copy() val c = IobTotal.combine(a, b) - Assertions.assertEquals(a.time.toDouble(), c.time.toDouble(), 0.01) - Assertions.assertEquals(23.0, c.iob, 0.01) - Assertions.assertEquals(22.0, c.activity, 0.01) - Assertions.assertEquals(12.0, c.bolussnooze, 0.01) - Assertions.assertEquals(26.0, c.basaliob, 0.01) - Assertions.assertEquals(28.0, c.netbasalinsulin, 0.01) - Assertions.assertEquals(30.0, c.hightempinsulin, 0.01) - Assertions.assertEquals(32.0, c.netInsulin, 0.01) - Assertions.assertEquals(34.0, c.extendedBolusInsulin, 0.01) + assertThat(c.time.toDouble()).isWithin(0.01).of(a.time.toDouble()) + assertThat(c.iob).isWithin(0.01).of(23.0) + assertThat(c.activity).isWithin(0.01).of(22.0) + assertThat(c.bolussnooze).isWithin(0.01).of(12.0) + assertThat(c.basaliob).isWithin(0.01).of(26.0) + assertThat(c.netbasalinsulin).isWithin(0.01).of(28.0) + assertThat(c.hightempinsulin).isWithin(0.01).of(30.0) + assertThat(c.netInsulin).isWithin(0.01).of(32.0) + assertThat(c.extendedBolusInsulin).isWithin(0.01).of(34.0) } @Test fun roundTest() { @@ -92,14 +92,14 @@ class IobTotalTest : TestBase() { a.netInsulin = 1.1111111111111 a.extendedBolusInsulin = 1.1111111111111 a.round() - Assertions.assertEquals(1.111, a.iob, 0.00001) - Assertions.assertEquals(1.1111, a.activity, 0.00001) - Assertions.assertEquals(1.1111, a.bolussnooze, 0.00001) - Assertions.assertEquals(1.111, a.basaliob, 0.00001) - Assertions.assertEquals(1.111, a.netbasalinsulin, 0.00001) - Assertions.assertEquals(1.111, a.hightempinsulin, 0.00001) - Assertions.assertEquals(1.111, a.netInsulin, 0.00001) - Assertions.assertEquals(1.111, a.extendedBolusInsulin, 0.00001) + assertThat(a.iob).isWithin(0.00001).of(1.111) + assertThat(a.activity).isWithin(0.00001).of(1.1111) + assertThat(a.bolussnooze).isWithin(0.00001).of(1.1111) + assertThat(a.basaliob).isWithin(0.00001).of(1.111) + assertThat(a.netbasalinsulin).isWithin(0.00001).of(1.111) + assertThat(a.hightempinsulin).isWithin(0.00001).of(1.111) + assertThat(a.netInsulin).isWithin(0.00001).of(1.111) + assertThat(a.extendedBolusInsulin).isWithin(0.00001).of(1.111) } @Test fun jsonTest() { @@ -112,15 +112,11 @@ class IobTotalTest : TestBase() { a.hightempinsulin = 15.0 a.netInsulin = 16.0 a.extendedBolusInsulin = 17.0 - try { - val j = a.json(dateUtil) - Assertions.assertEquals(a.iob, j.getDouble("iob"), 0.0000001) - Assertions.assertEquals(a.basaliob, j.getDouble("basaliob"), 0.0000001) - Assertions.assertEquals(a.activity, j.getDouble("activity"), 0.0000001) - Assertions.assertEquals(now, dateUtil.fromISODateString(j.getString("time"))) - } catch (e: Exception) { - Assertions.fail("Exception: " + e.message) - } + val j = a.json(dateUtil) + assertThat(j.getDouble("iob")).isWithin(0.0000001).of(a.iob) + assertThat(j.getDouble("basaliob")).isWithin(0.0000001).of(a.basaliob) + assertThat(j.getDouble("activity")).isWithin(0.0000001).of(a.activity) + assertThat(dateUtil.fromISODateString(j.getString("time"))).isEqualTo(now) } @Test fun determineBasalJsonTest() { @@ -134,17 +130,13 @@ class IobTotalTest : TestBase() { a.netInsulin = 16.0 a.extendedBolusInsulin = 17.0 a.iobWithZeroTemp = IobTotal(now) - try { - val j = a.determineBasalJson(dateUtil) - Assertions.assertEquals(a.iob, j.getDouble("iob"), 0.0000001) - Assertions.assertEquals(a.basaliob, j.getDouble("basaliob"), 0.0000001) - Assertions.assertEquals(a.bolussnooze, j.getDouble("bolussnooze"), 0.0000001) - Assertions.assertEquals(a.activity, j.getDouble("activity"), 0.0000001) - Assertions.assertEquals(0, j.getLong("lastBolusTime")) - Assertions.assertEquals(now, dateUtil.fromISODateString(j.getString("time"))) - Assertions.assertNotNull(j.getJSONObject("iobWithZeroTemp")) - } catch (e: Exception) { - Assertions.fail("Exception: " + e.message) - } + val j = a.determineBasalJson(dateUtil) + assertThat(j.getDouble("iob")).isWithin(0.0000001).of(a.iob) + assertThat(j.getDouble("basaliob")).isWithin(0.0000001).of(a.basaliob) + assertThat(j.getDouble("bolussnooze")).isWithin(0.0000001).of(a.bolussnooze) + assertThat(j.getDouble("activity")).isWithin(0.0000001).of(a.activity) + assertThat(j.getLong("lastBolusTime")).isEqualTo(0) + assertThat(dateUtil.fromISODateString(j.getString("time"))).isEqualTo(now) + assertThat(j.getJSONObject("iobWithZeroTemp")).isNotNull() } -} \ No newline at end of file +} From a46e396815e45804affb4c3191efa7f4d391ed1c Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:16:25 -0700 Subject: [PATCH 04/16] Rewrites MealDataTest with matchers Issue #2745 --- .../src/test/java/info/nightscout/core/data/MealDataTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/data/MealDataTest.kt b/core/main/src/test/java/info/nightscout/core/data/MealDataTest.kt index cd79a805ff..d6994d9d30 100644 --- a/core/main/src/test/java/info/nightscout/core/data/MealDataTest.kt +++ b/core/main/src/test/java/info/nightscout/core/data/MealDataTest.kt @@ -1,13 +1,13 @@ package info.nightscout.core.data +import com.google.common.truth.Truth.assertThat import info.nightscout.interfaces.iob.MealData -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test class MealDataTest { @Test fun canCreateObject() { val md = MealData() - Assertions.assertEquals(0.0, md.carbs, 0.01) + assertThat(md.carbs).isWithin(0.01).of(0.0) } -} \ No newline at end of file +} From 1448eb93947a1398892ccc7a8eee126db32e1c99 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:28:04 -0700 Subject: [PATCH 05/16] Rewrites ProfileTest with matchers Issue #2745 --- .../info/nightscout/core/data/ProfileTest.kt | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/data/ProfileTest.kt b/core/main/src/test/java/info/nightscout/core/data/ProfileTest.kt index 100f5fac12..bbad9e1711 100644 --- a/core/main/src/test/java/info/nightscout/core/data/ProfileTest.kt +++ b/core/main/src/test/java/info/nightscout/core/data/ProfileTest.kt @@ -1,6 +1,7 @@ package info.nightscout.core.data import android.content.Context +import com.google.common.truth.Truth.assertThat import dagger.android.AndroidInjector import info.nightscout.core.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed @@ -15,7 +16,6 @@ import info.nightscout.sharedtests.HardLimitsMock import info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestPumpPlugin import org.json.JSONObject -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -71,77 +71,77 @@ class ProfileTest : TestBase() { // Test valid profile var p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(okProfile), dateUtil)!!) - Assertions.assertEquals(true, p.isValid("Test", testPumpPlugin, config, rh, rxBus, hardLimits, false).isValid) -// Assertions.assertEquals(true, p.log().contains("NS units: mmol")) + assertThat(p.isValid("Test", testPumpPlugin, config, rh, rxBus, hardLimits, false).isValid).isTrue() +// assertThat(p.log()).contains("NS units: mmol") // JSONAssertions.assertEquals(JSONObject(okProfile), p.toPureNsJson(dateUtil), false) - Assertions.assertEquals(5.0, p.dia, 0.01) -// Assertions.assertEquals(TimeZone.getTimeZone("UTC"), p.timeZone) - Assertions.assertEquals("00:30", dateUtil.formatHHMM(30 * 60)) + assertThat(p.dia).isWithin(0.01).of(5.0) +// assertThat(p.timeZone).isEqualTo(TimeZone.getTimeZone("UTC")) + assertThat(dateUtil.formatHHMM(30 * 60)).isEqualTo("00:30") val c = Calendar.getInstance() c[Calendar.HOUR_OF_DAY] = 1 c[Calendar.MINUTE] = 0 c[Calendar.SECOND] = 0 c[Calendar.MILLISECOND] = 0 - Assertions.assertEquals(108.0, p.getIsfMgdl(c.timeInMillis), 0.01) + assertThat(p.getIsfMgdl(c.timeInMillis)).isWithin(0.01).of(108.0) c[Calendar.HOUR_OF_DAY] = 2 - Assertions.assertEquals(111.6, p.getIsfMgdl(c.timeInMillis), 0.01) -// Assertions.assertEquals(110.0, p.getIsfTimeFromMidnight(2 * 60 * 60), 0.01) - Assertions.assertEquals( + assertThat(p.getIsfMgdl(c.timeInMillis)).isWithin(0.01).of(111.6) +// assertThat(p.getIsfTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(110.0) + assertThat(p.getIsfList(rh, dateUtil).replace(".", ",")).isEqualTo( """ 00:00 6,0 mmol/U 02:00 6,2 mmol/U - """.trimIndent(), p.getIsfList(rh, dateUtil).replace(".", ",") + """.trimIndent() ) - Assertions.assertEquals(30.0, p.getIc(c.timeInMillis), 0.01) - Assertions.assertEquals(30.0, p.getIcTimeFromMidnight(2 * 60 * 60), 0.01) - Assertions.assertEquals("00:00 30,0 g/U", p.getIcList(rh, dateUtil).replace(".", ",")) - Assertions.assertEquals(0.1, p.getBasal(c.timeInMillis), 0.01) - Assertions.assertEquals(0.1, p.getBasalTimeFromMidnight(2 * 60 * 60), 0.01) - Assertions.assertEquals("00:00 0,10 U/h", p.getBasalList(rh, dateUtil).replace(".", ",")) - Assertions.assertEquals(0.1, p.getBasalValues()[0].value, 0.01) - Assertions.assertEquals(0.1, p.getMaxDailyBasal(), 0.01) - Assertions.assertEquals(2.4, p.percentageBasalSum(), 0.01) - Assertions.assertEquals(2.4, p.baseBasalSum(), 0.01) -// Assertions.assertEquals(81.0, p.getTargetMgdl(2 * 60 * 60), 0.01) - Assertions.assertEquals(90.0, p.getTargetLowMgdl(c.timeInMillis), 0.01) -// Assertions.assertEquals(4.0, p.getTargetLowTimeFromMidnight(2 * 60 * 60), 0.01) - Assertions.assertEquals(90.0, p.getTargetHighMgdl(c.timeInMillis), 0.01) -// Assertions.assertEquals(5.0, p.getTargetHighTimeFromMidnight(2 * 60 * 60), 0.01) - Assertions.assertEquals("00:00 5,0 - 5,0 mmol", p.getTargetList(rh, dateUtil).replace(".", ",")) - Assertions.assertEquals(100, p.percentage) - Assertions.assertEquals(0, p.timeshift) + assertThat(p.getIc(c.timeInMillis)).isWithin(0.01).of(30.0) + assertThat(p.getIcTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(30.0) + assertThat(p.getIcList(rh, dateUtil).replace(".", ",")).isEqualTo("00:00 30,0 g/U") + assertThat(p.getBasal(c.timeInMillis)).isWithin(0.01).of(0.1) + assertThat(p.getBasalTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(0.1) + assertThat(p.getBasalList(rh, dateUtil).replace(".", ",")).isEqualTo("00:00 0,10 U/h") + assertThat(p.getBasalValues()[0].value).isWithin(0.01).of(0.1) + assertThat(p.getMaxDailyBasal()).isWithin(0.01).of(0.1) + assertThat(p.percentageBasalSum()).isWithin(0.01).of(2.4) + assertThat(p.baseBasalSum()).isWithin(0.01).of(2.4) +// assertThat( p.getTargetMgdl(2 * 60 * 60)).isWithin(0.01).of(81.0) + assertThat( p.getTargetLowMgdl(c.timeInMillis)).isWithin(0.01).of(90.0) +// assertThat( p.getTargetLowTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(4.0) + assertThat( p.getTargetHighMgdl(c.timeInMillis)).isWithin(0.01).of(90.0) +// assertThat( p.getTargetHighTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(5.0) + assertThat(p.getTargetList(rh, dateUtil).replace(".", ",")).isEqualTo("00:00 5,0 - 5,0 mmol") + assertThat(p.percentage).isEqualTo(100) + assertThat(p.timeshift).isEqualTo(0) //Test basal profile below limit p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(belowLimitValidProfile), dateUtil)!!) p.isValid("Test", testPumpPlugin, config, rh, rxBus, hardLimits, false) // Test profile w/o units - Assertions.assertNull(pureProfileFromJson(JSONObject(noUnitsValidProfile), dateUtil)) + assertThat(pureProfileFromJson(JSONObject(noUnitsValidProfile), dateUtil)).isNull() //Test profile not starting at midnight p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(notStartingAtZeroValidProfile), dateUtil)!!) - Assertions.assertEquals(30.0, p.getIc(0), 0.01) + assertThat(p.getIc(0)).isWithin(0.01).of(30.0) // Test wrong profile - Assertions.assertNull(pureProfileFromJson(JSONObject(wrongProfile), dateUtil)) + assertThat(pureProfileFromJson(JSONObject(wrongProfile), dateUtil)).isNull() // Test percentage functionality p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(okProfile), dateUtil)!!) p.pct = 50 - Assertions.assertEquals(0.05, p.getBasal(c.timeInMillis), 0.01) - Assertions.assertEquals(1.2, p.percentageBasalSum(), 0.01) - Assertions.assertEquals(60.0, p.getIc(c.timeInMillis), 0.01) - Assertions.assertEquals(223.2, p.getIsfMgdl(c.timeInMillis), 0.01) + assertThat(p.getBasal(c.timeInMillis)).isWithin(0.01).of(0.05) + assertThat(p.percentageBasalSum()).isWithin(0.01).of(1.2) + assertThat(p.getIc(c.timeInMillis)).isWithin(0.01).of(60.0) + assertThat(p.getIsfMgdl(c.timeInMillis)).isWithin(0.01).of(223.2) // Test timeshift functionality p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(okProfile), dateUtil)!!) p.ts = 1 - Assertions.assertEquals( + assertThat(p.getIsfList(rh, dateUtil).replace(',', '.')).isEqualTo( """ 00:00 6.2 mmol/U 01:00 6.0 mmol/U 03:00 6.2 mmol/U - """.trimIndent(), p.getIsfList(rh, dateUtil).replace(',', '.') + """.trimIndent() ) // Test hour alignment @@ -149,4 +149,4 @@ class ProfileTest : TestBase() { p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(notAlignedBasalValidProfile), dateUtil)!!) p.isValid("Test", testPumpPlugin, config, rh, rxBus, hardLimits, false) } -} \ No newline at end of file +} From 571c95a85979b6692af4b10052a67749c58a6c26 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:32:07 -0700 Subject: [PATCH 06/16] Rewrites BlockExtensionKtTest with matchers --- .../core/extensions/BlockExtensionKtTest.kt | 116 +++++++++--------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/extensions/BlockExtensionKtTest.kt b/core/main/src/test/java/info/nightscout/core/extensions/BlockExtensionKtTest.kt index 4ddac08d24..733b01ff17 100644 --- a/core/main/src/test/java/info/nightscout/core/extensions/BlockExtensionKtTest.kt +++ b/core/main/src/test/java/info/nightscout/core/extensions/BlockExtensionKtTest.kt @@ -1,10 +1,10 @@ package info.nightscout.core.extensions +import com.google.common.truth.Truth.assertThat import info.nightscout.database.entities.data.Block import info.nightscout.database.entities.data.TargetBlock import info.nightscout.database.entities.data.checkSanity import info.nightscout.shared.utils.T -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test class BlockExtensionKtTest { @@ -17,36 +17,36 @@ class BlockExtensionKtTest { b.add(Block(T.hours(10).msecs(), 3.0)) b.add(Block(T.hours(12).msecs(), 4.0)) - Assertions.assertTrue(b.checkSanity()) + assertThat(b.checkSanity()).isTrue() - Assertions.assertEquals(1.0, b.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(2.0, b.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(3.0, b.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(3.0, b.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(4.0, b.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(4.0, b.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0), 0.01) + assertThat(b.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0)).isWithin(0.01).of(1.0) + assertThat(b.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0)).isWithin(0.01).of(2.0) + assertThat(b.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0) + assertThat(b.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0) + assertThat(b.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0) + assertThat(b.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0) val s1 = b.shiftBlock(1.0, -1) - Assertions.assertTrue(s1.checkSanity()) + assertThat(s1.checkSanity()).isTrue() - Assertions.assertEquals(1.0, s1.blockValueBySeconds(T.hours(23).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(2.0, s1.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(3.0, s1.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(3.0, s1.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(4.0, s1.blockValueBySeconds(T.hours(11).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(4.0, s1.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0), 0.01) + assertThat(s1.blockValueBySeconds(T.hours(23).secs().toInt(), 1.0, 0)).isWithin(0.01).of(1.0) + assertThat(s1.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0)).isWithin(0.01).of(2.0) + assertThat(s1.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0) + assertThat(s1.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0) + assertThat(s1.blockValueBySeconds(T.hours(11).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0) + assertThat(s1.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0) val s2 = b.shiftBlock(2.0, 1) - Assertions.assertTrue(s2.checkSanity()) + assertThat(s2.checkSanity()).isTrue() - Assertions.assertEquals(2.0, s2.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(4.0, s2.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(6.0, s2.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(6.0, s2.blockValueBySeconds(T.hours(4).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(8.0, s2.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0), 0.01) - Assertions.assertEquals(8.0, s2.blockValueBySeconds(T.hours(14).secs().toInt(), 1.0, 0), 0.01) + assertThat(s2.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0)).isWithin(0.01).of(2.0) + assertThat(s2.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0) + assertThat(s2.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0)).isWithin(0.01).of(6.0) + assertThat(s2.blockValueBySeconds(T.hours(4).secs().toInt(), 1.0, 0)).isWithin(0.01).of(6.0) + assertThat(s2.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0)).isWithin(0.01).of(8.0) + assertThat(s2.blockValueBySeconds(T.hours(14).secs().toInt(), 1.0, 0)).isWithin(0.01).of(8.0) } @Test @@ -57,36 +57,36 @@ class BlockExtensionKtTest { b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0)) b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0)) - Assertions.assertTrue(b.checkSanity()) + assertThat(b.checkSanity()).isTrue() - Assertions.assertEquals(1.5, b.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01) - Assertions.assertEquals(2.5, b.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01) - Assertions.assertEquals(3.5, b.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01) - Assertions.assertEquals(3.5, b.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01) - Assertions.assertEquals(4.5, b.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01) - Assertions.assertEquals(4.5, b.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01) + assertThat(b.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(1.5) + assertThat(b.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(2.5) + assertThat(b.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(3.5) + assertThat(b.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(3.5) + assertThat(b.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(4.5) + assertThat(b.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(4.5) val s1 = b.shiftTargetBlock(-1) - Assertions.assertTrue(s1.checkSanity()) + assertThat(s1.checkSanity()).isTrue() - Assertions.assertEquals(1.5, s1.targetBlockValueBySeconds(T.hours(23).secs().toInt(), 0), 0.01) - Assertions.assertEquals(2.5, s1.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01) - Assertions.assertEquals(3.5, s1.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01) - Assertions.assertEquals(3.5, s1.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01) - Assertions.assertEquals(4.5, s1.targetBlockValueBySeconds(T.hours(11).secs().toInt(), 0), 0.01) - Assertions.assertEquals(4.5, s1.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01) + assertThat(s1.targetBlockValueBySeconds(T.hours(23).secs().toInt(), 0)).isWithin(0.01).of(1.5) + assertThat(s1.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(2.5) + assertThat(s1.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(3.5) + assertThat(s1.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(3.5) + assertThat(s1.targetBlockValueBySeconds(T.hours(11).secs().toInt(), 0)).isWithin(0.01).of(4.5) + assertThat(s1.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(4.5) val s2 = b.shiftTargetBlock(1) - Assertions.assertTrue(s2.checkSanity()) + assertThat(s2.checkSanity()).isTrue() - Assertions.assertEquals(1.5, s2.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01) - Assertions.assertEquals(2.5, s2.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01) - Assertions.assertEquals(3.5, s2.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01) - Assertions.assertEquals(3.5, s2.targetBlockValueBySeconds(T.hours(4).secs().toInt(), 0), 0.01) - Assertions.assertEquals(4.5, s2.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01) - Assertions.assertEquals(4.5, s2.targetBlockValueBySeconds(T.hours(14).secs().toInt(), 0), 0.01) + assertThat(s2.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(1.5) + assertThat(s2.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(2.5) + assertThat(s2.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(3.5) + assertThat(s2.targetBlockValueBySeconds(T.hours(4).secs().toInt(), 0)).isWithin(0.01).of(3.5) + assertThat(s2.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(4.5) + assertThat(s2.targetBlockValueBySeconds(T.hours(14).secs().toInt(), 0)).isWithin(0.01).of(4.5) } @Test @@ -97,14 +97,14 @@ class BlockExtensionKtTest { b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0)) b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0)) - Assertions.assertTrue(b.checkSanity()) + assertThat(b.checkSanity()).isTrue() - Assertions.assertEquals(1.0, b.lowTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01) - Assertions.assertEquals(2.0, b.lowTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01) - Assertions.assertEquals(3.0, b.lowTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01) - Assertions.assertEquals(3.0, b.lowTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01) - Assertions.assertEquals(4.0, b.lowTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01) - Assertions.assertEquals(4.0, b.lowTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01) + assertThat(b.lowTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(1.0) + assertThat(b.lowTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(2.0) + assertThat(b.lowTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(3.0) + assertThat(b.lowTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(3.0) + assertThat(b.lowTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(4.0) + assertThat(b.lowTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(4.0) } @Test @@ -115,13 +115,13 @@ class BlockExtensionKtTest { b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0)) b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0)) - Assertions.assertTrue(b.checkSanity()) + assertThat(b.checkSanity()).isTrue() - Assertions.assertEquals(2.0, b.highTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01) - Assertions.assertEquals(3.0, b.highTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01) - Assertions.assertEquals(4.0, b.highTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01) - Assertions.assertEquals(4.0, b.highTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01) - Assertions.assertEquals(5.0, b.highTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01) - Assertions.assertEquals(5.0, b.highTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01) + assertThat(b.highTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(2.0) + assertThat(b.highTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(3.0) + assertThat(b.highTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(4.0) + assertThat(b.highTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(4.0) + assertThat(b.highTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(5.0) + assertThat(b.highTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(5.0) } -} \ No newline at end of file +} From 1417ff8d573f1bcce7ad9071a5f2bdad77cc48e6 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:35:37 -0700 Subject: [PATCH 07/16] Rewrites InMemoryGlucoseValueDataPointTest with matchers Issue #2745 --- .../core/graph/data/InMemoryGlucoseValueDataPointTest.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/graph/data/InMemoryGlucoseValueDataPointTest.kt b/core/main/src/test/java/info/nightscout/core/graph/data/InMemoryGlucoseValueDataPointTest.kt index d3f54d1de5..630479e72c 100644 --- a/core/main/src/test/java/info/nightscout/core/graph/data/InMemoryGlucoseValueDataPointTest.kt +++ b/core/main/src/test/java/info/nightscout/core/graph/data/InMemoryGlucoseValueDataPointTest.kt @@ -2,13 +2,13 @@ package info.nightscout.core.graph.data import android.content.Context import android.graphics.Color +import com.google.common.truth.Truth.assertThat import info.nightscout.database.entities.GlucoseValue import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.profile.DefaultValueHelper import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.shared.interfaces.ResourceHelper -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -34,15 +34,16 @@ internal class InMemoryGlucoseValueDataPointTest { Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) Mockito.`when`(rh.gac(any(), any())).thenReturn(Color.GREEN) } + @Test fun alphaShouldBeAddedForFilledGaps() { val gv = InMemoryGlucoseValue(1000, 100.0, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN) val sut = InMemoryGlucoseValueDataPoint(gv, defaultValueHelper, profileFunction, rh) var alpha = sut.color(context).ushr(24) - Assertions.assertEquals(255, alpha) + assertThat(alpha).isEqualTo(255) gv.filledGap = true alpha = sut.color(context).ushr(24) - Assertions.assertEquals(128, alpha) + assertThat(alpha).isEqualTo(128) } -} \ No newline at end of file +} From 398eb7a12dd80dcd2db76cc6738433f61e28341d Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:39:00 -0700 Subject: [PATCH 08/16] Rewrites PluginDescriptionTest with matchers Issue #2745 --- .../core/interfaces/PluginDescriptionTest.kt | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/interfaces/PluginDescriptionTest.kt b/core/main/src/test/java/info/nightscout/core/interfaces/PluginDescriptionTest.kt index 3bd219cce9..ae3e45e520 100644 --- a/core/main/src/test/java/info/nightscout/core/interfaces/PluginDescriptionTest.kt +++ b/core/main/src/test/java/info/nightscout/core/interfaces/PluginDescriptionTest.kt @@ -1,70 +1,70 @@ package info.nightscout.core.interfaces +import com.google.common.truth.Truth.assertThat import androidx.fragment.app.Fragment import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test class PluginDescriptionTest { @Test fun mainTypeTest() { val pluginDescription = PluginDescription().mainType(PluginType.PUMP) - Assertions.assertEquals(PluginType.PUMP, pluginDescription.mainType) + assertThat(pluginDescription.mainType).isEqualTo(PluginType.PUMP) } @Test fun fragmentClassTest() { val pluginDescription = PluginDescription().fragmentClass(Fragment::class.java.name) - Assertions.assertEquals(Fragment::class.java.name, pluginDescription.fragmentClass) + assertThat(pluginDescription.fragmentClass).isEqualTo(Fragment::class.java.name) } @Test fun alwaysEnabledTest() { val pluginDescription = PluginDescription().alwaysEnabled(true) - Assertions.assertEquals(true, pluginDescription.alwaysEnabled) + assertThat(pluginDescription.alwaysEnabled).isTrue() } @Test fun alwaysVisibleTest() { val pluginDescription = PluginDescription().alwaysVisible(true) - Assertions.assertEquals(true, pluginDescription.alwaysVisible) + assertThat(pluginDescription.alwaysVisible).isTrue() } @Test fun neverVisibleTest() { val pluginDescription = PluginDescription().neverVisible(true) - Assertions.assertEquals(true, pluginDescription.neverVisible) + assertThat(pluginDescription.neverVisible).isTrue() } @Test fun showInListTest() { val pluginDescription = PluginDescription().showInList(false) - Assertions.assertEquals(false, pluginDescription.showInList) + assertThat(pluginDescription.showInList).isFalse() } @Test fun pluginIcon() { val pluginDescription = PluginDescription().pluginIcon(10) - Assertions.assertEquals(10, pluginDescription.pluginIcon.toLong()) + assertThat(pluginDescription.pluginIcon.toLong()).isEqualTo(10) } @Test fun pluginName() { val pluginDescription = PluginDescription().pluginName(10) - Assertions.assertEquals(10, pluginDescription.pluginName.toLong()) + assertThat(pluginDescription.pluginName.toLong()).isEqualTo(10) } @Test fun shortNameTest() { val pluginDescription = PluginDescription().shortName(10) - Assertions.assertEquals(10, pluginDescription.shortName.toLong()) + assertThat(pluginDescription.shortName.toLong()).isEqualTo(10) } @Test fun preferencesIdTest() { val pluginDescription = PluginDescription().preferencesId(10) - Assertions.assertEquals(10, pluginDescription.preferencesId.toLong()) + assertThat(pluginDescription.preferencesId.toLong()).isEqualTo(10) } @Test fun enableByDefault() { val pluginDescription = PluginDescription().enableByDefault(true) - Assertions.assertEquals(true, pluginDescription.enableByDefault) + assertThat(pluginDescription.enableByDefault).isTrue() } @Test fun visibleByDefault() { val pluginDescription = PluginDescription().visibleByDefault(true) - Assertions.assertEquals(true, pluginDescription.visibleByDefault) + assertThat(pluginDescription.visibleByDefault).isTrue() } -} \ No newline at end of file +} From 0355a58d47bd72651ffce896819907c71f1512d7 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:44:47 -0700 Subject: [PATCH 09/16] Rewrites PumpDescriptionTest with matchers Issue #2745 --- .../core/interfaces/PumpDescriptionTest.kt | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/interfaces/PumpDescriptionTest.kt b/core/main/src/test/java/info/nightscout/core/interfaces/PumpDescriptionTest.kt index 2e7711d103..eda615a2c7 100644 --- a/core/main/src/test/java/info/nightscout/core/interfaces/PumpDescriptionTest.kt +++ b/core/main/src/test/java/info/nightscout/core/interfaces/PumpDescriptionTest.kt @@ -1,10 +1,10 @@ package info.nightscout.core.interfaces +import com.google.common.truth.Truth.assertThat import info.nightscout.interfaces.pump.defs.PumpCapability import info.nightscout.interfaces.pump.defs.PumpDescription import info.nightscout.interfaces.pump.defs.PumpTempBasalType import info.nightscout.interfaces.pump.defs.PumpType -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test class PumpDescriptionTest { @@ -12,22 +12,22 @@ class PumpDescriptionTest { @Test fun setPumpDescription() { val pumpDescription = PumpDescription() pumpDescription.fillFor(PumpType.ACCU_CHEK_COMBO) - Assertions.assertEquals(pumpDescription.bolusStep, PumpType.ACCU_CHEK_COMBO.bolusSize, 0.1) - Assertions.assertEquals(pumpDescription.basalMinimumRate, PumpType.ACCU_CHEK_COMBO.baseBasalStep, 0.1) - Assertions.assertEquals(pumpDescription.basalStep, PumpType.ACCU_CHEK_COMBO.baseBasalStep, 0.1) - Assertions.assertEquals(pumpDescription.extendedBolusDurationStep, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.durationStep?.toDouble()) - Assertions.assertEquals(pumpDescription.extendedBolusMaxDuration, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.maxDuration?.toDouble()) - Assertions.assertEquals(pumpDescription.extendedBolusStep, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.step) - Assertions.assertEquals(pumpDescription.isExtendedBolusCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.ExtendedBolus)) - Assertions.assertEquals(pumpDescription.isBolusCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Bolus)) - Assertions.assertEquals(pumpDescription.isRefillingCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Refill)) - Assertions.assertEquals(pumpDescription.isSetBasalProfileCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.BasalProfileSet)) - Assertions.assertEquals(pumpDescription.isTempBasalCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.TempBasal)) - Assertions.assertEquals(pumpDescription.maxTempPercent.toDouble(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.maxDose) - Assertions.assertEquals(pumpDescription.tempPercentStep.toDouble(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.step) - Assertions.assertEquals(pumpDescription.tempBasalStyle, if (PumpType.ACCU_CHEK_COMBO.pumpTempBasalType == PumpTempBasalType.Percent) PumpDescription.PERCENT else PumpDescription.ABSOLUTE) - Assertions.assertEquals(pumpDescription.tempDurationStep.toLong(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.durationStep?.toLong()) - Assertions.assertEquals(pumpDescription.tempDurationStep15mAllowed, PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration15minAllowed)) - Assertions.assertEquals(pumpDescription.tempDurationStep30mAllowed, PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration30minAllowed)) + assertThat(pumpDescription.bolusStep).isWithin(0.1).of(PumpType.ACCU_CHEK_COMBO.bolusSize) + assertThat(pumpDescription.basalMinimumRate).isWithin(0.1).of(PumpType.ACCU_CHEK_COMBO.baseBasalStep) + assertThat(pumpDescription.basalStep).isWithin(0.1).of(PumpType.ACCU_CHEK_COMBO.baseBasalStep) + assertThat(pumpDescription.extendedBolusDurationStep).isEqualTo(PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.durationStep?.toDouble()) + assertThat(pumpDescription.extendedBolusMaxDuration).isEqualTo(PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.maxDuration?.toDouble()) + assertThat(pumpDescription.extendedBolusStep).isEqualTo(PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.step) + assertThat(pumpDescription.isExtendedBolusCapable).isEqualTo(PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.ExtendedBolus)) + assertThat(pumpDescription.isBolusCapable).isEqualTo(PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Bolus)) + assertThat(pumpDescription.isRefillingCapable).isEqualTo(PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Refill)) + assertThat(pumpDescription.isSetBasalProfileCapable).isEqualTo(PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.BasalProfileSet)) + assertThat(pumpDescription.isTempBasalCapable).isEqualTo(PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.TempBasal)) + assertThat(pumpDescription.maxTempPercent.toDouble()).isEqualTo(PumpType.ACCU_CHEK_COMBO.tbrSettings?.maxDose) + assertThat(pumpDescription.tempPercentStep.toDouble()).isEqualTo(PumpType.ACCU_CHEK_COMBO.tbrSettings?.step) + assertThat(pumpDescription.tempBasalStyle).isEqualTo(if (PumpType.ACCU_CHEK_COMBO.pumpTempBasalType == PumpTempBasalType.Percent) PumpDescription.PERCENT else PumpDescription.ABSOLUTE) + assertThat(pumpDescription.tempDurationStep.toLong()).isEqualTo(PumpType.ACCU_CHEK_COMBO.tbrSettings?.durationStep?.toLong()) + assertThat(pumpDescription.tempDurationStep15mAllowed).isEqualTo(PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration15minAllowed)) + assertThat(pumpDescription.tempDurationStep30mAllowed).isEqualTo(PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration30minAllowed)) } -} \ No newline at end of file +} From 84138eba338a673317c9c5ad9ae0193f9bc53257 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:48:34 -0700 Subject: [PATCH 10/16] Rewrites DateTimeUtilUTest with matchers Issue #2745 --- .../nightscout/core/pump/common/utils/DateTimeUtilUTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/pump/common/utils/DateTimeUtilUTest.kt b/core/main/src/test/java/info/nightscout/core/pump/common/utils/DateTimeUtilUTest.kt index 8ba9e67eb7..5da3ef3e6d 100644 --- a/core/main/src/test/java/info/nightscout/core/pump/common/utils/DateTimeUtilUTest.kt +++ b/core/main/src/test/java/info/nightscout/core/pump/common/utils/DateTimeUtilUTest.kt @@ -1,7 +1,7 @@ package info.nightscout.core.pump.common.utils +import com.google.common.truth.Truth.assertThat import info.nightscout.core.utils.DateTimeUtil -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test internal class DateTimeUtilUTest { @@ -10,6 +10,6 @@ internal class DateTimeUtilUTest { val dt1 = 20191001182301L val dt2 = 20191001192805L val aTechDateDifferenceAsMinutes = DateTimeUtil.getATechDateDifferenceAsMinutes(dt1, dt2) - Assertions.assertEquals(65, aTechDateDifferenceAsMinutes) + assertThat(aTechDateDifferenceAsMinutes).isEqualTo(65) } -} \ No newline at end of file +} From 8819aed6e14529c4814ffa48e803b0e23e59b7ec Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:53:18 -0700 Subject: [PATCH 11/16] Rewrites CryptoUtilTest with matchers Issue #2745 --- .../nightscout/core/utils/CryptoUtilTest.kt | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/utils/CryptoUtilTest.kt b/core/main/src/test/java/info/nightscout/core/utils/CryptoUtilTest.kt index e57753fddb..824b4dc183 100644 --- a/core/main/src/test/java/info/nightscout/core/utils/CryptoUtilTest.kt +++ b/core/main/src/test/java/info/nightscout/core/utils/CryptoUtilTest.kt @@ -1,8 +1,8 @@ package info.nightscout.core.utils +import com.google.common.truth.Truth.assertThat import com.google.common.truth.TruthJUnit.assume import info.nightscout.sharedtests.TestBase -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test // https://stackoverflow.com/questions/52344522/joseexception-couldnt-create-aes-gcm-nopadding-cipher-illegal-key-size @@ -33,11 +33,11 @@ class CryptoUtilTest : TestBase() { val encrypted = cryptoUtil.encrypt(password, salt, payload) assumeAES256isSupported(cryptoUtil) - Assertions.assertNotNull(encrypted) + assertThat(encrypted).isNotNull() val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!) assumeAES256isSupported(cryptoUtil) - Assertions.assertEquals(decrypted, payload) + assertThat(decrypted).isEqualTo(payload) } @Test @@ -49,18 +49,18 @@ class CryptoUtilTest : TestBase() { val encrypted = cryptoUtil.encrypt(password, salt, payload) assumeAES256isSupported(cryptoUtil) - Assertions.assertNotNull(encrypted) + assertThat(encrypted).isNotNull() val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!) assumeAES256isSupported(cryptoUtil) - Assertions.assertEquals(decrypted, payload) + assertThat(decrypted).isEqualTo(payload) } @Test fun testHashVector() { val payload = "{what:payloadYouWantToProtect}" val hash = cryptoUtil.sha256(payload) - Assertions.assertEquals(hash, "a1aafe3ed6cc127e6d102ddbc40a205147230e9cfd178daf108c83543bbdcd13") + assertThat(hash).isEqualTo("a1aafe3ed6cc127e6d102ddbc40a205147230e9cfd178daf108c83543bbdcd13") } @Test @@ -69,44 +69,44 @@ class CryptoUtilTest : TestBase() { val password = "topSikret" val expectedHmac = "ea2213953d0f2e55047cae2d23fb4f0de1b805d55e6271efa70d6b85fb692bea" // generated using other HMAC tool val hash = cryptoUtil.hmac256(payload, password) - Assertions.assertEquals(hash, expectedHmac) + assertThat(hash).isEqualTo(expectedHmac) } @Test fun testPlainPasswordCheck() { - Assertions.assertTrue(cryptoUtil.checkPassword("same", "same")) - Assertions.assertFalse(cryptoUtil.checkPassword("same", "other")) + assertThat(cryptoUtil.checkPassword("same", "same")).isTrue() + assertThat(cryptoUtil.checkPassword("same", "other")).isFalse() } @Test fun testHashedPasswordCheck() { - Assertions.assertTrue(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("givenSecret"))) - Assertions.assertFalse(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("otherSecret"))) + assertThat(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("givenSecret"))).isTrue() + assertThat(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("otherSecret"))).isFalse() - Assertions.assertTrue( + assertThat( cryptoUtil.checkPassword( "givenHashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1" ) - ) - Assertions.assertFalse( + ).isTrue() + assertThat( cryptoUtil.checkPassword( "givenMashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1" ) - ) - Assertions.assertFalse( + ).isFalse() + assertThat( cryptoUtil.checkPassword( "givenHashToCheck", "hmac:0fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1" ) - ) - Assertions.assertFalse( + ).isFalse() + assertThat( cryptoUtil.checkPassword( "givenHashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:b0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1" ) - ) + ).isFalse() } } From 107f6d05dd17ceaff85e4a90f922a4a65e37c041 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 22:55:46 -0700 Subject: [PATCH 12/16] Rewrites DateUtilTest with matchers Issue #2745 --- .../nightscout/core/utils/DateUtilTest.kt | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/utils/DateUtilTest.kt b/core/main/src/test/java/info/nightscout/core/utils/DateUtilTest.kt index fb3258894e..29c75bff10 100644 --- a/core/main/src/test/java/info/nightscout/core/utils/DateUtilTest.kt +++ b/core/main/src/test/java/info/nightscout/core/utils/DateUtilTest.kt @@ -7,7 +7,6 @@ import info.nightscout.shared.utils.DateUtilImpl import info.nightscout.shared.utils.T import info.nightscout.sharedtests.TestBase import org.junit.jupiter.api.AfterAll -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import org.mockito.Mock @@ -41,25 +40,25 @@ class DateUtilTest : TestBase() { @Test fun fromISODateStringTest() { - Assertions.assertEquals(1511124634417L, DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34.417+0200")) - Assertions.assertEquals(1511124634000L, DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34+0200")) - Assertions.assertEquals(1512317365000L, DateUtilImpl(context).fromISODateString("2017-12-03T16:09:25.000Z")) - Assertions.assertEquals(1513902750000L, DateUtilImpl(context).fromISODateString("2017-12-22T00:32:30Z")) + assertThat(DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34.417+0200")).isEqualTo(1511124634417L) + assertThat(DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34+0200")).isEqualTo(1511124634000L) + assertThat(DateUtilImpl(context).fromISODateString("2017-12-03T16:09:25.000Z")).isEqualTo(1512317365000L) + assertThat(DateUtilImpl(context).fromISODateString("2017-12-22T00:32:30Z")).isEqualTo(1513902750000L) } @Test fun toISOStringTest() { - Assertions.assertEquals("2017-12-22T00:32:30.000Z", DateUtilImpl(context).toISOString(1513902750000L)) + assertThat(DateUtilImpl(context).toISOString(1513902750000L)).isEqualTo("2017-12-22T00:32:30.000Z") } @Test fun secondsOfTheDayToMillisecondsTest() { - Assertions.assertTrue(Date(DateUtilImpl(context).secondsOfTheDayToMilliseconds((T.hours(1).secs() + T.mins(1).secs() + 1).toInt())).toString().contains("01:01:00")) + assertThat(Date(DateUtilImpl(context).secondsOfTheDayToMilliseconds((T.hours(1).secs() + T.mins(1).secs() + 1).toInt())).toString()).contains("01:01:00") } @Test fun toSecondsTest() { - Assertions.assertEquals(3600, DateUtilImpl(context).toSeconds("01:00").toLong()) - Assertions.assertEquals(3600, DateUtilImpl(context).toSeconds("01:00 a.m.").toLong()) - Assertions.assertEquals(3600, DateUtilImpl(context).toSeconds("01:00 AM").toLong()) + assertThat(DateUtilImpl(context).toSeconds("01:00").toLong()).isEqualTo(3600) + assertThat(DateUtilImpl(context).toSeconds("01:00 a.m.").toLong()).isEqualTo(3600) + assertThat(DateUtilImpl(context).toSeconds("01:00 AM").toLong()).isEqualTo(3600) } @Test fun dateStringTest() { @@ -67,7 +66,7 @@ class DateUtilTest : TestBase() { } @Test fun timeStringTest() { - Assertions.assertTrue(DateUtilImpl(context).timeString(1513902750000L).contains("32")) + assertThat(DateUtilImpl(context).timeString(1513902750000L)).contains("32") } @Test fun dateAndTimeStringTest() { @@ -85,11 +84,11 @@ class DateUtilTest : TestBase() { /* @Test public void timeStringFromSecondsTest() { - Assertions.assertEquals("1:00 AM", DateUtil.timeStringFromSeconds((int) T.hours(1).secs())); + assertThat(DateUtil.timeStringFromSeconds((int) T.hours(1).secs()));.isEqualTo("1:00 AM") } */ @Test fun timeFrameStringTest() { `when`(rh.gs(info.nightscout.interfaces.R.string.shorthour)).thenReturn("h") - Assertions.assertEquals("(1h 1')", DateUtilImpl(context).timeFrameString(T.hours(1).msecs() + T.mins(1).msecs(), rh)) + assertThat(DateUtilImpl(context).timeFrameString(T.hours(1).msecs() + T.mins(1).msecs(), rh)).isEqualTo("(1h 1')") } } From e793620b6fa01f2b7ca48349d2f8273d8e4fd821 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 23:03:09 -0700 Subject: [PATCH 13/16] Rewrites JsonHelperTest with matchers Issue #2745 --- .../nightscout/core/utils/JsonHelperTest.kt | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/utils/JsonHelperTest.kt b/core/main/src/test/java/info/nightscout/core/utils/JsonHelperTest.kt index 2b0c1e686f..cd99713311 100644 --- a/core/main/src/test/java/info/nightscout/core/utils/JsonHelperTest.kt +++ b/core/main/src/test/java/info/nightscout/core/utils/JsonHelperTest.kt @@ -1,7 +1,7 @@ package info.nightscout.core.utils +import com.google.common.truth.Truth.assertThat import org.json.JSONObject -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test @Suppress("SpellCheckingInspection") @@ -13,67 +13,67 @@ class JsonHelperTest { fun safeGetObjectTest() { val json = JSONObject(jsonString) val o = Any() - Assertions.assertEquals(o, JsonHelper.safeGetObject(null, "x", o)) - Assertions.assertEquals(o, JsonHelper.safeGetObject(json, "x", o)) - Assertions.assertNotEquals(o, JsonHelper.safeGetObject(json, "d", o)) + assertThat(JsonHelper.safeGetObject(null, "x", o)).isEqualTo(o) + assertThat(JsonHelper.safeGetObject(json, "x", o)).isEqualTo(o) + assertThat(JsonHelper.safeGetObject(json, "d", o)).isNotEqualTo(o) } @Test fun safeGetJSONObjectTest() { val json = JSONObject(jsonString) val o = JSONObject() - Assertions.assertEquals(o, JsonHelper.safeGetJSONObject(null, "x", o)) - Assertions.assertTrue(JsonHelper.safeGetJSONObject(json, "j", o)!!.has("a")) - Assertions.assertEquals(o, JsonHelper.safeGetJSONObject(json, "d", o)) + assertThat(JsonHelper.safeGetJSONObject(null, "x", o)).isEqualTo(o) + assertThat(JsonHelper.safeGetJSONObject(json, "j", o)!!.has("a")).isTrue() + assertThat(JsonHelper.safeGetJSONObject(json, "d", o)).isEqualTo(o) } @Test fun safeGetStringTest() { val json = JSONObject(jsonString) - Assertions.assertNull(JsonHelper.safeGetString(null, "s")) - Assertions.assertNull(JsonHelper.safeGetString(json, "notexisting")) - Assertions.assertEquals("5", JsonHelper.safeGetString(json, "s")) - Assertions.assertEquals("default", JsonHelper.safeGetString(null, "notexisting", "default")) - Assertions.assertEquals("default", JsonHelper.safeGetString(json, "notexisting", "default")) - Assertions.assertEquals("5", JsonHelper.safeGetString(json, "s", "default")) - Assertions.assertEquals("default", JsonHelper.safeGetStringAllowNull(null, "notexisting", "default")) - Assertions.assertEquals("default", JsonHelper.safeGetStringAllowNull(json, "notexisting", "default")) - Assertions.assertNull(JsonHelper.safeGetStringAllowNull(json, "notexisting", null)) - Assertions.assertEquals("5", JsonHelper.safeGetStringAllowNull(json, "s", "default")) + assertThat(JsonHelper.safeGetString(null, "s")).isNull() + assertThat(JsonHelper.safeGetString(json, "notexisting")).isNull() + assertThat(JsonHelper.safeGetString(json, "s")).isEqualTo("5") + assertThat(JsonHelper.safeGetString(null, "notexisting", "default")).isEqualTo("default") + assertThat(JsonHelper.safeGetString(json, "notexisting", "default")).isEqualTo("default") + assertThat(JsonHelper.safeGetString(json, "s", "default")).isEqualTo("5") + assertThat(JsonHelper.safeGetStringAllowNull(null, "notexisting", "default")).isEqualTo("default") + assertThat(JsonHelper.safeGetStringAllowNull(json, "notexisting", "default")).isEqualTo("default") + assertThat(JsonHelper.safeGetStringAllowNull(json, "notexisting", null)).isNull() + assertThat(JsonHelper.safeGetStringAllowNull(json, "s", "default")).isEqualTo("5") } @Test fun safeGetDoubleTest() { val json = JSONObject(jsonString) - Assertions.assertEquals(0.0, JsonHelper.safeGetDouble(json, "notexisting"), 0.0) - Assertions.assertEquals(0.0, JsonHelper.safeGetDouble(null, "notexisting"), 0.0) - Assertions.assertEquals(3.0, JsonHelper.safeGetDouble(json, "d"), 0.000001) - Assertions.assertEquals(6.0, JsonHelper.safeGetDouble(null, "notexisting", 6.0), 0.0) - Assertions.assertEquals(6.0, JsonHelper.safeGetDouble(json, "notexisting", 6.0), 0.0) - Assertions.assertEquals(3.0, JsonHelper.safeGetDouble(json, "d", 6.0), 0.0) + assertThat(JsonHelper.safeGetDouble(json, "notexisting")).isWithin(0.0).of(0.0) + assertThat(JsonHelper.safeGetDouble(null, "notexisting")).isWithin(0.0).of(0.0) + assertThat(JsonHelper.safeGetDouble(json, "d")).isWithin(0.000001).of(3.0) + assertThat(JsonHelper.safeGetDouble(null, "notexisting", 6.0)).isWithin(0.0).of(6.0) + assertThat(JsonHelper.safeGetDouble(json, "notexisting", 6.0)).isWithin(0.0).of(6.0) + assertThat(JsonHelper.safeGetDouble(json, "d", 6.0)).isWithin(0.0).of(3.0) } @Test fun safeGetLntTest() { val json = JSONObject(jsonString) - Assertions.assertEquals(0, JsonHelper.safeGetInt(null, "notexisting").toLong()) - Assertions.assertEquals(0, JsonHelper.safeGetInt(json, "notexisting").toLong()) - Assertions.assertEquals(4, JsonHelper.safeGetInt(json, "i").toLong()) + assertThat(JsonHelper.safeGetInt(null, "notexisting").toLong()).isEqualTo(0) + assertThat(JsonHelper.safeGetInt(json, "notexisting").toLong()).isEqualTo(0) + assertThat(JsonHelper.safeGetInt(json, "i").toLong()).isEqualTo(4) } @Test fun safeGetLongTest() { val json = JSONObject(jsonString) - Assertions.assertEquals(0, JsonHelper.safeGetInt(null, "notexisting").toLong()) - Assertions.assertEquals(0, JsonHelper.safeGetInt(json, "notexisting").toLong()) - Assertions.assertEquals(4, JsonHelper.safeGetInt(json, "i").toLong()) + assertThat(JsonHelper.safeGetInt(null, "notexisting").toLong()).isEqualTo(0) + assertThat(JsonHelper.safeGetInt(json, "notexisting").toLong()).isEqualTo(0) + assertThat(JsonHelper.safeGetInt(json, "i").toLong()).isEqualTo(4) } @Test fun safeGetBooleanTest() { val json = JSONObject(jsonString) - Assertions.assertFalse(JsonHelper.safeGetBoolean(null, "notexisting")) - Assertions.assertFalse(JsonHelper.safeGetBoolean(json, "notexisting")) - Assertions.assertTrue(JsonHelper.safeGetBoolean(json, "b")) + assertThat(JsonHelper.safeGetBoolean(null, "notexisting")).isFalse() + assertThat(JsonHelper.safeGetBoolean(json, "notexisting")).isFalse() + assertThat(JsonHelper.safeGetBoolean(json, "b")).isTrue() } -} \ No newline at end of file +} From 309f823cc49298625c187402ccb85680f2db4e3a Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 23:07:43 -0700 Subject: [PATCH 14/16] Rewrites RoundTest with matchers Issue #2745 --- .../info/nightscout/core/utils/RoundTest.kt | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/utils/RoundTest.kt b/core/main/src/test/java/info/nightscout/core/utils/RoundTest.kt index 0980add1fe..6d57c65c02 100644 --- a/core/main/src/test/java/info/nightscout/core/utils/RoundTest.kt +++ b/core/main/src/test/java/info/nightscout/core/utils/RoundTest.kt @@ -1,41 +1,41 @@ package info.nightscout.core.utils +import com.google.common.truth.Truth.assertThat import info.nightscout.interfaces.utils.Round -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test class RoundTest { @Test fun roundToTest() { - Assertions.assertEquals(0.55, Round.roundTo(0.54, 0.05), 0.00000000000000000001) - Assertions.assertEquals(-3.26, Round.roundTo(-3.2553715764602713, 0.01), 0.00000000000000000001) - Assertions.assertEquals(0.816, Round.roundTo(0.8156666666666667, 0.001), 0.00000000000000000001) - Assertions.assertEquals(0.235, Round.roundTo(0.235, 0.001), 0.00000000000000000001) - Assertions.assertEquals(0.3, Round.roundTo(0.3, 0.1), 0.00000000000000001) - Assertions.assertEquals(0.0017, Round.roundTo(0.0016960652144170627, 0.0001), 0.00000000000000000001) - Assertions.assertEquals(0.0078, Round.roundTo(0.007804436682291013, 0.0001), 0.00000000000000000001) - Assertions.assertEquals(0.6, Round.roundTo(0.6, 0.05), 0.00000000000000000001) - Assertions.assertEquals(1.0, Round.roundTo(1.49, 1.0), 0.00000000000000000001) - Assertions.assertEquals(0.0, Round.roundTo(0.0, 1.0), 0.00000000000000000001) + assertThat(Round.roundTo(0.54, 0.05)).isWithin(0.00000000000000000001).of(0.55) + assertThat(Round.roundTo(-3.2553715764602713, 0.01)).isWithin(0.00000000000000000001).of(-3.26) + assertThat(Round.roundTo(0.8156666666666667, 0.001)).isWithin(0.00000000000000000001).of(0.816) + assertThat(Round.roundTo(0.235, 0.001)).isWithin(0.00000000000000000001).of(0.235) + assertThat(Round.roundTo(0.3, 0.1)).isWithin(0.00000000000000001).of(0.3) + assertThat(Round.roundTo(0.0016960652144170627, 0.0001)).isWithin(0.00000000000000000001).of(0.0017) + assertThat(Round.roundTo(0.007804436682291013, 0.0001)).isWithin(0.00000000000000000001).of(0.0078) + assertThat(Round.roundTo(0.6, 0.05)).isWithin(0.00000000000000000001).of(0.6) + assertThat(Round.roundTo(1.49, 1.0)).isWithin(0.00000000000000000001).of(1.0) + assertThat(Round.roundTo(0.0, 1.0)).isWithin(0.00000000000000000001).of(0.0) } @Test fun floorToTest() { - Assertions.assertEquals(0.5, Round.floorTo(0.54, 0.05), 0.00000001) - Assertions.assertEquals(1.0, Round.floorTo(1.59, 1.0), 0.00000001) - Assertions.assertEquals(0.0, Round.floorTo(0.0, 1.0), 0.00000001) + assertThat(Round.floorTo(0.54, 0.05)).isWithin(0.00000001).of(0.5) + assertThat(Round.floorTo(1.59, 1.0)).isWithin(0.00000001).of(1.0) + assertThat(Round.floorTo(0.0, 1.0)).isWithin(0.00000001).of(0.0) } @Test fun ceilToTest() { - Assertions.assertEquals(0.6, Round.ceilTo(0.54, 0.1), 0.00000001) - Assertions.assertEquals(2.0, Round.ceilTo(1.49999, 1.0), 0.00000001) - Assertions.assertEquals(0.0, Round.ceilTo(0.0, 1.0), 0.00000001) + assertThat(Round.ceilTo(0.54, 0.1)).isWithin(0.00000001).of(0.6) + assertThat(Round.ceilTo(1.49999, 1.0)).isWithin(0.00000001).of(2.0) + assertThat(Round.ceilTo(0.0, 1.0)).isWithin(0.00000001).of(0.0) } @Test fun isSameTest() { - Assertions.assertTrue(Round.isSame(0.54, 0.54)) + assertThat(Round.isSame(0.54, 0.54)).isTrue() } -} \ No newline at end of file +} From a49a10447539833df497368d8b39ac44092be5db Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 23:10:34 -0700 Subject: [PATCH 15/16] Rewrites StringUtilsTest with matchers Issue #2745 --- .../nightscout/core/utils/StringUtilsTest.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/utils/StringUtilsTest.kt b/core/main/src/test/java/info/nightscout/core/utils/StringUtilsTest.kt index f64748fb1d..3b0f005ddc 100644 --- a/core/main/src/test/java/info/nightscout/core/utils/StringUtilsTest.kt +++ b/core/main/src/test/java/info/nightscout/core/utils/StringUtilsTest.kt @@ -1,19 +1,19 @@ package info.nightscout.core.utils +import com.google.common.truth.Truth.assertThat import info.nightscout.core.utils.receivers.StringUtils -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test class StringUtilsTest { @Test fun removeSurroundingQuotesTest() { var compareString = "test" - Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString)) - Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")) - Assertions.assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString)) - compareString = "te\"st" - Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString)) - Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")) - Assertions.assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString)) + assertThat(StringUtils.removeSurroundingQuotes(compareString)).isEqualTo(compareString) + assertThat(StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")).isEqualTo(compareString) + assertThat(StringUtils.removeSurroundingQuotes("\"" + compareString)).isEqualTo("\"" + compareString) + compareString = """te"st""" + assertThat(StringUtils.removeSurroundingQuotes(compareString)).isEqualTo(compareString) + assertThat(StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")).isEqualTo(compareString) + assertThat(StringUtils.removeSurroundingQuotes("\"" + compareString)).isEqualTo("\"" + compareString) } -} \ No newline at end of file +} From 78ed9bc484a22f85f4d6f15d4e8563b3090ecffa Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 23:17:03 -0700 Subject: [PATCH 16/16] Rewrites QuickWizardTest with matchers Issue #2745 --- .../nightscout/core/wizard/QuickWizardTest.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/wizard/QuickWizardTest.kt b/core/main/src/test/java/info/nightscout/core/wizard/QuickWizardTest.kt index a3129b2df0..d89c0dfcd6 100644 --- a/core/main/src/test/java/info/nightscout/core/wizard/QuickWizardTest.kt +++ b/core/main/src/test/java/info/nightscout/core/wizard/QuickWizardTest.kt @@ -1,5 +1,6 @@ package info.nightscout.core.wizard +import com.google.common.truth.Truth.assertThat import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.interfaces.aps.Loop @@ -7,7 +8,6 @@ import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.shared.sharedPreferences.SP import info.nightscout.sharedtests.TestBase import org.json.JSONArray -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -55,46 +55,46 @@ class QuickWizardTest : TestBase() { @Test fun setDataTest() { quickWizard.setData(array) - Assertions.assertEquals(2, quickWizard.size()) + assertThat(quickWizard.size()).isEqualTo(2) } @Test fun test() { quickWizard.setData(array) - Assertions.assertEquals("Lunch", quickWizard[1].buttonText()) + assertThat(quickWizard[1].buttonText()).isEqualTo("Lunch") } @Test fun active() { quickWizard.setData(array) val e: QuickWizardEntry = quickWizard.getActive()!! - Assertions.assertEquals(36.0, e.carbs().toDouble(), 0.01) + assertThat(e.carbs().toDouble()).isWithin(0.01).of(36.0) quickWizard.remove(0) quickWizard.remove(0) - Assertions.assertNull(quickWizard.getActive()) + assertThat(quickWizard.getActive()).isNull() } @Test fun newEmptyItemTest() { - Assertions.assertNotNull(quickWizard.newEmptyItem()) + assertThat(quickWizard.newEmptyItem()).isNotNull() } @Test fun addOrUpdate() { quickWizard.setData(array) - Assertions.assertEquals(2, quickWizard.size()) + assertThat(quickWizard.size()).isEqualTo(2) quickWizard.addOrUpdate(quickWizard.newEmptyItem()) - Assertions.assertEquals(3, quickWizard.size()) + assertThat(quickWizard.size()).isEqualTo(3) val q: QuickWizardEntry = quickWizard.newEmptyItem() q.position = 0 quickWizard.addOrUpdate(q) - Assertions.assertEquals(3, quickWizard.size()) + assertThat(quickWizard.size()).isEqualTo(3) } @Test fun remove() { quickWizard.setData(array) quickWizard.remove(0) - Assertions.assertEquals(1, quickWizard.size()) + assertThat(quickWizard.size()).isEqualTo(1) } -} \ No newline at end of file +}