Merge pull request #2869 from ryanhaining/assertthat_plugins_automation
Rewrites plugins/automation tests with matchers
This commit is contained in:
commit
a4ee36f0eb
49 changed files with 498 additions and 497 deletions
|
@ -10,12 +10,13 @@ import app.aaps.plugins.automation.triggers.TriggerConnector
|
||||||
import app.aaps.plugins.automation.triggers.TriggerConnectorTest
|
import app.aaps.plugins.automation.triggers.TriggerConnectorTest
|
||||||
import app.aaps.plugins.automation.triggers.TriggerDummy
|
import app.aaps.plugins.automation.triggers.TriggerDummy
|
||||||
import app.aaps.shared.tests.TestBase
|
import app.aaps.shared.tests.TestBase
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
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.Mock
|
import org.mockito.Mock
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class AutomationEventTest : TestBase() {
|
class AutomationEventTest : TestBase() {
|
||||||
|
|
||||||
|
@ -40,8 +41,7 @@ class AutomationEventTest : TestBase() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test fun testCloneEvent() {
|
||||||
fun testCloneEvent() {
|
|
||||||
// create test object
|
// create test object
|
||||||
val event = AutomationEventObject(injector)
|
val event = AutomationEventObject(injector)
|
||||||
event.title = "Test"
|
event.title = "Test"
|
||||||
|
@ -51,33 +51,32 @@ class AutomationEventTest : TestBase() {
|
||||||
// export to json
|
// export to json
|
||||||
val eventJsonExpected =
|
val eventJsonExpected =
|
||||||
"{\"userAction\":false,\"autoRemove\":false,\"readOnly\":false,\"trigger\":\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[\\\"{\\\\\\\"data\\\\\\\":{\\\\\\\"connectorType\\\\\\\":\\\\\\\"AND\\\\\\\",\\\\\\\"triggerList\\\\\\\":[]},\\\\\\\"type\\\\\\\":\\\\\\\"TriggerConnector\\\\\\\"}\\\"]},\\\"type\\\":\\\"TriggerConnector\\\"}\",\"title\":\"Test\",\"systemAction\":false,\"actions\":[\"{\\\"type\\\":\\\"ActionLoopEnable\\\"}\"],\"enabled\":true}"
|
"{\"userAction\":false,\"autoRemove\":false,\"readOnly\":false,\"trigger\":\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[\\\"{\\\\\\\"data\\\\\\\":{\\\\\\\"connectorType\\\\\\\":\\\\\\\"AND\\\\\\\",\\\\\\\"triggerList\\\\\\\":[]},\\\\\\\"type\\\\\\\":\\\\\\\"TriggerConnector\\\\\\\"}\\\"]},\\\"type\\\":\\\"TriggerConnector\\\"}\",\"title\":\"Test\",\"systemAction\":false,\"actions\":[\"{\\\"type\\\":\\\"ActionLoopEnable\\\"}\"],\"enabled\":true}"
|
||||||
Assertions.assertEquals(eventJsonExpected, event.toJSON())
|
JSONAssert.assertEquals(eventJsonExpected, event.toJSON(), true)
|
||||||
|
|
||||||
// clone
|
// clone
|
||||||
val clone = AutomationEventObject(injector).fromJSON(eventJsonExpected, 1)
|
val clone = AutomationEventObject(injector).fromJSON(eventJsonExpected, 1)
|
||||||
|
|
||||||
// check title
|
// check title
|
||||||
Assertions.assertEquals(event.title, clone.title)
|
assertThat(clone.title).isEqualTo(event.title)
|
||||||
|
|
||||||
// check trigger
|
// check trigger
|
||||||
Assertions.assertNotNull(clone.trigger)
|
assertThat(clone.trigger).isNotNull()
|
||||||
Assertions.assertFalse(event.trigger === clone.trigger) // not the same object reference
|
assertThat(event.trigger).isNotSameInstanceAs(clone.trigger)
|
||||||
Assertions.assertEquals(event.trigger.javaClass, clone.trigger.javaClass)
|
assertThat(event.trigger.javaClass).isNotInstanceOf(clone.trigger.javaClass)
|
||||||
Assertions.assertEquals(event.trigger.toJSON(), clone.trigger.toJSON())
|
JSONAssert.assertEquals(event.trigger.toJSON(), clone.trigger.toJSON(), true)
|
||||||
|
|
||||||
// check action
|
// check action
|
||||||
Assertions.assertEquals(1, clone.actions.size)
|
assertThat(clone.actions).hasSize(1)
|
||||||
Assertions.assertFalse(event.actions === clone.actions) // not the same object reference
|
assertThat(event.actions).isNotSameInstanceAs(clone.actions)
|
||||||
Assertions.assertEquals(clone.toJSON(), clone.toJSON())
|
JSONAssert.assertEquals(clone.toJSON(), clone.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test fun hasStopProcessing() {
|
||||||
fun hasStopProcessing() {
|
|
||||||
val event = AutomationEventObject(injector)
|
val event = AutomationEventObject(injector)
|
||||||
event.title = "Test"
|
event.title = "Test"
|
||||||
event.trigger = TriggerDummy(injector).instantiate(JSONObject(TriggerConnectorTest().oneItem)) as TriggerConnector
|
event.trigger = TriggerDummy(injector).instantiate(JSONObject(TriggerConnectorTest().oneItem)) as TriggerConnector
|
||||||
Assertions.assertFalse(event.hasStopProcessing())
|
assertThat(event.hasStopProcessing()).isFalse()
|
||||||
event.addAction(ActionStopProcessing(injector))
|
event.addAction(ActionStopProcessing(injector))
|
||||||
Assertions.assertTrue(event.hasStopProcessing())
|
assertThat(event.hasStopProcessing()).isTrue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@ import app.aaps.plugins.automation.triggers.Trigger
|
||||||
import app.aaps.plugins.automation.ui.TimerUtil
|
import app.aaps.plugins.automation.ui.TimerUtil
|
||||||
import app.aaps.shared.impl.utils.DateUtilImpl
|
import app.aaps.shared.impl.utils.DateUtilImpl
|
||||||
import app.aaps.shared.tests.TestBase
|
import app.aaps.shared.tests.TestBase
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
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.ArgumentMatchers.anyInt
|
import org.mockito.ArgumentMatchers.anyInt
|
||||||
|
@ -63,10 +63,10 @@ class BolusTimerImplTest : TestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun doTest() {
|
fun doTest() {
|
||||||
Assertions.assertEquals(0, automationPlugin.size())
|
assertThat(automationPlugin.size()).isEqualTo(0)
|
||||||
automationPlugin.scheduleAutomationEventBolusReminder()
|
automationPlugin.scheduleAutomationEventBolusReminder()
|
||||||
Assertions.assertEquals(1, automationPlugin.size())
|
assertThat(automationPlugin.size()).isEqualTo(1)
|
||||||
automationPlugin.removeAutomationEventBolusReminder()
|
automationPlugin.removeAutomationEventBolusReminder()
|
||||||
Assertions.assertEquals(0, automationPlugin.size())
|
assertThat(automationPlugin.size()).isEqualTo(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@ import app.aaps.plugins.automation.triggers.Trigger
|
||||||
import app.aaps.plugins.automation.ui.TimerUtil
|
import app.aaps.plugins.automation.ui.TimerUtil
|
||||||
import app.aaps.shared.impl.utils.DateUtilImpl
|
import app.aaps.shared.impl.utils.DateUtilImpl
|
||||||
import app.aaps.shared.tests.TestBase
|
import app.aaps.shared.tests.TestBase
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
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.ArgumentMatchers.any
|
import org.mockito.ArgumentMatchers.any
|
||||||
|
@ -52,27 +52,24 @@ class CarbTimerImplTest : TestBase() {
|
||||||
|
|
||||||
private lateinit var automationPlugin: AutomationPlugin
|
private lateinit var automationPlugin: AutomationPlugin
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach fun init() {
|
||||||
fun init() {
|
|
||||||
Mockito.`when`(rh.gs(anyInt())).thenReturn("")
|
Mockito.`when`(rh.gs(anyInt())).thenReturn("")
|
||||||
Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
|
Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
|
||||||
dateUtil = DateUtilImpl(context)
|
dateUtil = DateUtilImpl(context)
|
||||||
timerUtil = TimerUtil(context)
|
timerUtil = TimerUtil(context)
|
||||||
automationPlugin = AutomationPlugin(
|
automationPlugin = AutomationPlugin(
|
||||||
injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil,
|
injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, activePlugin, timerUtil
|
||||||
activePlugin, timerUtil
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test fun doTest() {
|
||||||
fun doTest() {
|
assertThat(automationPlugin.size()).isEqualTo(0)
|
||||||
Assertions.assertEquals(0, automationPlugin.size())
|
|
||||||
automationPlugin.scheduleAutomationEventEatReminder()
|
automationPlugin.scheduleAutomationEventEatReminder()
|
||||||
Assertions.assertEquals(1, automationPlugin.size())
|
assertThat(automationPlugin.size()).isEqualTo(1)
|
||||||
automationPlugin.removeAutomationEventEatReminder()
|
automationPlugin.removeAutomationEventEatReminder()
|
||||||
Assertions.assertEquals(0, automationPlugin.size())
|
assertThat(automationPlugin.size()).isEqualTo(0)
|
||||||
|
|
||||||
automationPlugin.scheduleTimeToEatReminder(1)
|
automationPlugin.scheduleTimeToEatReminder(1)
|
||||||
Mockito.verify(context, Mockito.times(1)).startActivity(any())
|
Mockito.verify(context, Mockito.times(1)).startActivity(any())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,14 @@ import app.aaps.plugins.automation.triggers.Trigger
|
||||||
import app.aaps.plugins.automation.triggers.TriggerConnector
|
import app.aaps.plugins.automation.triggers.TriggerConnector
|
||||||
import app.aaps.plugins.automation.triggers.TriggerDummy
|
import app.aaps.plugins.automation.triggers.TriggerDummy
|
||||||
import app.aaps.shared.tests.TestBase
|
import app.aaps.shared.tests.TestBase
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import org.junit.jupiter.api.Assertions
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class ComposeTriggerTest : TestBase() {
|
class ComposeTriggerTest : TestBase() {
|
||||||
|
|
||||||
var injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { } }
|
val injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { } }
|
||||||
|
|
||||||
@Test fun testTriggerList() {
|
@Test fun testTriggerList() {
|
||||||
val root = TriggerConnector(injector)
|
val root = TriggerConnector(injector)
|
||||||
|
@ -23,16 +23,11 @@ class ComposeTriggerTest : TestBase() {
|
||||||
root.list.add(t1)
|
root.list.add(t1)
|
||||||
val t2: Trigger = TriggerDummy(injector)
|
val t2: Trigger = TriggerDummy(injector)
|
||||||
root.list.add(t2)
|
root.list.add(t2)
|
||||||
Assertions.assertEquals(3, root.size())
|
assertThat(root.list).containsExactly(t0, t1, t2).inOrder()
|
||||||
Assertions.assertEquals(t0, root.list[0])
|
|
||||||
Assertions.assertEquals(t1, root.list[1])
|
|
||||||
Assertions.assertEquals(t2, root.list[2])
|
|
||||||
|
|
||||||
// remove a trigger
|
// remove a trigger
|
||||||
root.list.remove(t1)
|
root.list.remove(t1)
|
||||||
Assertions.assertEquals(2, root.size())
|
assertThat(root.list).containsExactly(t0, t2).inOrder()
|
||||||
Assertions.assertEquals(t0, root.list[0])
|
|
||||||
Assertions.assertEquals(t2, root.list[1])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -44,6 +39,6 @@ class ComposeTriggerTest : TestBase() {
|
||||||
t[i] = TriggerDummy(injector)
|
t[i] = TriggerDummy(injector)
|
||||||
root.list.add(t[i]!!)
|
root.list.add(t[i]!!)
|
||||||
}
|
}
|
||||||
Assertions.assertEquals(4, root.size())
|
assertThat(root.size()).isEqualTo(4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,15 @@ import app.aaps.plugins.automation.R
|
||||||
import app.aaps.plugins.automation.elements.InputString
|
import app.aaps.plugins.automation.elements.InputString
|
||||||
import app.aaps.plugins.automation.ui.TimerUtil
|
import app.aaps.plugins.automation.ui.TimerUtil
|
||||||
import app.aaps.shared.tests.TestBase
|
import app.aaps.shared.tests.TestBase
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
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.ArgumentMatchers
|
import org.mockito.ArgumentMatchers
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class ActionAlarmTest : TestBase() {
|
class ActionAlarmTest : TestBase() {
|
||||||
|
|
||||||
|
@ -54,39 +55,39 @@ class ActionAlarmTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.string.alarm, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(app.aaps.core.ui.R.string.alarm)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
sut.text = InputString("Asd")
|
sut.text = InputString("Asd")
|
||||||
Assertions.assertEquals("Alarm: %s", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Alarm: %s")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.main.R.drawable.ic_access_alarm_24dp, sut.icon())
|
assertThat(sut.icon()).isEqualTo(app.aaps.core.main.R.drawable.ic_access_alarm_24dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
sut.text = InputString("Asd")
|
sut.text = InputString("Asd")
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertTrue(result.success)
|
assertThat(result.success).isTrue()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
Assertions.assertTrue(sut.hasDialog())
|
assertThat(sut.hasDialog()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
sut.text = InputString("Asd")
|
sut.text = InputString("Asd")
|
||||||
Assertions.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionAlarm\"}", sut.toJSON())
|
JSONAssert.assertEquals("""{"data":{"text":"Asd"},"type":"ActionAlarm"}""", sut.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun fromJSONTest() {
|
@Test fun fromJSONTest() {
|
||||||
sut.text = InputString("Asd")
|
sut.text = InputString("Asd")
|
||||||
sut.fromJSON("{\"text\":\"Asd\"}")
|
sut.fromJSON("""{"text":"Asd"}""")
|
||||||
Assertions.assertEquals("Asd", sut.text.value)
|
assertThat(sut.text.value).isEqualTo("Asd")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,12 @@ import app.aaps.plugins.automation.elements.InputCarePortalMenu
|
||||||
import app.aaps.plugins.automation.elements.InputDuration
|
import app.aaps.plugins.automation.elements.InputDuration
|
||||||
import app.aaps.plugins.automation.elements.InputString
|
import app.aaps.plugins.automation.elements.InputString
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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.ArgumentMatchers
|
import org.mockito.ArgumentMatchers
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class ActionCarePortalEventTest : ActionsTestBase() {
|
class ActionCarePortalEventTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
@ -35,41 +36,42 @@ class ActionCarePortalEventTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.string.careportal, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(app.aaps.core.ui.R.string.careportal)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
Assertions.assertEquals("Note : Asd", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Note : Asd")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.main.R.drawable.ic_cp_note, sut.icon())
|
assertThat(sut.icon()).isEqualTo(app.aaps.core.main.R.drawable.ic_cp_note)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertTrue(result.success)
|
assertThat(result.success).isTrue()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
Assertions.assertTrue(sut.hasDialog())
|
assertThat(sut.hasDialog()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
Assertions.assertEquals(
|
JSONAssert.assertEquals(
|
||||||
"{\"data\":{\"note\":\"Asd\",\"cpEvent\":\"NOTE\",\"durationInMinutes\":5},\"type\":\"ActionCarePortalEvent\"}",
|
"""{"data":{"note":"Asd","cpEvent":"NOTE","durationInMinutes":5},"type":"ActionCarePortalEvent"}""",
|
||||||
sut.toJSON()
|
sut.toJSON(),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun fromJSONTest() {
|
@Test fun fromJSONTest() {
|
||||||
sut.note = InputString("Asd")
|
sut.note = InputString("Asd")
|
||||||
sut.fromJSON("{\"note\":\"Asd\",\"cpEvent\":\"NOTE\",\"durationInMinutes\":5}")
|
sut.fromJSON("""{"note":"Asd","cpEvent":"NOTE","durationInMinutes":5}""")
|
||||||
Assertions.assertEquals("Asd", sut.note.value)
|
assertThat(sut.note.value).isEqualTo("Asd")
|
||||||
Assertions.assertEquals(5, sut.duration.value)
|
assertThat(sut.duration.value).isEqualTo(5)
|
||||||
Assertions.assertEquals(InputCarePortalMenu.EventType.NOTE, sut.cpEvent.value)
|
assertThat(sut.cpEvent.value).isEqualTo(InputCarePortalMenu.EventType.NOTE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
package app.aaps.plugins.automation.actions
|
package app.aaps.plugins.automation.actions
|
||||||
|
|
||||||
|
import kotlin.test.assertIs
|
||||||
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
|
||||||
|
|
||||||
class ActionDummyTest : ActionsTestBase() {
|
class ActionDummyTest : ActionsTestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun instantiateTest() {
|
fun instantiateTest() {
|
||||||
var action: Action? = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy\"}"))
|
var action: Action? = ActionDummy(injector).instantiate(JSONObject("""{"type":"info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy"}"""))
|
||||||
Assertions.assertTrue(action is ActionDummy)
|
assertIs<ActionDummy>(action)
|
||||||
|
|
||||||
action = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"app.aaps.plugins.automation.actions.ActionDummy\"}"))
|
action = ActionDummy(injector).instantiate(JSONObject("""{"type":"app.aaps.plugins.automation.actions.ActionDummy"}"""))
|
||||||
Assertions.assertTrue(action is ActionDummy)
|
assertIs<ActionDummy>(action)
|
||||||
|
|
||||||
action = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"ActionDummy\"}"))
|
action = ActionDummy(injector).instantiate(JSONObject("""{"type":"ActionDummy"}"""))
|
||||||
Assertions.assertTrue(action is ActionDummy)
|
assertIs<ActionDummy>(action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package app.aaps.plugins.automation.actions
|
||||||
import app.aaps.core.interfaces.plugin.PluginType
|
import app.aaps.core.interfaces.plugin.PluginType
|
||||||
import app.aaps.core.interfaces.queue.Callback
|
import app.aaps.core.interfaces.queue.Callback
|
||||||
import app.aaps.plugins.automation.R
|
import app.aaps.plugins.automation.R
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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.ArgumentMatchers.eq
|
import org.mockito.ArgumentMatchers.eq
|
||||||
|
@ -27,17 +27,17 @@ class ActionLoopDisableTest : ActionsTestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun friendlyNameTest() {
|
fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.string.disableloop, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(app.aaps.core.ui.R.string.disableloop)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shortDescriptionTest() {
|
fun shortDescriptionTest() {
|
||||||
Assertions.assertEquals("Disable loop", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Disable loop")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun iconTest() {
|
fun iconTest() {
|
||||||
Assertions.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
|
assertThat(sut.icon()).isEqualTo(R.drawable.ic_stop_24dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -60,4 +60,4 @@ class ActionLoopDisableTest : ActionsTestBase() {
|
||||||
Mockito.verify(configBuilder, Mockito.times(1)).storeSettings("ActionLoopDisable")
|
Mockito.verify(configBuilder, Mockito.times(1)).storeSettings("ActionLoopDisable")
|
||||||
Mockito.verify(commandQueue, Mockito.times(1)).cancelTempBasal(eq(true), anyObject())
|
Mockito.verify(commandQueue, Mockito.times(1)).cancelTempBasal(eq(true), anyObject())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package app.aaps.plugins.automation.actions
|
||||||
import app.aaps.core.interfaces.plugin.PluginType
|
import app.aaps.core.interfaces.plugin.PluginType
|
||||||
import app.aaps.core.interfaces.queue.Callback
|
import app.aaps.core.interfaces.queue.Callback
|
||||||
import app.aaps.plugins.automation.R
|
import app.aaps.plugins.automation.R
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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
|
import org.mockito.Mockito
|
||||||
|
@ -24,15 +24,15 @@ class ActionLoopEnableTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.string.enableloop, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(app.aaps.core.ui.R.string.enableloop)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
Assertions.assertEquals("Enable loop", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Enable loop")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(R.drawable.ic_play_circle_outline_24dp, sut.icon())
|
assertThat(sut.icon()).isEqualTo(R.drawable.ic_play_circle_outline_24dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
|
@ -52,4 +52,4 @@ class ActionLoopEnableTest : ActionsTestBase() {
|
||||||
Mockito.verify(loopPlugin, Mockito.times(1)).setPluginEnabled(PluginType.LOOP, true)
|
Mockito.verify(loopPlugin, Mockito.times(1)).setPluginEnabled(PluginType.LOOP, true)
|
||||||
Mockito.verify(configBuilder, Mockito.times(1)).storeSettings("ActionLoopEnable")
|
Mockito.verify(configBuilder, Mockito.times(1)).storeSettings("ActionLoopEnable")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import app.aaps.database.impl.transactions.CancelCurrentOfflineEventIfAnyTransac
|
||||||
import app.aaps.database.impl.transactions.Transaction
|
import app.aaps.database.impl.transactions.Transaction
|
||||||
import app.aaps.plugins.automation.R
|
import app.aaps.plugins.automation.R
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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`
|
||||||
|
@ -25,15 +25,15 @@ class ActionLoopResumeTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.string.resumeloop, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(app.aaps.core.ui.R.string.resumeloop)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
Assertions.assertEquals("Resume loop", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Resume loop")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(R.drawable.ic_replay_24dp, sut.icon())
|
assertThat(sut.icon()).isEqualTo(R.drawable.ic_replay_24dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
|
@ -64,4 +64,4 @@ class ActionLoopResumeTest : ActionsTestBase() {
|
||||||
})
|
})
|
||||||
//Mockito.verify(loopPlugin, Mockito.times(1)).suspendTo(0)
|
//Mockito.verify(loopPlugin, Mockito.times(1)).suspendTo(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package app.aaps.plugins.automation.actions
|
||||||
import app.aaps.core.interfaces.queue.Callback
|
import app.aaps.core.interfaces.queue.Callback
|
||||||
import app.aaps.plugins.automation.R
|
import app.aaps.plugins.automation.R
|
||||||
import app.aaps.plugins.automation.elements.InputDuration
|
import app.aaps.plugins.automation.elements.InputDuration
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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
|
import org.mockito.Mockito
|
||||||
|
@ -24,16 +24,16 @@ class ActionLoopSuspendTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.string.suspendloop, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(app.aaps.core.ui.R.string.suspendloop)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
sut.minutes = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
sut.minutes = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
||||||
Assertions.assertEquals("Suspend loop for 30 min", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Suspend loop for 30 min")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(R.drawable.ic_pause_circle_outline_24dp, sut.icon())
|
assertThat(sut.icon()).isEqualTo(R.drawable.ic_pause_circle_outline_24dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
|
@ -57,11 +57,11 @@ class ActionLoopSuspendTest : ActionsTestBase() {
|
||||||
a.minutes = InputDuration(20, InputDuration.TimeUnit.MINUTES)
|
a.minutes = InputDuration(20, InputDuration.TimeUnit.MINUTES)
|
||||||
val b = ActionLoopSuspend(injector)
|
val b = ActionLoopSuspend(injector)
|
||||||
b.apply(a)
|
b.apply(a)
|
||||||
Assertions.assertEquals(20, b.minutes.getMinutes().toLong())
|
assertThat(b.minutes.getMinutes().toLong()).isEqualTo(20)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
val a = ActionLoopSuspend(injector)
|
val a = ActionLoopSuspend(injector)
|
||||||
Assertions.assertTrue(a.hasDialog())
|
assertThat(a.hasDialog()).isTrue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,14 @@ import app.aaps.shared.tests.TestBase
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import io.reactivex.rxjava3.core.Completable
|
import io.reactivex.rxjava3.core.Completable
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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.ArgumentMatchers
|
import org.mockito.ArgumentMatchers
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class ActionNotificationTest : TestBase() {
|
class ActionNotificationTest : TestBase() {
|
||||||
|
|
||||||
|
@ -60,22 +61,22 @@ class ActionNotificationTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.string.notification, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(app.aaps.core.ui.R.string.notification)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
sut.text = InputString("Asd")
|
sut.text = InputString("Asd")
|
||||||
Assertions.assertEquals("Notification: %s", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Notification: %s")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(R.drawable.ic_notifications, sut.icon())
|
assertThat(sut.icon()).isEqualTo(R.drawable.ic_notifications)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertTrue(result.success)
|
assertThat(result.success).isTrue()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Mockito.verify(rxBusMocked, Mockito.times(2)).send(anyObject())
|
Mockito.verify(rxBusMocked, Mockito.times(2)).send(anyObject())
|
||||||
|
@ -83,20 +84,21 @@ class ActionNotificationTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
Assertions.assertTrue(sut.hasDialog())
|
assertThat(sut.hasDialog())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
sut.text = InputString("Asd")
|
sut.text = InputString("Asd")
|
||||||
Assertions.assertEquals(
|
JSONAssert.assertEquals(
|
||||||
"{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionNotification\"}",
|
"""{"data":{"text":"Asd"},"type":"ActionNotification"}""",
|
||||||
sut.toJSON()
|
sut.toJSON(),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun fromJSONTest() {
|
@Test fun fromJSONTest() {
|
||||||
sut.text = InputString("Asd")
|
sut.text = InputString("Asd")
|
||||||
sut.fromJSON("{\"text\":\"Asd\"}")
|
sut.fromJSON("""{"text":"Asd"}""")
|
||||||
Assertions.assertEquals("Asd", sut.text.value)
|
assertThat(sut.text.value).isEqualTo("Asd")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,12 @@ import app.aaps.core.interfaces.queue.Callback
|
||||||
import app.aaps.plugins.automation.R
|
import app.aaps.plugins.automation.R
|
||||||
import app.aaps.plugins.automation.elements.InputDuration
|
import app.aaps.plugins.automation.elements.InputDuration
|
||||||
import app.aaps.plugins.automation.elements.InputPercent
|
import app.aaps.plugins.automation.elements.InputPercent
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class ActionProfileSwitchPercentTest : ActionsTestBase() {
|
class ActionProfileSwitchPercentTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
@ -24,17 +25,17 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(R.string.profilepercentage, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(R.string.profilepercentage)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
sut.pct = InputPercent(100.0)
|
sut.pct = InputPercent(100.0)
|
||||||
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
||||||
Assertions.assertEquals("Start profile 100% for 30 min", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Start profile 100% for 30 min")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.drawable.ic_actions_profileswitch, sut.icon())
|
assertThat(sut.icon()).isEqualTo(app.aaps.core.ui.R.drawable.ic_actions_profileswitch)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
|
@ -43,25 +44,25 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() {
|
||||||
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertTrue(result.success)
|
assertThat(result.success).isTrue()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Mockito.verify(profileFunction, Mockito.times(1)).createProfileSwitch(30, 110, 0)
|
Mockito.verify(profileFunction, Mockito.times(1)).createProfileSwitch(30, 110, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
Assertions.assertTrue(sut.hasDialog())
|
assertThat(sut.hasDialog()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
sut.pct = InputPercent(100.0)
|
sut.pct = InputPercent(100.0)
|
||||||
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
||||||
Assertions.assertEquals("{\"data\":{\"percentage\":100,\"durationInMinutes\":30},\"type\":\"ActionProfileSwitchPercent\"}", sut.toJSON())
|
JSONAssert.assertEquals("""{"data":{"percentage":100,"durationInMinutes":30},"type":"ActionProfileSwitchPercent"}""", sut.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun fromJSONTest() {
|
@Test fun fromJSONTest() {
|
||||||
sut.fromJSON("{\"percentage\":100,\"durationInMinutes\":30}")
|
sut.fromJSON("""{"percentage":100,"durationInMinutes":30}""")
|
||||||
Assertions.assertEquals(100.0, sut.pct.value, 0.001)
|
assertThat(sut.pct.value).isWithin(0.001).of(100.0)
|
||||||
Assertions.assertEquals(30.0, sut.duration.getMinutes().toDouble(), 0.001)
|
assertThat(sut.duration.getMinutes().toDouble()).isWithin(0.001).of(30.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package app.aaps.plugins.automation.actions
|
||||||
import app.aaps.core.interfaces.queue.Callback
|
import app.aaps.core.interfaces.queue.Callback
|
||||||
import app.aaps.plugins.automation.R
|
import app.aaps.plugins.automation.R
|
||||||
import app.aaps.plugins.automation.elements.InputProfileName
|
import app.aaps.plugins.automation.elements.InputProfileName
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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.ArgumentMatchers.anyLong
|
import org.mockito.ArgumentMatchers.anyLong
|
||||||
|
@ -11,13 +11,14 @@ import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.anyInt
|
import org.mockito.Mockito.anyInt
|
||||||
import org.mockito.Mockito.anyString
|
import org.mockito.Mockito.anyString
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
|
private const val STRING_JSON = """{"data":{"profileToSwitchTo":"Test"},"type":"ActionProfileSwitch"}"""
|
||||||
|
|
||||||
class ActionProfileSwitchTest : ActionsTestBase() {
|
class ActionProfileSwitchTest : ActionsTestBase() {
|
||||||
|
|
||||||
private lateinit var sut: ActionProfileSwitch
|
private lateinit var sut: ActionProfileSwitch
|
||||||
|
|
||||||
private val stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"ActionProfileSwitch\"}"
|
|
||||||
|
|
||||||
@BeforeEach fun setUp() {
|
@BeforeEach fun setUp() {
|
||||||
`when`(rh.gs(R.string.profilename)).thenReturn("Change profile to")
|
`when`(rh.gs(R.string.profilename)).thenReturn("Change profile to")
|
||||||
`when`(rh.gs(R.string.changengetoprofilename)).thenReturn("Change profile to %s")
|
`when`(rh.gs(R.string.changengetoprofilename)).thenReturn("Change profile to %s")
|
||||||
|
@ -30,11 +31,11 @@ class ActionProfileSwitchTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyName() {
|
@Test fun friendlyName() {
|
||||||
Assertions.assertEquals(R.string.profilename, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(R.string.profilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
Assertions.assertEquals("Change profile to ", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Change profile to ")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doAction() {
|
@Test fun doAction() {
|
||||||
|
@ -43,7 +44,7 @@ class ActionProfileSwitchTest : ActionsTestBase() {
|
||||||
sut.inputProfileName = InputProfileName(rh, activePlugin, "")
|
sut.inputProfileName = InputProfileName(rh, activePlugin, "")
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertFalse(result.success)
|
assertThat(result.success).isFalse()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ class ActionProfileSwitchTest : ActionsTestBase() {
|
||||||
sut.inputProfileName = InputProfileName(rh, activePlugin, "someProfile")
|
sut.inputProfileName = InputProfileName(rh, activePlugin, "someProfile")
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertFalse(result.success)
|
assertThat(result.success).isFalse()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -62,8 +63,8 @@ class ActionProfileSwitchTest : ActionsTestBase() {
|
||||||
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
|
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertTrue(result.success)
|
assertThat(result.success).isTrue()
|
||||||
Assertions.assertEquals("Already set", result.comment)
|
assertThat(result.comment).isEqualTo("Already set")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -72,8 +73,8 @@ class ActionProfileSwitchTest : ActionsTestBase() {
|
||||||
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
|
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertFalse(result.success)
|
assertThat(result.success).isFalse()
|
||||||
Assertions.assertEquals("not exists", result.comment)
|
assertThat(result.comment).isEqualTo("not exists")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -83,29 +84,28 @@ class ActionProfileSwitchTest : ActionsTestBase() {
|
||||||
sut.inputProfileName = InputProfileName(rh, activePlugin, TESTPROFILENAME)
|
sut.inputProfileName = InputProfileName(rh, activePlugin, TESTPROFILENAME)
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertTrue(result.success)
|
assertThat(result.success).isTrue()
|
||||||
Assertions.assertEquals("OK", result.comment)
|
assertThat(result.comment).isEqualTo("OK")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Mockito.verify(profileFunction, Mockito.times(1)).createProfileSwitch(anyObject(), anyString(), anyInt(), anyInt(), anyInt(), anyLong())
|
Mockito.verify(profileFunction, Mockito.times(1)).createProfileSwitch(anyObject(), anyString(), anyInt(), anyInt(), anyInt(), anyLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
Assertions.assertTrue(sut.hasDialog())
|
assertThat(sut.hasDialog()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
|
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
|
||||||
Assertions.assertEquals(stringJson, sut.toJSON())
|
JSONAssert.assertEquals(STRING_JSON, sut.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun fromJSONTest() {
|
@Test fun fromJSONTest() {
|
||||||
val data = "{\"profileToSwitchTo\":\"Test\"}"
|
sut.fromJSON("""{"profileToSwitchTo":"Test"}""")
|
||||||
sut.fromJSON(data)
|
assertThat(sut.inputProfileName.value).isEqualTo("Test")
|
||||||
Assertions.assertEquals("Test", sut.inputProfileName.value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.drawable.ic_actions_profileswitch, sut.icon())
|
assertThat(sut.icon()).isEqualTo(app.aaps.core.ui.R.drawable.ic_actions_profileswitch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,12 @@ package app.aaps.plugins.automation.actions
|
||||||
import app.aaps.core.interfaces.queue.Callback
|
import app.aaps.core.interfaces.queue.Callback
|
||||||
import app.aaps.plugins.automation.R
|
import app.aaps.plugins.automation.R
|
||||||
import app.aaps.plugins.automation.elements.InputString
|
import app.aaps.plugins.automation.elements.InputString
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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.ArgumentMatchers.anyString
|
import org.mockito.ArgumentMatchers.anyString
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class ActionSendSMSTest : ActionsTestBase() {
|
class ActionSendSMSTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
@ -23,15 +24,15 @@ class ActionSendSMSTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(R.string.sendsmsactiondescription, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(R.string.sendsmsactiondescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
Assertions.assertEquals("Send SMS: ", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Send SMS: ")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(R.drawable.ic_notifications, sut.icon())
|
assertThat(sut.icon()).isEqualTo(R.drawable.ic_notifications)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
|
@ -39,22 +40,22 @@ class ActionSendSMSTest : ActionsTestBase() {
|
||||||
sut.text = InputString("Asd")
|
sut.text = InputString("Asd")
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertTrue(result.success)
|
assertThat(result.success).isTrue()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
Assertions.assertTrue(sut.hasDialog())
|
assertThat(sut.hasDialog()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
sut.text = InputString("Asd")
|
sut.text = InputString("Asd")
|
||||||
Assertions.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionSendSMS\"}", sut.toJSON())
|
JSONAssert.assertEquals("""{"data":{"text":"Asd"},"type":"ActionSendSMS"}""", sut.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun fromJSONTest() {
|
@Test fun fromJSONTest() {
|
||||||
sut.fromJSON("{\"text\":\"Asd\"}")
|
sut.fromJSON("""{"text":"Asd"}""")
|
||||||
Assertions.assertEquals("Asd", sut.text.value)
|
assertThat(sut.text.value).isEqualTo("Asd")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,12 @@ import app.aaps.plugins.automation.R
|
||||||
import app.aaps.plugins.automation.elements.InputDuration
|
import app.aaps.plugins.automation.elements.InputDuration
|
||||||
import app.aaps.plugins.automation.elements.InputTempTarget
|
import app.aaps.plugins.automation.elements.InputTempTarget
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class ActionStartTempTargetTest : ActionsTestBase() {
|
class ActionStartTempTargetTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
@ -27,18 +28,18 @@ class ActionStartTempTargetTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(R.string.starttemptarget, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(R.string.starttemptarget)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
sut.value = InputTempTarget(profileFunction)
|
sut.value = InputTempTarget(profileFunction)
|
||||||
sut.value.value = 100.0
|
sut.value.value = 100.0
|
||||||
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
||||||
Assertions.assertEquals("Start temp target: 100mg/dl@null(Automation)", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Start temp target: 100mg/dl@null(Automation)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.main.R.drawable.ic_temptarget_high, sut.icon())
|
assertThat(sut.icon()).isEqualTo(app.aaps.core.main.R.drawable.ic_temptarget_high)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
|
@ -78,27 +79,27 @@ class ActionStartTempTargetTest : ActionsTestBase() {
|
||||||
|
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertTrue(result.success)
|
assertThat(result.success).isTrue()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Mockito.verify(repository, Mockito.times(1)).runTransactionForResult(anyObject<Transaction<InsertAndCancelCurrentTemporaryTargetTransaction.TransactionResult>>())
|
Mockito.verify(repository, Mockito.times(1)).runTransactionForResult(anyObject<Transaction<InsertAndCancelCurrentTemporaryTargetTransaction.TransactionResult>>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
Assertions.assertTrue(sut.hasDialog())
|
assertThat(sut.hasDialog()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
sut.value = InputTempTarget(profileFunction)
|
sut.value = InputTempTarget(profileFunction)
|
||||||
sut.value.value = 100.0
|
sut.value.value = 100.0
|
||||||
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
|
||||||
Assertions.assertEquals("{\"data\":{\"durationInMinutes\":30,\"units\":\"mg/dl\",\"value\":100},\"type\":\"ActionStartTempTarget\"}", sut.toJSON())
|
JSONAssert.assertEquals("""{"data":{"durationInMinutes":30,"units":"mg/dl","value":100},"type":"ActionStartTempTarget"}""", sut.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun fromJSONTest() {
|
@Test fun fromJSONTest() {
|
||||||
sut.fromJSON("{\"value\":100,\"durationInMinutes\":30,\"units\":\"mg/dl\"}")
|
sut.fromJSON("""{"value":100,"durationInMinutes":30,"units":"mg/dl"}""")
|
||||||
Assertions.assertEquals(GlucoseUnit.MGDL, sut.value.units)
|
assertThat(sut.value.units).isEqualTo(GlucoseUnit.MGDL)
|
||||||
Assertions.assertEquals(100.0, sut.value.value, 0.001)
|
assertThat(sut.value.value).isWithin(0.001).of(100.0)
|
||||||
Assertions.assertEquals(30.0, sut.duration.getMinutes().toDouble(), 0.001)
|
assertThat(sut.duration.getMinutes().toDouble()).isWithin(0.001).of(30.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package app.aaps.plugins.automation.actions
|
||||||
|
|
||||||
import app.aaps.core.interfaces.queue.Callback
|
import app.aaps.core.interfaces.queue.Callback
|
||||||
import app.aaps.plugins.automation.R
|
import app.aaps.plugins.automation.R
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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`
|
||||||
|
@ -20,25 +20,25 @@ class ActionStopProcessingTest : ActionsTestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun friendlyNameTest() {
|
fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(R.string.stop_processing, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(R.string.stop_processing)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shortDescriptionTest() {
|
fun shortDescriptionTest() {
|
||||||
Assertions.assertEquals("Stop processing", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Stop processing")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun iconTest() {
|
fun iconTest() {
|
||||||
Assertions.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
|
assertThat(sut.icon()).isEqualTo(R.drawable.ic_stop_24dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun doActionTest() {
|
fun doActionTest() {
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertTrue(result.success)
|
assertThat(result.success).isTrue()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,12 @@ import app.aaps.database.impl.transactions.CancelCurrentTemporaryTargetIfAnyTran
|
||||||
import app.aaps.database.impl.transactions.Transaction
|
import app.aaps.database.impl.transactions.Transaction
|
||||||
import app.aaps.plugins.automation.R
|
import app.aaps.plugins.automation.R
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class ActionStopTempTargetTest : ActionsTestBase() {
|
class ActionStopTempTargetTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
@ -24,15 +25,15 @@ class ActionStopTempTargetTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.string.stoptemptarget, sut.friendlyName())
|
assertThat(sut.friendlyName()).isEqualTo(app.aaps.core.ui.R.string.stoptemptarget)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortDescriptionTest() {
|
@Test fun shortDescriptionTest() {
|
||||||
Assertions.assertEquals("Stop temp target", sut.shortDescription())
|
assertThat(sut.shortDescription()).isEqualTo("Stop temp target")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
Assertions.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
|
assertThat(sut.icon()).isEqualTo(R.drawable.ic_stop_24dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
|
@ -52,22 +53,22 @@ class ActionStopTempTargetTest : ActionsTestBase() {
|
||||||
|
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assertions.assertTrue(result.success)
|
assertThat(result.success).isTrue()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Mockito.verify(repository, Mockito.times(1)).runTransactionForResult((anyObject<Transaction<CancelCurrentTemporaryTargetIfAnyTransaction.TransactionResult>>()))
|
Mockito.verify(repository, Mockito.times(1)).runTransactionForResult((anyObject<Transaction<CancelCurrentTemporaryTargetIfAnyTransaction.TransactionResult>>()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
Assertions.assertFalse(sut.hasDialog())
|
assertThat(sut.hasDialog()).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
Assertions.assertEquals("{\"type\":\"ActionStopTempTarget\"}", sut.toJSON())
|
JSONAssert.assertEquals("""{"type":"ActionStopTempTarget"}""", sut.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun fromJSONTest() {
|
@Test fun fromJSONTest() {
|
||||||
sut.fromJSON("{\"reason\":\"Test\"}")
|
sut.fromJSON("""{"reason":"Test"}""")
|
||||||
Assertions.assertNotNull(sut)
|
assertThat(sut).isNotNull()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
package app.aaps.plugins.automation.elements
|
package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class ComparatorConnectTest : TriggerTestBase() {
|
class ComparatorConnectTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test fun labelsTest() {
|
@Test fun labelsTest() {
|
||||||
Assertions.assertEquals(2, ComparatorConnect.Compare.labels(rh).size)
|
assertThat(ComparatorConnect.Compare.labels(rh)).hasSize(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun setValueTest() {
|
@Test fun setValueTest() {
|
||||||
val c = ComparatorConnect(rh)
|
val c = ComparatorConnect(rh)
|
||||||
c.value = ComparatorConnect.Compare.ON_DISCONNECT
|
c.value = ComparatorConnect.Compare.ON_DISCONNECT
|
||||||
Assertions.assertEquals(ComparatorConnect.Compare.ON_DISCONNECT, c.value)
|
assertThat(c.value).isEqualTo(ComparatorConnect.Compare.ON_DISCONNECT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
package app.aaps.plugins.automation.elements
|
package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class ComparatorExistsTest : TriggerTestBase() {
|
class ComparatorExistsTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test fun labelsTest() {
|
@Test fun labelsTest() {
|
||||||
Assertions.assertEquals(2, ComparatorExists.Compare.labels(rh).size)
|
assertThat(ComparatorExists.Compare.labels(rh)).hasSize(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun setValueTest() {
|
@Test fun setValueTest() {
|
||||||
val c = ComparatorExists(rh)
|
val c = ComparatorExists(rh)
|
||||||
c.value = ComparatorExists.Compare.NOT_EXISTS
|
c.value = ComparatorExists.Compare.NOT_EXISTS
|
||||||
Assertions.assertEquals(ComparatorExists.Compare.NOT_EXISTS, c.value)
|
assertThat(c.value).isEqualTo(ComparatorExists.Compare.NOT_EXISTS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
package app.aaps.plugins.automation.elements
|
package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class ComparatorTest : TriggerTestBase() {
|
class ComparatorTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun checkTest() {
|
fun checkTest() {
|
||||||
Assertions.assertTrue(Comparator.Compare.IS_EQUAL.check(1, 1))
|
assertThat(Comparator.Compare.IS_EQUAL.check(1, 1)).isTrue()
|
||||||
Assertions.assertTrue(Comparator.Compare.IS_LESSER.check(1, 2))
|
assertThat(Comparator.Compare.IS_LESSER.check(1, 2)).isTrue()
|
||||||
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(1, 2))
|
assertThat(Comparator.Compare.IS_EQUAL_OR_LESSER.check(1, 2)).isTrue()
|
||||||
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 2))
|
assertThat(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 2)).isTrue()
|
||||||
Assertions.assertTrue(Comparator.Compare.IS_GREATER.check(2, 1))
|
assertThat(Comparator.Compare.IS_GREATER.check(2, 1)).isTrue()
|
||||||
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 1))
|
assertThat(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 1)).isTrue()
|
||||||
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 2))
|
assertThat(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 2)).isTrue()
|
||||||
Assertions.assertFalse(Comparator.Compare.IS_LESSER.check(2, 1))
|
assertThat(Comparator.Compare.IS_LESSER.check(2, 1)).isFalse()
|
||||||
Assertions.assertFalse(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 1))
|
assertThat(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 1)).isFalse()
|
||||||
Assertions.assertFalse(Comparator.Compare.IS_GREATER.check(1, 2))
|
assertThat(Comparator.Compare.IS_GREATER.check(1, 2)).isFalse()
|
||||||
Assertions.assertFalse(Comparator.Compare.IS_EQUAL_OR_GREATER.check(1, 2))
|
assertThat(Comparator.Compare.IS_EQUAL_OR_GREATER.check(1, 2)).isFalse()
|
||||||
// Assertions.assertTrue(Comparator.Compare.IS_NOT_AVAILABLE.check<Int?>(1, null))
|
// assertThat(Comparator.Compare.IS_NOT_AVAILABLE.check<Int?>(1, null)).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun labelsTest() {
|
fun labelsTest() {
|
||||||
Assertions.assertEquals(6, Comparator.Compare.labels(rh).size)
|
assertThat(Comparator.Compare.labels(rh)).hasSize(6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun setValueTest() {
|
fun setValueTest() {
|
||||||
val c: Comparator = Comparator(rh).setValue(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
val c: Comparator = Comparator(rh).setValue(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_GREATER, c.value)
|
assertThat(c.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.core.interfaces.db.GlucoseUnit
|
import app.aaps.core.interfaces.db.GlucoseUnit
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
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`
|
||||||
|
@ -12,16 +12,16 @@ class InputBgTest : TriggerTestBase() {
|
||||||
@Test
|
@Test
|
||||||
fun setValueTest() {
|
fun setValueTest() {
|
||||||
var i: InputBg = InputBg(profileFunction).setUnits(GlucoseUnit.MMOL).setValue(5.0)
|
var i: InputBg = InputBg(profileFunction).setUnits(GlucoseUnit.MMOL).setValue(5.0)
|
||||||
Assertions.assertEquals(5.0, i.value, 0.01)
|
assertThat(i.value).isWithin(0.01).of(5.0)
|
||||||
Assertions.assertEquals(InputBg.MMOL_MIN, i.minValue, 0.01)
|
assertThat(i.minValue).isWithin(0.01).of(InputBg.MMOL_MIN)
|
||||||
i = InputBg(profileFunction).setValue(100.0).setUnits(GlucoseUnit.MGDL)
|
i = InputBg(profileFunction).setValue(100.0).setUnits(GlucoseUnit.MGDL)
|
||||||
Assertions.assertEquals(100.0, i.value, 0.01)
|
assertThat(i.value).isWithin(0.01).of(100.0)
|
||||||
Assertions.assertEquals(InputBg.MGDL_MIN, i.minValue, 0.01)
|
assertThat(i.minValue).isWithin(0.01).of(InputBg.MGDL_MIN)
|
||||||
Assertions.assertEquals(GlucoseUnit.MGDL, i.units)
|
assertThat(i.units).isEqualTo(GlucoseUnit.MGDL)
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun prepare() {
|
fun prepare() {
|
||||||
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
|
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
package app.aaps.plugins.automation.elements
|
package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class InputCarePortalEventTest : TriggerTestBase() {
|
class InputCarePortalEventTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun labelsTest() {
|
fun labelsTest() {
|
||||||
Assertions.assertEquals(4, InputCarePortalMenu.EventType.labels(rh).size)
|
assertThat(InputCarePortalMenu.EventType.labels(rh)).hasSize(4)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun setValueTest() {
|
fun setValueTest() {
|
||||||
val cp = InputCarePortalMenu(rh, InputCarePortalMenu.EventType.EXERCISE)
|
val cp = InputCarePortalMenu(rh, InputCarePortalMenu.EventType.EXERCISE)
|
||||||
Assertions.assertEquals(InputCarePortalMenu.EventType.EXERCISE, cp.value)
|
assertThat(cp.value).isEqualTo(InputCarePortalMenu.EventType.EXERCISE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
package app.aaps.plugins.automation.elements
|
package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class InputDurationTest : TriggerTestBase() {
|
class InputDurationTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test fun setValueTest() {
|
@Test fun setValueTest() {
|
||||||
var i = InputDuration(5, InputDuration.TimeUnit.MINUTES)
|
var i = InputDuration(5, InputDuration.TimeUnit.MINUTES)
|
||||||
Assertions.assertEquals(5, i.value)
|
assertThat(i.value).isEqualTo(5)
|
||||||
Assertions.assertEquals(InputDuration.TimeUnit.MINUTES, i.unit)
|
assertThat(i.unit).isEqualTo(InputDuration.TimeUnit.MINUTES)
|
||||||
i = InputDuration(5, InputDuration.TimeUnit.HOURS)
|
i = InputDuration(5, InputDuration.TimeUnit.HOURS)
|
||||||
Assertions.assertEquals(5, i.value)
|
assertThat(i.value).isEqualTo(5)
|
||||||
Assertions.assertEquals(InputDuration.TimeUnit.HOURS, i.unit)
|
assertThat(i.unit).isEqualTo(InputDuration.TimeUnit.HOURS)
|
||||||
Assertions.assertEquals(5 * 60, i.getMinutes())
|
assertThat(i.getMinutes()).isEqualTo(5 * 60)
|
||||||
i.setMinutes(60)
|
i.setMinutes(60)
|
||||||
Assertions.assertEquals(1, i.value)
|
assertThat(i.value).isEqualTo(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package app.aaps.plugins.automation.elements
|
package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class InputInsulinTest : TriggerTestBase() {
|
class InputInsulinTest : TriggerTestBase() {
|
||||||
|
@ -9,6 +9,6 @@ class InputInsulinTest : TriggerTestBase() {
|
||||||
@Test fun setValueTest() {
|
@Test fun setValueTest() {
|
||||||
val i = InputInsulin()
|
val i = InputInsulin()
|
||||||
i.value = 5.0
|
i.value = 5.0
|
||||||
Assertions.assertEquals(5.0, i.value, 0.01)
|
assertThat(i.value).isWithin(0.01).of(5.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package app.aaps.plugins.automation.elements
|
package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class InputPercentTest : TriggerTestBase() {
|
class InputPercentTest : TriggerTestBase() {
|
||||||
|
@ -9,6 +9,6 @@ class InputPercentTest : TriggerTestBase() {
|
||||||
@Test fun setValueTest() {
|
@Test fun setValueTest() {
|
||||||
val i = InputPercent()
|
val i = InputPercent()
|
||||||
i.value = 10.0
|
i.value = 10.0
|
||||||
Assertions.assertEquals(10.0, i.value, 0.01)
|
assertThat(i.value).isWithin(0.01).of(10.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package app.aaps.plugins.automation.elements
|
package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class InputProfileNameTest : TriggerTestBase() {
|
class InputProfileNameTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test fun setValue() {
|
@Test fun setValue() {
|
||||||
val inputProfileName = InputProfileName(rh, activePlugin, "Test")
|
val inputProfileName = InputProfileName(rh, activePlugin, "Test")
|
||||||
Assertions.assertEquals("Test", inputProfileName.value)
|
assertThat(inputProfileName.value).isEqualTo("Test")
|
||||||
inputProfileName.value = "Test2"
|
inputProfileName.value = "Test2"
|
||||||
Assertions.assertEquals("Test2", inputProfileName.value)
|
assertThat(inputProfileName.value).isEqualTo("Test2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package app.aaps.plugins.automation.elements
|
package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class InputStringTest : TriggerTestBase() {
|
class InputStringTest : TriggerTestBase() {
|
||||||
|
@ -9,6 +9,6 @@ class InputStringTest : TriggerTestBase() {
|
||||||
@Test fun setValueTest() {
|
@Test fun setValueTest() {
|
||||||
val i = InputString()
|
val i = InputString()
|
||||||
i.value = "asd"
|
i.value = "asd"
|
||||||
Assertions.assertEquals("asd", i.value)
|
assertThat(i.value).isEqualTo("asd")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.core.interfaces.db.GlucoseUnit
|
import app.aaps.core.interfaces.db.GlucoseUnit
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class InputTempTargetTest : TriggerTestBase() {
|
class InputTempTargetTest : TriggerTestBase() {
|
||||||
|
@ -11,10 +11,10 @@ class InputTempTargetTest : TriggerTestBase() {
|
||||||
val i = InputTempTarget(profileFunction)
|
val i = InputTempTarget(profileFunction)
|
||||||
i.units = GlucoseUnit.MMOL
|
i.units = GlucoseUnit.MMOL
|
||||||
i.value = 5.0
|
i.value = 5.0
|
||||||
Assertions.assertEquals(5.0, i.value, 0.01)
|
assertThat(i.value).isWithin(0.01).of(5.0)
|
||||||
i.units = GlucoseUnit.MGDL
|
i.units = GlucoseUnit.MGDL
|
||||||
i.value = 100.0
|
i.value = 100.0
|
||||||
Assertions.assertEquals(100.0, i.value, 0.01)
|
assertThat(i.value).isWithin(0.01).of(100.0)
|
||||||
Assertions.assertEquals(GlucoseUnit.MGDL, i.units)
|
assertThat(i.units).isEqualTo(GlucoseUnit.MGDL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
package app.aaps.plugins.automation.elements
|
package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import kotlin.test.assertIs
|
||||||
|
|
||||||
class LabelWithElementTest : TriggerTestBase() {
|
class LabelWithElementTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun constructorTest() {
|
fun constructorTest() {
|
||||||
val l = LabelWithElement(rh, "A", "B", InputInsulin())
|
val l = LabelWithElement(rh, "A", "B", InputInsulin())
|
||||||
Assertions.assertEquals("A", l.textPre)
|
assertThat(l.textPre).isEqualTo("A")
|
||||||
Assertions.assertEquals("B", l.textPost)
|
assertThat(l.textPost).isEqualTo("B")
|
||||||
Assertions.assertEquals(InputInsulin::class.java, l.element!!.javaClass)
|
assertIs<InputInsulin>(l.element)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package app.aaps.plugins.automation.elements
|
||||||
import app.aaps.shared.tests.TestBase
|
import app.aaps.shared.tests.TestBase
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class LayoutBuilderTest : TestBase() {
|
class LayoutBuilderTest : TestBase() {
|
||||||
|
@ -14,15 +14,15 @@ class LayoutBuilderTest : TestBase() {
|
||||||
val layoutBuilder = LayoutBuilder()
|
val layoutBuilder = LayoutBuilder()
|
||||||
val inputInsulin = InputInsulin()
|
val inputInsulin = InputInsulin()
|
||||||
layoutBuilder.add(inputInsulin)
|
layoutBuilder.add(inputInsulin)
|
||||||
Assertions.assertEquals(1, layoutBuilder.mElements.size)
|
assertThat(layoutBuilder.mElements).hasSize(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun addConditionalTest() {
|
@Test fun addConditionalTest() {
|
||||||
val layoutBuilder = LayoutBuilder()
|
val layoutBuilder = LayoutBuilder()
|
||||||
val inputInsulin = InputInsulin()
|
val inputInsulin = InputInsulin()
|
||||||
layoutBuilder.maybeAdd(inputInsulin, true)
|
layoutBuilder.maybeAdd(inputInsulin, true)
|
||||||
Assertions.assertEquals(1, layoutBuilder.mElements.size)
|
assertThat(layoutBuilder.mElements).hasSize(1)
|
||||||
layoutBuilder.maybeAdd(inputInsulin, false)
|
layoutBuilder.maybeAdd(inputInsulin, false)
|
||||||
Assertions.assertEquals(1, layoutBuilder.mElements.size)
|
assertThat(layoutBuilder.mElements).hasSize(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package app.aaps.plugins.automation.elements
|
||||||
|
|
||||||
import app.aaps.plugins.automation.triggers.TriggerDummy
|
import app.aaps.plugins.automation.triggers.TriggerDummy
|
||||||
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
import app.aaps.plugins.automation.triggers.TriggerTestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
|
||||||
|
@ -10,9 +10,9 @@ class StaticLabelTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test fun constructor() {
|
@Test fun constructor() {
|
||||||
var sl = StaticLabel(rh, "any", TriggerDummy(injector))
|
var sl = StaticLabel(rh, "any", TriggerDummy(injector))
|
||||||
Assertions.assertEquals("any", sl.label)
|
assertThat(sl.label).isEqualTo("any")
|
||||||
`when`(rh.gs(app.aaps.core.ui.R.string.pumplimit)).thenReturn("pump limit")
|
`when`(rh.gs(app.aaps.core.ui.R.string.pumplimit)).thenReturn("pump limit")
|
||||||
sl = StaticLabel(rh, app.aaps.core.ui.R.string.pumplimit, TriggerDummy(injector))
|
sl = StaticLabel(rh, app.aaps.core.ui.R.string.pumplimit, TriggerDummy(injector))
|
||||||
Assertions.assertEquals("pump limit", sl.label)
|
assertThat(sl.label).isEqualTo("pump limit")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ import app.aaps.plugins.automation.elements.Comparator
|
||||||
import app.aaps.plugins.main.iob.iobCobCalculator.data.AutosensDataObject
|
import app.aaps.plugins.main.iob.iobCobCalculator.data.AutosensDataObject
|
||||||
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.ArgumentMatchers
|
import org.mockito.ArgumentMatchers
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class TriggerAutosensValueTest : TriggerTestBase() {
|
class TriggerAutosensValueTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -20,53 +20,53 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
||||||
var t = TriggerAutosensValue(injector)
|
var t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 110.0
|
t.autosens.value = 110.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||||
Assertions.assertEquals(110.0, t.autosens.value, 0.01)
|
assertThat(t.autosens.value).isWithin(0.01).of(110.0)
|
||||||
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 = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 100.0
|
t.autosens.value = 100.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||||
Assertions.assertEquals(100.0, t.autosens.value, 0.01)
|
assertThat(t.autosens.value).isWithin(0.01).of(100.0)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 50.0
|
t.autosens.value = 50.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 310.0
|
t.autosens.value = 310.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 420.0
|
t.autosens.value = 420.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 390.0
|
t.autosens.value = 390.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 390.0
|
t.autosens.value = 390.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 20.0
|
t.autosens.value = 20.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 390.0
|
t.autosens.value = 390.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(AutosensDataObject(injector))
|
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(AutosensDataObject(injector))
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 80.0
|
t.autosens.value = 80.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
|
|
||||||
// Test autosensData == null and Comparator == IS_NOT_AVAILABLE
|
// Test autosensData == null and Comparator == IS_NOT_AVAILABLE
|
||||||
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(null)
|
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(null)
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.comparator.value = Comparator.Compare.IS_NOT_AVAILABLE
|
t.comparator.value = Comparator.Compare.IS_NOT_AVAILABLE
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -75,8 +75,8 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
||||||
t.autosens.value = 213.0
|
t.autosens.value = 213.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||||
val t1 = t.duplicate() as TriggerAutosensValue
|
val t1 = t.duplicate() as TriggerAutosensValue
|
||||||
Assertions.assertEquals(213.0, t1.autosens.value, 0.01)
|
assertThat(t1.autosens.value).isWithin(0.01).of(213.0)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var asJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"value\":410},\"type\":\"TriggerAutosensValue\"}"
|
private var asJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"value\":410},\"type\":\"TriggerAutosensValue\"}"
|
||||||
|
@ -86,7 +86,7 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
||||||
val t = TriggerAutosensValue(injector)
|
val t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 410.0
|
t.autosens.value = 410.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||||
Assertions.assertEquals(asJson, t.toJSON())
|
JSONAssert.assertEquals(asJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -95,15 +95,13 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
||||||
t.autosens.value = 410.0
|
t.autosens.value = 410.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerAutosensValue
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerAutosensValue
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(410.0, t2.autosens.value, 0.01)
|
assertThat(t2.autosens.value).isWithin(0.01).of(410.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
assertThat(TriggerAutosensValue(injector).icon().get()).isEqualTo(R.drawable.ic_as)
|
assertThat(TriggerAutosensValue(injector).icon().get()).isEqualTo(R.drawable.ic_as)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateAutosensData(): AutosensDataObject {
|
private fun generateAutosensData() = AutosensDataObject(injector)
|
||||||
return AutosensDataObject(injector)
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ package app.aaps.plugins.automation.triggers
|
||||||
import app.aaps.plugins.automation.elements.ComparatorConnect
|
import app.aaps.plugins.automation.elements.ComparatorConnect
|
||||||
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.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class TriggerBTDeviceTest : TriggerTestBase() {
|
class TriggerBTDeviceTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -19,14 +19,14 @@ class TriggerBTDeviceTest : TriggerTestBase() {
|
||||||
@Test fun toJSON() {
|
@Test fun toJSON() {
|
||||||
val t = TriggerBTDevice(injector)
|
val t = TriggerBTDevice(injector)
|
||||||
t.btDevice.value = someName
|
t.btDevice.value = someName
|
||||||
Assertions.assertEquals(btJson, t.toJSON())
|
JSONAssert.assertEquals(btJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun fromJSON() {
|
fun fromJSON() {
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(btJson)) as TriggerBTDevice
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(btJson)) as TriggerBTDevice
|
||||||
Assertions.assertEquals(ComparatorConnect.Compare.ON_CONNECT, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(ComparatorConnect.Compare.ON_CONNECT)
|
||||||
Assertions.assertEquals("Headset", t2.btDevice.value)
|
assertThat(t2.btDevice.value).isEqualTo("Headset")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -40,7 +40,7 @@ class TriggerBTDeviceTest : TriggerTestBase() {
|
||||||
it.btDevice.value = someName
|
it.btDevice.value = someName
|
||||||
}
|
}
|
||||||
val t1 = t.duplicate() as TriggerBTDevice
|
val t1 = t.duplicate() as TriggerBTDevice
|
||||||
Assertions.assertEquals("Headset", t1.btDevice.value)
|
assertThat(t1.btDevice.value).isEqualTo("Headset")
|
||||||
Assertions.assertEquals(ComparatorConnect.Compare.ON_DISCONNECT, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(ComparatorConnect.Compare.ON_DISCONNECT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,11 @@ import app.aaps.database.entities.GlucoseValue
|
||||||
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 com.google.common.truth.Truth.assertThat
|
||||||
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 TriggerBgTest : TriggerTestBase() {
|
class TriggerBgTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -22,37 +23,37 @@ class TriggerBgTest : TriggerTestBase() {
|
||||||
fun shouldRunTest() {
|
fun shouldRunTest() {
|
||||||
`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOneCurrentRecordBgData())
|
`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOneCurrentRecordBgData())
|
||||||
var t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MMOL).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
var t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MMOL).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(214.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(214.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(214.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(214.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(214.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(214.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(ArrayList())
|
`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(ArrayList())
|
||||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerBg(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
t = TriggerBg(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun copyConstructorTest() {
|
fun copyConstructorTest() {
|
||||||
val t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
val t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
val t1 = t.duplicate() as TriggerBg
|
val t1 = t.duplicate() as TriggerBg
|
||||||
Assertions.assertEquals(213.0, t1.bg.value, 0.01)
|
assertThat(t1.bg.value).isWithin(0.01).of(213.0)
|
||||||
Assertions.assertEquals(GlucoseUnit.MGDL, t1.bg.units)
|
assertThat(t1.bg.units).isEqualTo(GlucoseUnit.MGDL)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"bg\":4.1,\"units\":\"mmol\"},\"type\":\"TriggerBg\"}"
|
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"bg\":4.1,\"units\":\"mmol\"},\"type\":\"TriggerBg\"}"
|
||||||
|
@ -60,16 +61,16 @@ class TriggerBgTest : TriggerTestBase() {
|
||||||
@Test
|
@Test
|
||||||
fun toJSONTest() {
|
fun toJSONTest() {
|
||||||
val t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MMOL).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MMOL).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(bgJson, t.toJSON())
|
JSONAssert.assertEquals(bgJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun fromJSONTest() {
|
fun fromJSONTest() {
|
||||||
val t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MMOL).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MMOL).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerBg
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerBg
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(4.1, t2.bg.value, 0.01)
|
assertThat(t2.bg.value).isWithin(0.01).of(4.1)
|
||||||
Assertions.assertEquals(GlucoseUnit.MMOL, t2.bg.units)
|
assertThat(t2.bg.units).isEqualTo(GlucoseUnit.MMOL)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -82,4 +83,4 @@ class TriggerBgTest : TriggerTestBase() {
|
||||||
list.add(InMemoryGlucoseValue(value = 214.0, timestamp = now - 1, trendArrow = GlucoseValue.TrendArrow.FLAT, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN))
|
list.add(InMemoryGlucoseValue(value = 214.0, timestamp = now - 1, trendArrow = GlucoseValue.TrendArrow.FLAT, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN))
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@ import com.google.common.truth.Truth.assertThat
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
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 TriggerBolusAgoTest : TriggerTestBase() {
|
class TriggerBolusAgoTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -29,26 +29,26 @@ class TriggerBolusAgoTest : TriggerTestBase() {
|
||||||
)
|
)
|
||||||
`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 = TriggerBolusAgo(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL)
|
var t = TriggerBolusAgo(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 = TriggerBolusAgo(injector).setValue(10).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerBolusAgo(injector).setValue(10).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(10, t.minutesAgo.value)
|
assertThat(t.minutesAgo.value).isEqualTo(10)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerBolusAgo(injector).setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerBolusAgo(injector).setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerBolusAgo(injector).setValue(310).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerBolusAgo(injector).setValue(310).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerBolusAgo(injector).setValue(420).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerBolusAgo(injector).setValue(420).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerBolusAgo(injector).setValue(2).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerBolusAgo(injector).setValue(2).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
// Set last bolus time to 0
|
// Set last bolus time to 0
|
||||||
`when`(repository.getLastBolusRecordOfTypeWrapped(Bolus.Type.NORMAL)).thenReturn(
|
`when`(repository.getLastBolusRecordOfTypeWrapped(Bolus.Type.NORMAL)).thenReturn(
|
||||||
Single.just(
|
Single.just(
|
||||||
|
@ -62,30 +62,30 @@ class TriggerBolusAgoTest : TriggerTestBase() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
t = TriggerBolusAgo(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
t = TriggerBolusAgo(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun copyConstructorTest() {
|
@Test fun copyConstructorTest() {
|
||||||
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
val t1 = t.duplicate() as TriggerBolusAgo
|
val t1 = t.duplicate() as TriggerBolusAgo
|
||||||
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\":\"TriggerBolusAgo\"}"
|
private var lbJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"minutesAgo\":410},\"type\":\"TriggerBolusAgo\"}"
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(lbJson, t.toJSON())
|
JSONAssert.assertEquals(lbJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test @Throws(JSONException::class) fun fromJSONTest() {
|
@Test @Throws(JSONException::class) fun fromJSONTest() {
|
||||||
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerBolusAgo
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerBolusAgo
|
||||||
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() {
|
||||||
assertThat(TriggerBolusAgo(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_bolus)
|
assertThat(TriggerBolusAgo(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_bolus)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import app.aaps.core.interfaces.iob.CobInfo
|
||||||
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.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.ArgumentMatchers
|
import org.mockito.ArgumentMatchers
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class TriggerCOBTest : TriggerTestBase() {
|
class TriggerCOBTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -20,44 +20,44 @@ class TriggerCOBTest : TriggerTestBase() {
|
||||||
// COB value is 6
|
// COB value is 6
|
||||||
`when`(iobCobCalculator.getCobInfo("AutomationTriggerCOB")).thenReturn(CobInfo(0, 6.0, 2.0))
|
`when`(iobCobCalculator.getCobInfo("AutomationTriggerCOB")).thenReturn(CobInfo(0, 6.0, 2.0))
|
||||||
var t: TriggerCOB = TriggerCOB(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL)
|
var t: TriggerCOB = TriggerCOB(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerCOB(injector).setValue(6.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerCOB(injector).setValue(6.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerCOB(injector).setValue(5.0).comparator(Comparator.Compare.IS_GREATER)
|
t = TriggerCOB(injector).setValue(5.0).comparator(Comparator.Compare.IS_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerCOB(injector).setValue(5.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerCOB(injector).setValue(5.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerCOB(injector).setValue(6.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerCOB(injector).setValue(6.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerCOB(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerCOB(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerCOB(injector).setValue(10.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerCOB(injector).setValue(10.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerCOB(injector).setValue(5.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerCOB(injector).setValue(5.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun copyConstructorTest() {
|
@Test fun copyConstructorTest() {
|
||||||
val t: TriggerCOB = TriggerCOB(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
val t: TriggerCOB = TriggerCOB(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertEquals(213.0, t.cob.value, 0.01)
|
assertThat(t.cob.value).isWithin(0.01).of(213.0)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"carbs\":4},\"type\":\"TriggerCOB\"}"
|
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"carbs\":4},\"type\":\"TriggerCOB\"}"
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
val t: TriggerCOB = TriggerCOB(injector).setValue(4.0).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerCOB = TriggerCOB(injector).setValue(4.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(bgJson, t.toJSON())
|
JSONAssert.assertEquals(bgJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun fromJSONTest() {
|
fun fromJSONTest() {
|
||||||
val t: TriggerCOB = TriggerCOB(injector).setValue(4.0).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerCOB = TriggerCOB(injector).setValue(4.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerCOB
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerCOB
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(4.0, t2.cob.value, 0.01)
|
assertThat(t2.cob.value).isWithin(0.01).of(4.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
assertThat(TriggerCOB(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_cp_bolus_carbs)
|
assertThat(TriggerCOB(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_cp_bolus_carbs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package app.aaps.plugins.automation.triggers
|
package app.aaps.plugins.automation.triggers
|
||||||
|
|
||||||
|
import kotlin.test.assertIs
|
||||||
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
|
||||||
|
|
||||||
class TriggerDummyTest : TriggerTestBase() {
|
class TriggerDummyTest : TriggerTestBase() {
|
||||||
|
@ -9,13 +9,13 @@ class TriggerDummyTest : TriggerTestBase() {
|
||||||
@Test
|
@Test
|
||||||
fun instantiateTest() {
|
fun instantiateTest() {
|
||||||
var trigger: Trigger? = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy\"}"))
|
var trigger: Trigger? = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy\"}"))
|
||||||
Assertions.assertTrue(trigger is TriggerDummy)
|
assertIs<TriggerDummy>(trigger)
|
||||||
|
|
||||||
trigger = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"app.aaps.plugins.automation.triggers.TriggerDummy\"}"))
|
trigger = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"app.aaps.plugins.automation.triggers.TriggerDummy\"}"))
|
||||||
Assertions.assertTrue(trigger is TriggerDummy)
|
assertIs<TriggerDummy>(trigger)
|
||||||
|
|
||||||
trigger = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"TriggerDummy\"}"))
|
trigger = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"TriggerDummy\"}"))
|
||||||
Assertions.assertTrue(trigger is TriggerDummy)
|
assertIs<TriggerDummy>(trigger)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,19 +3,20 @@ package app.aaps.plugins.automation.triggers
|
||||||
import app.aaps.database.entities.HeartRate
|
import app.aaps.database.entities.HeartRate
|
||||||
import app.aaps.plugins.automation.R
|
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 io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
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.verify
|
import org.mockito.Mockito.verify
|
||||||
import org.mockito.Mockito.verifyNoMoreInteractions
|
import org.mockito.Mockito.verifyNoMoreInteractions
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class TriggerHeartRateTest : TriggerTestBase() {
|
class TriggerHeartRateTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun friendlyName() {
|
fun friendlyName() {
|
||||||
Assertions.assertEquals(R.string.triggerHeartRate, TriggerHeartRate(injector).friendlyName())
|
assertThat(TriggerHeartRate(injector).friendlyName()).isEqualTo(R.string.triggerHeartRate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -23,7 +24,7 @@ class TriggerHeartRateTest : TriggerTestBase() {
|
||||||
val t = TriggerHeartRate(injector)
|
val t = TriggerHeartRate(injector)
|
||||||
`when`(rh.gs(Comparator.Compare.IS_EQUAL_OR_GREATER.stringRes)).thenReturn(">")
|
`when`(rh.gs(Comparator.Compare.IS_EQUAL_OR_GREATER.stringRes)).thenReturn(">")
|
||||||
`when`(rh.gs(R.string.triggerHeartRateDesc, ">", 80.0)).thenReturn("test")
|
`when`(rh.gs(R.string.triggerHeartRateDesc, ">", 80.0)).thenReturn("test")
|
||||||
Assertions.assertEquals("test", t.friendlyDescription())
|
assertThat(t.friendlyDescription()).isEqualTo("test")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -33,16 +34,16 @@ class TriggerHeartRateTest : TriggerTestBase() {
|
||||||
comparator.value = Comparator.Compare.IS_GREATER
|
comparator.value = Comparator.Compare.IS_GREATER
|
||||||
}
|
}
|
||||||
val dup = t.duplicate() as TriggerHeartRate
|
val dup = t.duplicate() as TriggerHeartRate
|
||||||
Assertions.assertNotSame(t, dup)
|
assertThat(dup).isNotSameInstanceAs(t)
|
||||||
Assertions.assertEquals(100.0, dup.heartRate.value, 0.01)
|
assertThat(dup.heartRate.value).isWithin(0.01).of(100.0)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_GREATER, dup.comparator.value)
|
assertThat(dup.comparator.value).isEqualTo(Comparator.Compare.IS_GREATER)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldRunNotAvailable() {
|
fun shouldRunNotAvailable() {
|
||||||
val t = TriggerHeartRate(injector).apply { comparator.value = Comparator.Compare.IS_NOT_AVAILABLE }
|
val t = TriggerHeartRate(injector).apply { comparator.value = Comparator.Compare.IS_NOT_AVAILABLE }
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
verifyNoMoreInteractions(repository)
|
verifyNoMoreInteractions(repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ class TriggerHeartRateTest : TriggerTestBase() {
|
||||||
comparator.value = Comparator.Compare.IS_GREATER
|
comparator.value = Comparator.Compare.IS_GREATER
|
||||||
}
|
}
|
||||||
`when`(repository.getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)).thenReturn(Single.just(emptyList()))
|
`when`(repository.getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)).thenReturn(Single.just(emptyList()))
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
verify(repository).getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)
|
verify(repository).getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)
|
||||||
verifyNoMoreInteractions(repository)
|
verifyNoMoreInteractions(repository)
|
||||||
}
|
}
|
||||||
|
@ -69,7 +70,7 @@ class TriggerHeartRateTest : TriggerTestBase() {
|
||||||
HeartRate(duration = 300_000, timestamp = now, beatsPerMinute = 60.0, device = "test"),
|
HeartRate(duration = 300_000, timestamp = now, beatsPerMinute = 60.0, device = "test"),
|
||||||
)
|
)
|
||||||
`when`(repository.getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)).thenReturn(Single.just(hrs))
|
`when`(repository.getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)).thenReturn(Single.just(hrs))
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
verify(repository).getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)
|
verify(repository).getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)
|
||||||
verifyNoMoreInteractions(repository)
|
verifyNoMoreInteractions(repository)
|
||||||
}
|
}
|
||||||
|
@ -84,7 +85,7 @@ class TriggerHeartRateTest : TriggerTestBase() {
|
||||||
HeartRate(duration = 300_000, timestamp = now, beatsPerMinute = 120.0, device = "test"),
|
HeartRate(duration = 300_000, timestamp = now, beatsPerMinute = 120.0, device = "test"),
|
||||||
)
|
)
|
||||||
`when`(repository.getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)).thenReturn(Single.just(hrs))
|
`when`(repository.getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)).thenReturn(Single.just(hrs))
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
verify(repository).getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)
|
verify(repository).getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)
|
||||||
verifyNoMoreInteractions(repository)
|
verifyNoMoreInteractions(repository)
|
||||||
}
|
}
|
||||||
|
@ -95,9 +96,9 @@ class TriggerHeartRateTest : TriggerTestBase() {
|
||||||
heartRate.value = 100.0
|
heartRate.value = 100.0
|
||||||
comparator.value = Comparator.Compare.IS_GREATER
|
comparator.value = Comparator.Compare.IS_GREATER
|
||||||
}
|
}
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_GREATER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_GREATER)
|
||||||
|
|
||||||
Assertions.assertEquals("""{"data":{"comparator":"IS_GREATER","heartRate":100},"type":"TriggerHeartRate"}""".trimMargin(), t.toJSON())
|
JSONAssert.assertEquals("""{"data":{"comparator":"IS_GREATER","heartRate":100},"type":"TriggerHeartRate"}""", t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -107,7 +108,7 @@ class TriggerHeartRateTest : TriggerTestBase() {
|
||||||
"""{"data":{"comparator":"IS_GREATER","heartRate":100},"type":"TriggerHeartRate"}"""
|
"""{"data":{"comparator":"IS_GREATER","heartRate":100},"type":"TriggerHeartRate"}"""
|
||||||
)
|
)
|
||||||
) as TriggerHeartRate
|
) as TriggerHeartRate
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_GREATER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_GREATER)
|
||||||
Assertions.assertEquals(100.0, t.heartRate.value, 0.01)
|
assertThat(t.heartRate.value).isWithin(0.01).of(100.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ 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.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.ArgumentMatchers
|
import org.mockito.ArgumentMatchers
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class TriggerIobTest : TriggerTestBase() {
|
class TriggerIobTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -20,43 +20,43 @@ class TriggerIobTest : TriggerTestBase() {
|
||||||
@Test fun shouldRunTest() {
|
@Test fun shouldRunTest() {
|
||||||
`when`(iobCobCalculator.calculateFromTreatmentsAndTemps(ArgumentMatchers.anyLong(), anyObject())).thenReturn(generateIobRecordData())
|
`when`(iobCobCalculator.calculateFromTreatmentsAndTemps(ArgumentMatchers.anyLong(), anyObject())).thenReturn(generateIobRecordData())
|
||||||
var t: TriggerIob = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL)
|
var t: TriggerIob = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerIob(injector).setValue(0.8).comparator(Comparator.Compare.IS_GREATER)
|
t = TriggerIob(injector).setValue(0.8).comparator(Comparator.Compare.IS_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerIob(injector).setValue(0.8).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerIob(injector).setValue(0.8).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerIob(injector).setValue(0.9).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerIob(injector).setValue(0.9).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerIob(injector).setValue(1.2).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerIob(injector).setValue(1.2).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerIob(injector).setValue(0.9).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerIob(injector).setValue(0.9).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun copyConstructorTest() {
|
@Test fun copyConstructorTest() {
|
||||||
val t: TriggerIob = TriggerIob(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
val t: TriggerIob = TriggerIob(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertEquals(213.0, t.insulin.value, 0.01)
|
assertThat(t.insulin.value).isWithin(0.01).of(213.0)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"insulin\":4.1},\"type\":\"TriggerIob\"}"
|
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"insulin\":4.1},\"type\":\"TriggerIob\"}"
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
val t: TriggerIob = TriggerIob(injector).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerIob = TriggerIob(injector).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(bgJson, t.toJSON())
|
JSONAssert.assertEquals(bgJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun fromJSONTest() {
|
fun fromJSONTest() {
|
||||||
val t: TriggerIob = TriggerIob(injector).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerIob = TriggerIob(injector).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerIob
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerIob
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(4.1, t2.insulin.value, 0.01)
|
assertThat(t2.insulin.value).isWithin(0.01).of(4.1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
|
@ -68,4 +68,4 @@ class TriggerIobTest : TriggerTestBase() {
|
||||||
iobTotal.iob = 1.0
|
iobTotal.iob = 1.0
|
||||||
return iobTotal
|
return iobTotal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import app.aaps.plugins.automation.elements.InputLocationMode
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
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`
|
||||||
|
@ -24,10 +23,10 @@ class TriggerLocationTest : TriggerTestBase() {
|
||||||
t.distance.setValue(2.0)
|
t.distance.setValue(2.0)
|
||||||
t.modeSelected.value = InputLocationMode.Mode.INSIDE
|
t.modeSelected.value = InputLocationMode.Mode.INSIDE
|
||||||
val t1 = t.duplicate() as TriggerLocation
|
val t1 = t.duplicate() as TriggerLocation
|
||||||
Assertions.assertEquals(213.0, t1.latitude.value, 0.01)
|
assertThat(t1.latitude.value).isWithin(0.01).of(213.0)
|
||||||
Assertions.assertEquals(212.0, t1.longitude.value, 0.01)
|
assertThat(t1.longitude.value).isWithin(0.01).of(212.0)
|
||||||
Assertions.assertEquals(2.0, t1.distance.value, 0.01)
|
assertThat(t1.distance.value).isWithin(0.01).of(2.0)
|
||||||
Assertions.assertEquals(InputLocationMode.Mode.INSIDE, t1.modeSelected.value)
|
assertThat(t1.modeSelected.value).isEqualTo(InputLocationMode.Mode.INSIDE)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shouldRunTest() {
|
@Test fun shouldRunTest() {
|
||||||
|
@ -37,12 +36,12 @@ class TriggerLocationTest : TriggerTestBase() {
|
||||||
t.distance.setValue(2.0)
|
t.distance.setValue(2.0)
|
||||||
// t.modeSelected.setValue(InputLocationMode.Mode.OUTSIDE);
|
// t.modeSelected.setValue(InputLocationMode.Mode.OUTSIDE);
|
||||||
`when`(locationDataContainer.lastLocation).thenReturn(null)
|
`when`(locationDataContainer.lastLocation).thenReturn(null)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocation())
|
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocation())
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerLocation(injector)
|
t = TriggerLocation(injector)
|
||||||
t.distance.setValue(-500.0)
|
t.distance.setValue(-500.0)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
|
|
||||||
//Test of GOING_IN - last mode should be OUTSIDE, and current mode should be INSIDE
|
//Test of GOING_IN - last mode should be OUTSIDE, and current mode should be INSIDE
|
||||||
t = TriggerLocation(injector)
|
t = TriggerLocation(injector)
|
||||||
|
@ -51,9 +50,9 @@ class TriggerLocationTest : TriggerTestBase() {
|
||||||
`when`(locationDataContainer.lastLocation).thenReturn(null)
|
`when`(locationDataContainer.lastLocation).thenReturn(null)
|
||||||
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocationOut())
|
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocationOut())
|
||||||
t.modeSelected.value = InputLocationMode.Mode.GOING_IN
|
t.modeSelected.value = InputLocationMode.Mode.GOING_IN
|
||||||
Assertions.assertEquals(t.lastMode, InputLocationMode.Mode.OUTSIDE)
|
assertThat(InputLocationMode.Mode.OUTSIDE).isEqualTo(t.lastMode)
|
||||||
Assertions.assertEquals(t.currentMode(5.0), InputLocationMode.Mode.INSIDE)
|
assertThat(InputLocationMode.Mode.INSIDE).isEqualTo(t.currentMode(5.0))
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
|
|
||||||
//Test of GOING_OUT - last mode should be INSIDE, and current mode should be OUTSIDE
|
//Test of GOING_OUT - last mode should be INSIDE, and current mode should be OUTSIDE
|
||||||
// Currently unavailable due to problems with Location mocking
|
// Currently unavailable due to problems with Location mocking
|
||||||
|
@ -67,7 +66,7 @@ class TriggerLocationTest : TriggerTestBase() {
|
||||||
t.distance.setValue(2.0)
|
t.distance.setValue(2.0)
|
||||||
t.modeSelected.value = InputLocationMode.Mode.OUTSIDE
|
t.modeSelected.value = InputLocationMode.Mode.OUTSIDE
|
||||||
// t.modeSelected = t.modeSelected.value
|
// t.modeSelected = t.modeSelected.value
|
||||||
Assertions.assertEquals(locationJson, t.toJSON())
|
assertThat(t.toJSON()).isEqualTo(locationJson)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test @Throws(JSONException::class) fun fromJSONTest() {
|
@Test @Throws(JSONException::class) fun fromJSONTest() {
|
||||||
|
@ -77,18 +76,18 @@ class TriggerLocationTest : TriggerTestBase() {
|
||||||
t.distance.setValue(2.0)
|
t.distance.setValue(2.0)
|
||||||
t.modeSelected.value = InputLocationMode.Mode.INSIDE
|
t.modeSelected.value = InputLocationMode.Mode.INSIDE
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerLocation
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerLocation
|
||||||
Assertions.assertEquals(t.latitude.value, t2.latitude.value, 0.01)
|
assertThat(t2.latitude.value).isWithin(0.01).of(t.latitude.value)
|
||||||
Assertions.assertEquals(t.longitude.value, t2.longitude.value, 0.01)
|
assertThat(t2.longitude.value).isWithin(0.01).of(t.longitude.value)
|
||||||
Assertions.assertEquals(t.distance.value, t2.distance.value, 0.01)
|
assertThat(t2.distance.value).isWithin(0.01).of(t.distance.value)
|
||||||
Assertions.assertEquals(t.modeSelected.value, t2.modeSelected.value)
|
assertThat(t2.modeSelected.value).isEqualTo(t.modeSelected.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(R.string.location, TriggerLocation(injector).friendlyName())
|
assertThat(TriggerLocation(injector).friendlyName()).isEqualTo(R.string.location)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyDescriptionTest() {
|
@Test fun friendlyDescriptionTest() {
|
||||||
Assertions.assertEquals(null, TriggerLocation(injector).friendlyDescription()) //not mocked }
|
assertThat(TriggerLocation(injector).friendlyDescription()).isNull() //not mocked }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
|
@ -110,4 +109,4 @@ class TriggerLocationTest : TriggerTestBase() {
|
||||||
newLocation.accuracy = 1f
|
newLocation.accuracy = 1f
|
||||||
return newLocation
|
return newLocation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,10 @@ 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.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 TriggerProfilePercentTest : TriggerTestBase() {
|
class TriggerProfilePercentTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -17,43 +17,43 @@ class TriggerProfilePercentTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test fun shouldRunTest() {
|
@Test fun shouldRunTest() {
|
||||||
var t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(101.0).comparator(Comparator.Compare.IS_EQUAL)
|
var t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(101.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerProfilePercent(injector).setValue(90.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerProfilePercent(injector).setValue(90.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerProfilePercent(injector).setValue(101.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerProfilePercent(injector).setValue(101.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerProfilePercent(injector).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerProfilePercent(injector).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerProfilePercent(injector).setValue(110.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerProfilePercent(injector).setValue(110.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerProfilePercent(injector).setValue(90.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerProfilePercent(injector).setValue(90.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun copyConstructorTest() {
|
@Test fun copyConstructorTest() {
|
||||||
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
val t1 = t.duplicate() as TriggerProfilePercent
|
val t1 = t.duplicate() as TriggerProfilePercent
|
||||||
Assertions.assertEquals(213.0, t1.pct.value, 0.01)
|
assertThat( t1.pct.value).isWithin(0.01).of(213.0)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"percentage\":110},\"type\":\"TriggerProfilePercent\"}"
|
private val bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"percentage\":110},\"type\":\"TriggerProfilePercent\"}"
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(110.0).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(110.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(bgJson, t.toJSON())
|
JSONAssert.assertEquals(bgJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun fromJSONTest() {
|
@Test fun fromJSONTest() {
|
||||||
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(120.0).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(120.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerProfilePercent
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerProfilePercent
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(120.0, t2.pct.value, 0.01)
|
assertThat(t2.pct.value).isWithin(0.01).of(120.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
|
@ -61,6 +61,6 @@ class TriggerProfilePercentTest : TriggerTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(R.string.profilepercentage, TriggerProfilePercent(injector).friendlyName()) // not mocked
|
assertThat(TriggerProfilePercent(injector).friendlyName()).isEqualTo(R.string.profilepercentage) // not mocked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@ package app.aaps.plugins.automation.triggers
|
||||||
|
|
||||||
import app.aaps.core.interfaces.utils.MidnightTime
|
import app.aaps.core.interfaces.utils.MidnightTime
|
||||||
import app.aaps.core.interfaces.utils.T
|
import app.aaps.core.interfaces.utils.T
|
||||||
|
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
|
import org.mockito.Mockito
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class TriggerRecurringTimeTest : TriggerTestBase() {
|
class TriggerRecurringTimeTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -19,12 +20,12 @@ class TriggerRecurringTimeTest : TriggerTestBase() {
|
||||||
|
|
||||||
var t: TriggerRecurringTime = TriggerRecurringTime(injector).time(89)
|
var t: TriggerRecurringTime = TriggerRecurringTime(injector).time(89)
|
||||||
t.days.setAll(true)
|
t.days.setAll(true)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
|
|
||||||
// scheduled 1 min before
|
// scheduled 1 min before
|
||||||
t = TriggerRecurringTime(injector).time(94)
|
t = TriggerRecurringTime(injector).time(94)
|
||||||
t.days.setAll(true)
|
t.days.setAll(true)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var timeJson =
|
private var timeJson =
|
||||||
|
@ -33,13 +34,13 @@ class TriggerRecurringTimeTest : TriggerTestBase() {
|
||||||
@Test
|
@Test
|
||||||
fun toJSONTest() {
|
fun toJSONTest() {
|
||||||
val t = TriggerRecurringTime(injector).time(4444)
|
val t = TriggerRecurringTime(injector).time(4444)
|
||||||
Assertions.assertEquals(timeJson, t.toJSON())
|
JSONAssert.assertEquals(timeJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun fromJSONTest() {
|
fun fromJSONTest() {
|
||||||
val t = TriggerRecurringTime(injector).time(4444)
|
val t = TriggerRecurringTime(injector).time(4444)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerRecurringTime
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerRecurringTime
|
||||||
Assertions.assertEquals(4444, t2.time.value)
|
assertThat(t2.time.value).isEqualTo(4444)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import app.aaps.plugins.automation.R
|
||||||
import app.aaps.plugins.automation.elements.ComparatorExists
|
import app.aaps.plugins.automation.elements.ComparatorExists
|
||||||
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.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class TriggerTempTargetTest : TriggerTestBase() {
|
class TriggerTempTargetTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -13,36 +13,36 @@ class TriggerTempTargetTest : TriggerTestBase() {
|
||||||
@Test fun shouldRunTest() {
|
@Test fun shouldRunTest() {
|
||||||
`when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(null)
|
`when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(null)
|
||||||
var t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
|
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)
|
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))
|
`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)
|
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
|
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@Test fun copyConstructorTest() {
|
@Test fun copyConstructorTest() {
|
||||||
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
|
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
|
||||||
val t1 = t.duplicate() as TriggerTempTarget
|
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\"}"
|
private var ttJson = "{\"data\":{\"comparator\":\"EXISTS\"},\"type\":\"TriggerTempTarget\"}"
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
|
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
|
||||||
Assertions.assertEquals(ttJson, t.toJSON())
|
JSONAssert.assertEquals(ttJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun fromJSONTest() {
|
fun fromJSONTest() {
|
||||||
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
|
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTarget
|
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() {
|
@Test fun iconTest() {
|
||||||
assertThat(TriggerTempTarget(injector).icon().get()).isEqualTo(R.drawable.ic_keyboard_tab)
|
assertThat(TriggerTempTarget(injector).icon().get()).isEqualTo(R.drawable.ic_keyboard_tab)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,10 @@ import app.aaps.plugins.automation.elements.Comparator
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
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 TriggerTempTargetValueTest : TriggerTestBase() {
|
class TriggerTempTargetValueTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -36,37 +36,37 @@ class TriggerTempTargetValueTest : TriggerTestBase() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
var t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
var t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerTempTargetValue(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
t = TriggerTempTargetValue(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
`when`(repository.getTemporaryTargetActiveAt(dateUtil.now())).thenReturn(Single.just(ValueWrapper.Absent()))
|
`when`(repository.getTemporaryTargetActiveAt(dateUtil.now())).thenReturn(Single.just(ValueWrapper.Absent()))
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun copyConstructorTest() {
|
fun copyConstructorTest() {
|
||||||
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
val t1 = t.duplicate() as TriggerTempTargetValue
|
val t1 = t.duplicate() as TriggerTempTargetValue
|
||||||
Assertions.assertEquals(140.0, t1.ttValue.value, 0.01)
|
assertThat(t1.ttValue.value).isWithin(0.01).of(140.0)
|
||||||
Assertions.assertEquals(GlucoseUnit.MGDL, t1.ttValue.units)
|
assertThat(t1.ttValue.units).isEqualTo(GlucoseUnit.MGDL)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var ttJson = "{\"data\":{\"tt\":7.7,\"comparator\":\"IS_EQUAL\",\"units\":\"mmol\"},\"type\":\"TriggerTempTargetValue\"}"
|
private var ttJson = "{\"data\":{\"tt\":7.7,\"comparator\":\"IS_EQUAL\",\"units\":\"mmol\"},\"type\":\"TriggerTempTargetValue\"}"
|
||||||
|
@ -74,16 +74,16 @@ class TriggerTempTargetValueTest : TriggerTestBase() {
|
||||||
@Test
|
@Test
|
||||||
fun toJSONTest() {
|
fun toJSONTest() {
|
||||||
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(ttJson, t.toJSON())
|
JSONAssert.assertEquals(ttJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun fromJSONTest() {
|
fun fromJSONTest() {
|
||||||
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTargetValue
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTargetValue
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(7.7, t2.ttValue.value, 0.01)
|
assertThat(t2.ttValue.value).isWithin(0.01).of(7.7)
|
||||||
Assertions.assertEquals(GlucoseUnit.MMOL, t2.ttValue.units)
|
assertThat(t2.ttValue.units).isEqualTo(GlucoseUnit.MMOL)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@ import app.aaps.plugins.automation.elements.Comparator
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
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 TriggerWifiSsidTest : TriggerTestBase() {
|
class TriggerWifiSsidTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -17,40 +17,40 @@ class TriggerWifiSsidTest : TriggerTestBase() {
|
||||||
`when`(receiverStatusStore.lastNetworkEvent).thenReturn(e)
|
`when`(receiverStatusStore.lastNetworkEvent).thenReturn(e)
|
||||||
var t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID 1").comparator(Comparator.Compare.IS_EQUAL)
|
var t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID 1").comparator(Comparator.Compare.IS_EQUAL)
|
||||||
e.wifiConnected = false
|
e.wifiConnected = false
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
e.wifiConnected = true
|
e.wifiConnected = true
|
||||||
e.ssid = "otherSSID"
|
e.ssid = "otherSSID"
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
e.wifiConnected = true
|
e.wifiConnected = true
|
||||||
e.ssid = "aSSID 1"
|
e.ssid = "aSSID 1"
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerWifiSsid(injector).setValue("aSSID 1").comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
t = TriggerWifiSsid(injector).setValue("aSSID 1").comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
||||||
e.wifiConnected = false
|
e.wifiConnected = false
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
|
|
||||||
// no network data
|
// no network data
|
||||||
`when`(receiverStatusStore.lastNetworkEvent).thenReturn(null)
|
`when`(receiverStatusStore.lastNetworkEvent).thenReturn(null)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun copyConstructorTest() {
|
@Test fun copyConstructorTest() {
|
||||||
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
val t1 = t.duplicate() as TriggerWifiSsid
|
val t1 = t.duplicate() as TriggerWifiSsid
|
||||||
Assertions.assertEquals("aSSID", t1.ssid.value)
|
assertThat(t1.ssid.value).isEqualTo("aSSID")
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
}
|
}
|
||||||
|
|
||||||
var json = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"ssid\":\"aSSID\"},\"type\":\"TriggerWifiSsid\"}"
|
var json = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"ssid\":\"aSSID\"},\"type\":\"TriggerWifiSsid\"}"
|
||||||
@Test fun toJSONTest() {
|
@Test fun toJSONTest() {
|
||||||
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(json, t.toJSON())
|
JSONAssert.assertEquals(json, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test @Throws(JSONException::class) fun fromJSONTest() {
|
@Test @Throws(JSONException::class) fun fromJSONTest() {
|
||||||
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerWifiSsid
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerWifiSsid
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals("aSSID", t2.ssid.value)
|
assertThat(t2.ssid.value).isEqualTo("aSSID")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
|
@ -58,10 +58,10 @@ class TriggerWifiSsidTest : TriggerTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyNameTest() {
|
@Test fun friendlyNameTest() {
|
||||||
Assertions.assertEquals(app.aaps.core.ui.R.string.ns_wifi_ssids, TriggerWifiSsid(injector).friendlyName())
|
assertThat(TriggerWifiSsid(injector).friendlyName()).isEqualTo(app.aaps.core.ui.R.string.ns_wifi_ssids)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun friendlyDescriptionTest() {
|
@Test fun friendlyDescriptionTest() {
|
||||||
Assertions.assertEquals(null, TriggerWifiSsid(injector).friendlyDescription()) //not mocked
|
assertThat(TriggerWifiSsid(injector).friendlyDescription()).isNull() //not mocked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue