Rewrites TriggerTimeRangeTest with matchers

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

View file

@ -4,10 +4,10 @@ import app.aaps.core.interfaces.utils.MidnightTime
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.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class TriggerTimeRangeTest : TriggerTestBase() { class TriggerTimeRangeTest : TriggerTestBase() {
@ -25,47 +25,47 @@ class TriggerTimeRangeTest : TriggerTestBase() {
fun shouldRunTest() { fun shouldRunTest() {
// range starts 1 min in the future // range starts 1 min in the future
var t: TriggerTimeRange = TriggerTimeRange(injector).period((now + 1).toInt(), (now + 30).toInt()) var t: TriggerTimeRange = TriggerTimeRange(injector).period((now + 1).toInt(), (now + 30).toInt())
Assertions.assertEquals(false, t.shouldRun()) assertThat(t.shouldRun()).isFalse()
// range starts 30 min back // range starts 30 min back
t = TriggerTimeRange(injector).period((now - 30).toInt(), (now + 30).toInt()) t = TriggerTimeRange(injector).period((now - 30).toInt(), (now + 30).toInt())
Assertions.assertEquals(true, t.shouldRun()) assertThat(t.shouldRun()).isTrue()
// Period is all day long // Period is all day long
t = TriggerTimeRange(injector).period(1, 1440) t = TriggerTimeRange(injector).period(1, 1440)
Assertions.assertEquals(true, t.shouldRun()) assertThat(t.shouldRun()).isTrue()
} }
@Test @Test
fun toJSONTest() { fun toJSONTest() {
val t: TriggerTimeRange = TriggerTimeRange(injector).period((now - 1).toInt(), (now + 30).toInt()) val t: TriggerTimeRange = TriggerTimeRange(injector).period((now - 1).toInt(), (now + 30).toInt())
Assertions.assertEquals(timeJson, t.toJSON()) JSONAssert.assertEquals(timeJson, t.toJSON(), true)
} }
@Test @Test
fun fromJSONTest() { fun fromJSONTest() {
val t: TriggerTimeRange = TriggerTimeRange(injector).period(120, 180) val t: TriggerTimeRange = TriggerTimeRange(injector).period(120, 180)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTimeRange val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTimeRange
Assertions.assertEquals((now - 1).toInt(), t2.period(753, 360).range.start) assertThat(t2.period(753, 360).range.start).isEqualTo((now - 1).toInt())
Assertions.assertEquals(360, t2.period(753, 360).range.end) assertThat(t2.period(753, 360).range.end).isEqualTo(360)
} }
@Test fun copyConstructorTest() { @Test fun copyConstructorTest() {
val t = TriggerTimeRange(injector) val t = TriggerTimeRange(injector)
t.period(now.toInt(), (now + 30).toInt()) t.period(now.toInt(), (now + 30).toInt())
val t1 = t.duplicate() as TriggerTimeRange val t1 = t.duplicate() as TriggerTimeRange
Assertions.assertEquals(now.toInt(), t1.range.start) assertThat(t1.range.start).isEqualTo(now.toInt())
} }
@Test fun friendlyNameTest() { @Test fun friendlyNameTest() {
Assertions.assertEquals(R.string.time_range, TriggerTimeRange(injector).friendlyName()) assertThat(TriggerTimeRange(injector).friendlyName()).isEqualTo(R.string.time_range)
} }
@Test fun friendlyDescriptionTest() { @Test fun friendlyDescriptionTest() {
Assertions.assertEquals("Time is between 12:34PM and 12:34PM", TriggerTimeRange(injector).friendlyDescription()) assertThat(TriggerTimeRange(injector).friendlyDescription()).isEqualTo("Time is between 12:34PM and 12:34PM")
} }
@Test fun iconTest() { @Test fun iconTest() {
assertThat(TriggerTimeRange(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_access_alarm_24dp) assertThat(TriggerTimeRange(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_access_alarm_24dp)
} }
} }