From 8966f0b8cc8a467b8acff083bbba628ad8490e3c Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 4 Oct 2023 21:59:58 -0700 Subject: [PATCH] Rewrites TriggerTempTargetValueTest with matchers Issue #2745 --- .../triggers/TriggerTempTargetValueTest.kt | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerTempTargetValueTest.kt b/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerTempTargetValueTest.kt index ad599d9f32..5aba9e5018 100644 --- a/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerTempTargetValueTest.kt +++ b/plugins/automation/src/test/kotlin/app/aaps/plugins/automation/triggers/TriggerTempTargetValueTest.kt @@ -8,10 +8,10 @@ import app.aaps.plugins.automation.elements.Comparator import com.google.common.truth.Truth.assertThat import io.reactivex.rxjava3.core.Single 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 TriggerTempTargetValueTest : TriggerTestBase() { @@ -36,37 +36,37 @@ class TriggerTempTargetValueTest : TriggerTestBase() { ) ) var t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) - Assertions.assertFalse(t.shouldRun()) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() + assertThat(t.shouldRun()).isFalse() t = TriggerTempTargetValue(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE) - Assertions.assertFalse(t.shouldRun()) + assertThat(t.shouldRun()).isFalse() `when`(repository.getTemporaryTargetActiveAt(dateUtil.now())).thenReturn(Single.just(ValueWrapper.Absent())) - Assertions.assertTrue(t.shouldRun()) + assertThat(t.shouldRun()).isTrue() } @Test fun copyConstructorTest() { val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) val t1 = t.duplicate() as TriggerTempTargetValue - Assertions.assertEquals(140.0, t1.ttValue.value, 0.01) - Assertions.assertEquals(GlucoseUnit.MGDL, t1.ttValue.units) - Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value) + assertThat(t1.ttValue.value).isWithin(0.01).of(140.0) + assertThat(t1.ttValue.units).isEqualTo(GlucoseUnit.MGDL) + assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER) } private var ttJson = "{\"data\":{\"tt\":7.7,\"comparator\":\"IS_EQUAL\",\"units\":\"mmol\"},\"type\":\"TriggerTempTargetValue\"}" @@ -74,16 +74,16 @@ class TriggerTempTargetValueTest : TriggerTestBase() { @Test fun toJSONTest() { val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL) - Assertions.assertEquals(ttJson, t.toJSON()) + JSONAssert.assertEquals(ttJson, t.toJSON(), true) } @Test fun fromJSONTest() { val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL) val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTargetValue - Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value) - Assertions.assertEquals(7.7, t2.ttValue.value, 0.01) - Assertions.assertEquals(GlucoseUnit.MMOL, t2.ttValue.units) + assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL) + assertThat(t2.ttValue.value).isWithin(0.01).of(7.7) + assertThat(t2.ttValue.units).isEqualTo(GlucoseUnit.MMOL) } @Test