Rewrites TriggerTempTargetTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-04 22:38:20 -07:00
parent a801306d40
commit b2fe352555

View file

@ -4,8 +4,8 @@ import app.aaps.plugins.automation.R
import app.aaps.plugins.automation.elements.ComparatorExists import app.aaps.plugins.automation.elements.ComparatorExists
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import org.json.JSONObject import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.skyscreamer.jsonassert.JSONAssert
class TriggerTempTargetTest : TriggerTestBase() { class TriggerTempTargetTest : TriggerTestBase() {
@ -13,36 +13,36 @@ class TriggerTempTargetTest : TriggerTestBase() {
@Test fun shouldRunTest() { @Test fun shouldRunTest() {
`when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(null) `when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(null)
var t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS) var t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
Assertions.assertFalse(t.shouldRun()) assertThat(t.shouldRun()).isFalse()
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
Assertions.assertTrue(t.shouldRun()) assertThat(t.shouldRun()).isTrue()
`when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(TemporaryTarget(duration = 0, highTarget = 0.0, lowTarget = 0.0, reason = TemporaryTarget.Reason.CUSTOM, timestamp = 0)) `when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(TemporaryTarget(duration = 0, highTarget = 0.0, lowTarget = 0.0, reason = TemporaryTarget.Reason.CUSTOM, timestamp = 0))
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
Assertions.assertFalse(t.shouldRun()) assertThat(t.shouldRun()).isFalse()
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS) t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
Assertions.assertTrue(t.shouldRun()) assertThat(t.shouldRun()).isTrue()
} }
*/ */
@Test fun copyConstructorTest() { @Test fun copyConstructorTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
val t1 = t.duplicate() as TriggerTempTarget val t1 = t.duplicate() as TriggerTempTarget
Assertions.assertEquals(ComparatorExists.Compare.NOT_EXISTS, t1.comparator.value) assertThat(t1.comparator.value).isEqualTo(ComparatorExists.Compare.NOT_EXISTS)
} }
private var ttJson = "{\"data\":{\"comparator\":\"EXISTS\"},\"type\":\"TriggerTempTarget\"}" private var ttJson = "{\"data\":{\"comparator\":\"EXISTS\"},\"type\":\"TriggerTempTarget\"}"
@Test fun toJSONTest() { @Test fun toJSONTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS) val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
Assertions.assertEquals(ttJson, t.toJSON()) JSONAssert.assertEquals(ttJson, t.toJSON(), true)
} }
@Test @Test
fun fromJSONTest() { fun fromJSONTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTarget val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTarget
Assertions.assertEquals(ComparatorExists.Compare.NOT_EXISTS, t2.comparator.value) assertThat(t2.comparator.value).isEqualTo(ComparatorExists.Compare.NOT_EXISTS)
} }
@Test fun iconTest() { @Test fun iconTest() {
assertThat(TriggerTempTarget(injector).icon().get()).isEqualTo(R.drawable.ic_keyboard_tab) assertThat(TriggerTempTarget(injector).icon().get()).isEqualTo(R.drawable.ic_keyboard_tab)
} }
} }