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 com.google.common.truth.Truth.assertThat
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.skyscreamer.jsonassert.JSONAssert
class TriggerTempTargetTest : TriggerTestBase() {
@ -13,36 +13,36 @@ class TriggerTempTargetTest : TriggerTestBase() {
@Test fun shouldRunTest() {
`when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(null)
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)
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))
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
}
*/
@Test fun copyConstructorTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
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\"}"
@Test fun toJSONTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
Assertions.assertEquals(ttJson, t.toJSON())
JSONAssert.assertEquals(ttJson, t.toJSON(), true)
}
@Test
fun fromJSONTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
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() {
assertThat(TriggerTempTarget(injector).icon().get()).isEqualTo(R.drawable.ic_keyboard_tab)
}
}
}