parent
b2fe352555
commit
60c4d70a3f
|
@ -4,10 +4,10 @@ import app.aaps.core.interfaces.utils.MidnightTime
|
|||
import app.aaps.plugins.automation.R
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
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 TriggerTimeRangeTest : TriggerTestBase() {
|
||||
|
||||
|
@ -25,47 +25,47 @@ class TriggerTimeRangeTest : TriggerTestBase() {
|
|||
fun shouldRunTest() {
|
||||
// range starts 1 min in the future
|
||||
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
|
||||
t = TriggerTimeRange(injector).period((now - 30).toInt(), (now + 30).toInt())
|
||||
Assertions.assertEquals(true, t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
|
||||
// Period is all day long
|
||||
t = TriggerTimeRange(injector).period(1, 1440)
|
||||
Assertions.assertEquals(true, t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toJSONTest() {
|
||||
val t: TriggerTimeRange = TriggerTimeRange(injector).period((now - 1).toInt(), (now + 30).toInt())
|
||||
Assertions.assertEquals(timeJson, t.toJSON())
|
||||
JSONAssert.assertEquals(timeJson, t.toJSON(), true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromJSONTest() {
|
||||
val t: TriggerTimeRange = TriggerTimeRange(injector).period(120, 180)
|
||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTimeRange
|
||||
Assertions.assertEquals((now - 1).toInt(), t2.period(753, 360).range.start)
|
||||
Assertions.assertEquals(360, t2.period(753, 360).range.end)
|
||||
assertThat(t2.period(753, 360).range.start).isEqualTo((now - 1).toInt())
|
||||
assertThat(t2.period(753, 360).range.end).isEqualTo(360)
|
||||
}
|
||||
|
||||
@Test fun copyConstructorTest() {
|
||||
val t = TriggerTimeRange(injector)
|
||||
t.period(now.toInt(), (now + 30).toInt())
|
||||
val t1 = t.duplicate() as TriggerTimeRange
|
||||
Assertions.assertEquals(now.toInt(), t1.range.start)
|
||||
assertThat(t1.range.start).isEqualTo(now.toInt())
|
||||
}
|
||||
|
||||
@Test fun friendlyNameTest() {
|
||||
Assertions.assertEquals(R.string.time_range, TriggerTimeRange(injector).friendlyName())
|
||||
assertThat(TriggerTimeRange(injector).friendlyName()).isEqualTo(R.string.time_range)
|
||||
}
|
||||
|
||||
@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() {
|
||||
assertThat(TriggerTimeRange(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_access_alarm_24dp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue