Rewrites TriggerTimeTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-04 22:38:36 -07:00
parent 60c4d70a3f
commit 3c85552413

View file

@ -4,9 +4,9 @@ import app.aaps.core.interfaces.utils.T
import app.aaps.plugins.automation.R import app.aaps.plugins.automation.R
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.mockito.Mockito import org.mockito.Mockito
import org.skyscreamer.jsonassert.JSONAssert
class TriggerTimeTest : TriggerTestBase() { class TriggerTimeTest : TriggerTestBase() {
@ -19,11 +19,11 @@ class TriggerTimeTest : TriggerTestBase() {
// scheduled 1 min before // scheduled 1 min before
var t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs()) var t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs())
Assertions.assertTrue(t.shouldRun()) assertThat(t.shouldRun()).isTrue()
// scheduled 1 min in the future // scheduled 1 min in the future
t = TriggerTime(injector).runAt(now + T.mins(1).msecs()) t = TriggerTime(injector).runAt(now + T.mins(1).msecs())
Assertions.assertFalse(t.shouldRun()) assertThat(t.shouldRun()).isFalse()
} }
private var timeJson = "{\"data\":{\"runAt\":1656358762000},\"type\":\"TriggerTime\"}" private var timeJson = "{\"data\":{\"runAt\":1656358762000},\"type\":\"TriggerTime\"}"
@ -31,14 +31,14 @@ class TriggerTimeTest : TriggerTestBase() {
@Test @Test
fun toJSONTest() { fun toJSONTest() {
val t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs()) val t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs())
Assertions.assertEquals(timeJson, t.toJSON()) JSONAssert.assertEquals(timeJson, t.toJSON(), true)
} }
@Test @Test
fun fromJSONTest() { fun fromJSONTest() {
val t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs()) val t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs())
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTime val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTime
Assertions.assertEquals(now - T.mins(1).msecs(), t2.time.value) assertThat(t2.time.value).isEqualTo(now - T.mins(1).msecs())
} }
@Test @Test
@ -46,22 +46,22 @@ class TriggerTimeTest : TriggerTestBase() {
val t = TriggerTime(injector) val t = TriggerTime(injector)
t.runAt(now) t.runAt(now)
val t1 = t.duplicate() as TriggerTime val t1 = t.duplicate() as TriggerTime
Assertions.assertEquals(now, t1.time.value) assertThat(t1.time.value).isEqualTo(now)
} }
@Test @Test
fun friendlyNameTest() { fun friendlyNameTest() {
Assertions.assertEquals(app.aaps.core.ui.R.string.time, TriggerTime(injector).friendlyName()) assertThat(TriggerTime(injector).friendlyName()).isEqualTo(app.aaps.core.ui.R.string.time)
} }
@Test @Test
fun friendlyDescriptionTest() { fun friendlyDescriptionTest() {
Mockito.`when`(rh.gs(R.string.atspecifiedtime)).thenReturn("At %1\$s") Mockito.`when`(rh.gs(R.string.atspecifiedtime)).thenReturn("At %1\$s")
Assertions.assertTrue(TriggerTime(injector).friendlyDescription().startsWith("At ")) assertThat(TriggerTime(injector).friendlyDescription()).startsWith("At ")
} }
@Test @Test
fun iconTest() { fun iconTest() {
assertThat(TriggerTime(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_access_alarm_24dp) assertThat(TriggerTime(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_access_alarm_24dp)
} }
} }