From 3aafe1212a1037a2bd0e3edd89741df8fada87ee Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 4 Oct 2023 22:37:47 -0700 Subject: [PATCH] Rewrites TriggerBolusAgoTest with matchers Issue #2745 --- .../triggers/TriggerBolusAgoTest.kt | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerBolusAgoTest.kt b/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerBolusAgoTest.kt index 8f53218183..4e5cf8e277 100644 --- a/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerBolusAgoTest.kt +++ b/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerBolusAgoTest.kt @@ -7,9 +7,9 @@ import com.google.common.truth.Truth.assertThat import io.reactivex.rxjava3.core.Single import org.json.JSONException import org.json.JSONObject -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import org.mockito.Mockito.`when` +import org.skyscreamer.jsonassert.JSONAssert class TriggerBolusAgoTest : TriggerTestBase() { @@ -29,26 +29,26 @@ class TriggerBolusAgoTest : TriggerTestBase() { ) `when`(dateUtil.now()).thenReturn(now + 10 * 60 * 1000) // set current time to now + 10 min var t = TriggerBolusAgo(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertEquals(110, t.minutesAgo.value) - Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.minutesAgo.value).isEqualTo(110) + assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL) + assertThat(t.shouldRun()).isFalse() t = TriggerBolusAgo(injector).setValue(10).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertEquals(10, t.minutesAgo.value) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.minutesAgo.value).isEqualTo(10) + assertThat(t.shouldRun()).isTrue() t = TriggerBolusAgo(injector).setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerBolusAgo(injector).setValue(310).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerBolusAgo(injector).setValue(420).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() t = TriggerBolusAgo(injector).setValue(2).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() // Set last bolus time to 0 `when`(repository.getLastBolusRecordOfTypeWrapped(Bolus.Type.NORMAL)).thenReturn( Single.just( @@ -62,30 +62,30 @@ class TriggerBolusAgoTest : TriggerTestBase() { ) ) t = TriggerBolusAgo(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() } @Test fun copyConstructorTest() { val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) val t1 = t.duplicate() as TriggerBolusAgo - Assertions.assertEquals(213, t1.minutesAgo.value) - Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value) + assertThat(t1.minutesAgo.value).isEqualTo(213) + assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER) } private var lbJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"minutesAgo\":410},\"type\":\"TriggerBolusAgo\"}" @Test fun toJSONTest() { val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertEquals(lbJson, t.toJSON()) + JSONAssert.assertEquals(lbJson, t.toJSON(), true) } @Test @Throws(JSONException::class) fun fromJSONTest() { val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL) val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerBolusAgo - Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value) - Assertions.assertEquals(410, t2.minutesAgo.value) + assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL) + assertThat(t2.minutesAgo.value).isEqualTo(410) } @Test fun iconTest() { assertThat(TriggerBolusAgo(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_bolus) } -} \ No newline at end of file +}