From de404686633473de997ce50981fc2c5922bd3094 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 4 Oct 2023 22:37:36 -0700 Subject: [PATCH] Rewrites TriggerProfilePercentTest with matchers Issue #2745 --- .../triggers/TriggerProfilePercentTest.kt | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerProfilePercentTest.kt b/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerProfilePercentTest.kt index fdaba24f13..9becc46ad7 100644 --- a/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerProfilePercentTest.kt +++ b/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerProfilePercentTest.kt @@ -4,10 +4,10 @@ import app.aaps.plugins.automation.R import app.aaps.plugins.automation.elements.Comparator import com.google.common.truth.Truth.assertThat 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.Mockito.`when` +import org.skyscreamer.jsonassert.JSONAssert class TriggerProfilePercentTest : TriggerTestBase() { @@ -17,43 +17,43 @@ class TriggerProfilePercentTest : TriggerTestBase() { @Test fun shouldRunTest() { var t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(101.0).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerProfilePercent(injector).setValue(90.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerProfilePercent(injector).setValue(101.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerProfilePercent(injector).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() t = TriggerProfilePercent(injector).setValue(110.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() t = TriggerProfilePercent(injector).setValue(90.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() } @Test fun copyConstructorTest() { val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) val t1 = t.duplicate() as TriggerProfilePercent - Assertions.assertEquals(213.0, t1.pct.value, 0.01) - Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value) + assertThat( t1.pct.value).isWithin(0.01).of(213.0) + assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER) } private val bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"percentage\":110},\"type\":\"TriggerProfilePercent\"}" @Test fun toJSONTest() { val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(110.0).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertEquals(bgJson, t.toJSON()) + JSONAssert.assertEquals(bgJson, t.toJSON(), true) } @Test fun fromJSONTest() { val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(120.0).comparator(Comparator.Compare.IS_EQUAL) val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerProfilePercent - Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value) - Assertions.assertEquals(120.0, t2.pct.value, 0.01) + assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL) + assertThat(t2.pct.value).isWithin(0.01).of(120.0) } @Test fun iconTest() { @@ -61,6 +61,6 @@ class TriggerProfilePercentTest : TriggerTestBase() { } @Test fun friendlyNameTest() { - Assertions.assertEquals(R.string.profilepercentage, TriggerProfilePercent(injector).friendlyName()) // not mocked + assertThat(TriggerProfilePercent(injector).friendlyName()).isEqualTo(R.string.profilepercentage) // not mocked } -} \ No newline at end of file +}