parent
c7c858a46b
commit
a801306d40
1 changed files with 17 additions and 17 deletions
|
@ -4,9 +4,9 @@ import app.aaps.plugins.automation.R
|
||||||
import app.aaps.plugins.automation.elements.Comparator
|
import app.aaps.plugins.automation.elements.Comparator
|
||||||
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.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class TriggerPumpLastConnectionTest : TriggerTestBase() {
|
class TriggerPumpLastConnectionTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -14,42 +14,42 @@ class TriggerPumpLastConnectionTest : TriggerTestBase() {
|
||||||
fun shouldRunTest() {
|
fun shouldRunTest() {
|
||||||
// System.currentTimeMillis() is always 0
|
// System.currentTimeMillis() is always 0
|
||||||
// and so is every last connection time
|
// and so is every last connection time
|
||||||
Assertions.assertEquals(0L, testPumpPlugin.lastDataTime())
|
assertThat(testPumpPlugin.lastDataTime()).isEqualTo(0L)
|
||||||
`when`(dateUtil.now()).thenReturn(now + 10 * 60 * 1000) // set current time to now + 10 min
|
`when`(dateUtil.now()).thenReturn(now + 10 * 60 * 1000) // set current time to now + 10 min
|
||||||
var t = TriggerPumpLastConnection(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL)
|
var t = TriggerPumpLastConnection(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(110, t.minutesAgo.value)
|
assertThat(t.minutesAgo.value).isEqualTo(110)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerPumpLastConnection(injector).setValue(10).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerPumpLastConnection(injector).setValue(10).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(10, t.minutesAgo.value)
|
assertThat(t.minutesAgo.value).isEqualTo(10)
|
||||||
Assertions.assertFalse(t.shouldRun()) // 0 == 10 -> FALSE
|
assertThat(t.shouldRun()).isFalse() // 0 == 10 -> FALSE
|
||||||
t = TriggerPumpLastConnection(injector).setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerPumpLastConnection(injector).setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun()) // 5 => 0 -> TRUE
|
assertThat(t.shouldRun()).isTrue() // 5 => 0 -> TRUE
|
||||||
t = TriggerPumpLastConnection(injector).setValue(310).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerPumpLastConnection(injector).setValue(310).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertFalse(t.shouldRun()) // 310 <= 0 -> FALSE
|
assertThat(t.shouldRun()).isFalse() // 310 <= 0 -> FALSE
|
||||||
t = TriggerPumpLastConnection(injector).setValue(420).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerPumpLastConnection(injector).setValue(420).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun()) // 420 == 0 -> FALSE
|
assertThat(t.shouldRun()).isFalse() // 420 == 0 -> FALSE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun copyConstructorTest() {
|
@Test fun copyConstructorTest() {
|
||||||
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
val t1 = t.duplicate() as TriggerPumpLastConnection
|
val t1 = t.duplicate() as TriggerPumpLastConnection
|
||||||
Assertions.assertEquals(213, t1.minutesAgo.value)
|
assertThat(t1.minutesAgo.value).isEqualTo(213)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var lbJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"minutesAgo\":410},\"type\":\"TriggerPumpLastConnection\"}"
|
private var lbJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"minutesAgo\":410},\"type\":\"TriggerPumpLastConnection\"}"
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(lbJson, t.toJSON())
|
JSONAssert.assertEquals(lbJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun fromJSONTest() {
|
fun fromJSONTest() {
|
||||||
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerPumpLastConnection
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerPumpLastConnection
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(410, t2.minutesAgo.value)
|
assertThat(t2.minutesAgo.value).isEqualTo(410)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
|
@ -57,6 +57,6 @@ class TriggerPumpLastConnectionTest : TriggerTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(R.string.automation_trigger_pump_last_connection_label, TriggerPumpLastConnection(injector).friendlyName())
|
assertThat(TriggerPumpLastConnection(injector).friendlyName()).isEqualTo(R.string.automation_trigger_pump_last_connection_label)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue