Merge pull request #2869 from ryanhaining/assertthat_plugins_automation

Rewrites plugins/automation tests with matchers
This commit is contained in:
Milos Kozak 2023-10-05 10:25:17 +02:00 committed by GitHub
commit a4ee36f0eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 498 additions and 497 deletions

View file

@ -10,12 +10,13 @@ import app.aaps.plugins.automation.triggers.TriggerConnector
import app.aaps.plugins.automation.triggers.TriggerConnectorTest
import app.aaps.plugins.automation.triggers.TriggerDummy
import app.aaps.shared.tests.TestBase
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mock
import org.skyscreamer.jsonassert.JSONAssert
class AutomationEventTest : TestBase() {
@ -40,8 +41,7 @@ class AutomationEventTest : TestBase() {
}
}
@Test
fun testCloneEvent() {
@Test fun testCloneEvent() {
// create test object
val event = AutomationEventObject(injector)
event.title = "Test"
@ -51,33 +51,32 @@ class AutomationEventTest : TestBase() {
// export to json
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}"
Assertions.assertEquals(eventJsonExpected, event.toJSON())
JSONAssert.assertEquals(eventJsonExpected, event.toJSON(), true)
// clone
val clone = AutomationEventObject(injector).fromJSON(eventJsonExpected, 1)
// check title
Assertions.assertEquals(event.title, clone.title)
assertThat(clone.title).isEqualTo(event.title)
// check trigger
Assertions.assertNotNull(clone.trigger)
Assertions.assertFalse(event.trigger === clone.trigger) // not the same object reference
Assertions.assertEquals(event.trigger.javaClass, clone.trigger.javaClass)
Assertions.assertEquals(event.trigger.toJSON(), clone.trigger.toJSON())
assertThat(clone.trigger).isNotNull()
assertThat(event.trigger).isNotSameInstanceAs(clone.trigger)
assertThat(event.trigger.javaClass).isNotInstanceOf(clone.trigger.javaClass)
JSONAssert.assertEquals(event.trigger.toJSON(), clone.trigger.toJSON(), true)
// check action
Assertions.assertEquals(1, clone.actions.size)
Assertions.assertFalse(event.actions === clone.actions) // not the same object reference
Assertions.assertEquals(clone.toJSON(), clone.toJSON())
assertThat(clone.actions).hasSize(1)
assertThat(event.actions).isNotSameInstanceAs(clone.actions)
JSONAssert.assertEquals(clone.toJSON(), clone.toJSON(), true)
}
@Test
fun hasStopProcessing() {
@Test fun hasStopProcessing() {
val event = AutomationEventObject(injector)
event.title = "Test"
event.trigger = TriggerDummy(injector).instantiate(JSONObject(TriggerConnectorTest().oneItem)) as TriggerConnector
Assertions.assertFalse(event.hasStopProcessing())
assertThat(event.hasStopProcessing()).isFalse()
event.addAction(ActionStopProcessing(injector))
Assertions.assertTrue(event.hasStopProcessing())
assertThat(event.hasStopProcessing()).isTrue()
}
}

View file

@ -16,9 +16,9 @@ import app.aaps.plugins.automation.triggers.Trigger
import app.aaps.plugins.automation.ui.TimerUtil
import app.aaps.shared.impl.utils.DateUtilImpl
import app.aaps.shared.tests.TestBase
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyInt
@ -63,10 +63,10 @@ class BolusTimerImplTest : TestBase() {
@Test
fun doTest() {
Assertions.assertEquals(0, automationPlugin.size())
assertThat(automationPlugin.size()).isEqualTo(0)
automationPlugin.scheduleAutomationEventBolusReminder()
Assertions.assertEquals(1, automationPlugin.size())
assertThat(automationPlugin.size()).isEqualTo(1)
automationPlugin.removeAutomationEventBolusReminder()
Assertions.assertEquals(0, automationPlugin.size())
assertThat(automationPlugin.size()).isEqualTo(0)
}
}
}

View file

@ -16,9 +16,9 @@ import app.aaps.plugins.automation.triggers.Trigger
import app.aaps.plugins.automation.ui.TimerUtil
import app.aaps.shared.impl.utils.DateUtilImpl
import app.aaps.shared.tests.TestBase
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.any
@ -52,27 +52,24 @@ class CarbTimerImplTest : TestBase() {
private lateinit var automationPlugin: AutomationPlugin
@BeforeEach
fun init() {
@BeforeEach fun init() {
Mockito.`when`(rh.gs(anyInt())).thenReturn("")
Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
dateUtil = DateUtilImpl(context)
timerUtil = TimerUtil(context)
automationPlugin = AutomationPlugin(
injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil,
activePlugin, timerUtil
injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, activePlugin, timerUtil
)
}
@Test
fun doTest() {
Assertions.assertEquals(0, automationPlugin.size())
@Test fun doTest() {
assertThat(automationPlugin.size()).isEqualTo(0)
automationPlugin.scheduleAutomationEventEatReminder()
Assertions.assertEquals(1, automationPlugin.size())
assertThat(automationPlugin.size()).isEqualTo(1)
automationPlugin.removeAutomationEventEatReminder()
Assertions.assertEquals(0, automationPlugin.size())
assertThat(automationPlugin.size()).isEqualTo(0)
automationPlugin.scheduleTimeToEatReminder(1)
Mockito.verify(context, Mockito.times(1)).startActivity(any())
}
}
}

View file

@ -4,14 +4,14 @@ import app.aaps.plugins.automation.triggers.Trigger
import app.aaps.plugins.automation.triggers.TriggerConnector
import app.aaps.plugins.automation.triggers.TriggerDummy
import app.aaps.shared.tests.TestBase
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ComposeTriggerTest : TestBase() {
var injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { } }
val injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { } }
@Test fun testTriggerList() {
val root = TriggerConnector(injector)
@ -23,16 +23,11 @@ class ComposeTriggerTest : TestBase() {
root.list.add(t1)
val t2: Trigger = TriggerDummy(injector)
root.list.add(t2)
Assertions.assertEquals(3, root.size())
Assertions.assertEquals(t0, root.list[0])
Assertions.assertEquals(t1, root.list[1])
Assertions.assertEquals(t2, root.list[2])
assertThat(root.list).containsExactly(t0, t1, t2).inOrder()
// remove a trigger
root.list.remove(t1)
Assertions.assertEquals(2, root.size())
Assertions.assertEquals(t0, root.list[0])
Assertions.assertEquals(t2, root.list[1])
assertThat(root.list).containsExactly(t0, t2).inOrder()
}
@Test
@ -44,6 +39,6 @@ class ComposeTriggerTest : TestBase() {
t[i] = TriggerDummy(injector)
root.list.add(t[i]!!)
}
Assertions.assertEquals(4, root.size())
assertThat(root.size()).isEqualTo(4)
}
}
}

View file

@ -10,14 +10,15 @@ import app.aaps.plugins.automation.R
import app.aaps.plugins.automation.elements.InputString
import app.aaps.plugins.automation.ui.TimerUtil
import app.aaps.shared.tests.TestBase
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class ActionAlarmTest : TestBase() {
@ -54,39 +55,39 @@ class ActionAlarmTest : TestBase() {
}
@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() {
sut.text = InputString("Asd")
Assertions.assertEquals("Alarm: %s", sut.shortDescription())
assertThat(sut.shortDescription()).isEqualTo("Alarm: %s")
}
@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() {
sut.text = InputString("Asd")
sut.doAction(object : Callback() {
override fun run() {
Assertions.assertTrue(result.success)
assertThat(result.success).isTrue()
}
})
}
@Test fun hasDialogTest() {
Assertions.assertTrue(sut.hasDialog())
assertThat(sut.hasDialog()).isTrue()
}
@Test fun toJSONTest() {
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() {
sut.text = InputString("Asd")
sut.fromJSON("{\"text\":\"Asd\"}")
Assertions.assertEquals("Asd", sut.text.value)
sut.fromJSON("""{"text":"Asd"}""")
assertThat(sut.text.value).isEqualTo("Asd")
}
}
}

View file

@ -8,11 +8,12 @@ import app.aaps.plugins.automation.elements.InputCarePortalMenu
import app.aaps.plugins.automation.elements.InputDuration
import app.aaps.plugins.automation.elements.InputString
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.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class ActionCarePortalEventTest : ActionsTestBase() {
@ -35,41 +36,42 @@ class ActionCarePortalEventTest : ActionsTestBase() {
}
@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() {
Assertions.assertEquals("Note : Asd", sut.shortDescription())
assertThat(sut.shortDescription()).isEqualTo("Note : Asd")
}
@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() {
sut.doAction(object : Callback() {
override fun run() {
Assertions.assertTrue(result.success)
assertThat(result.success).isTrue()
}
})
}
@Test fun hasDialogTest() {
Assertions.assertTrue(sut.hasDialog())
assertThat(sut.hasDialog()).isTrue()
}
@Test fun toJSONTest() {
Assertions.assertEquals(
"{\"data\":{\"note\":\"Asd\",\"cpEvent\":\"NOTE\",\"durationInMinutes\":5},\"type\":\"ActionCarePortalEvent\"}",
sut.toJSON()
JSONAssert.assertEquals(
"""{"data":{"note":"Asd","cpEvent":"NOTE","durationInMinutes":5},"type":"ActionCarePortalEvent"}""",
sut.toJSON(),
true,
)
}
@Test fun fromJSONTest() {
sut.note = InputString("Asd")
sut.fromJSON("{\"note\":\"Asd\",\"cpEvent\":\"NOTE\",\"durationInMinutes\":5}")
Assertions.assertEquals("Asd", sut.note.value)
Assertions.assertEquals(5, sut.duration.value)
Assertions.assertEquals(InputCarePortalMenu.EventType.NOTE, sut.cpEvent.value)
sut.fromJSON("""{"note":"Asd","cpEvent":"NOTE","durationInMinutes":5}""")
assertThat(sut.note.value).isEqualTo("Asd")
assertThat(sut.duration.value).isEqualTo(5)
assertThat(sut.cpEvent.value).isEqualTo(InputCarePortalMenu.EventType.NOTE)
}
}
}

View file

@ -1,20 +1,20 @@
package app.aaps.plugins.automation.actions
import kotlin.test.assertIs
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ActionDummyTest : ActionsTestBase() {
@Test
fun instantiateTest() {
var action: Action? = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy\"}"))
Assertions.assertTrue(action is ActionDummy)
var action: Action? = ActionDummy(injector).instantiate(JSONObject("""{"type":"info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy"}"""))
assertIs<ActionDummy>(action)
action = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"app.aaps.plugins.automation.actions.ActionDummy\"}"))
Assertions.assertTrue(action is ActionDummy)
action = ActionDummy(injector).instantiate(JSONObject("""{"type":"app.aaps.plugins.automation.actions.ActionDummy"}"""))
assertIs<ActionDummy>(action)
action = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"ActionDummy\"}"))
Assertions.assertTrue(action is ActionDummy)
action = ActionDummy(injector).instantiate(JSONObject("""{"type":"ActionDummy"}"""))
assertIs<ActionDummy>(action)
}
}
}

View file

@ -3,7 +3,7 @@ package app.aaps.plugins.automation.actions
import app.aaps.core.interfaces.plugin.PluginType
import app.aaps.core.interfaces.queue.Callback
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.Test
import org.mockito.ArgumentMatchers.eq
@ -27,17 +27,17 @@ class ActionLoopDisableTest : ActionsTestBase() {
@Test
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
fun shortDescriptionTest() {
Assertions.assertEquals("Disable loop", sut.shortDescription())
assertThat(sut.shortDescription()).isEqualTo("Disable loop")
}
@Test
fun iconTest() {
Assertions.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
assertThat(sut.icon()).isEqualTo(R.drawable.ic_stop_24dp)
}
@Test
@ -60,4 +60,4 @@ class ActionLoopDisableTest : ActionsTestBase() {
Mockito.verify(configBuilder, Mockito.times(1)).storeSettings("ActionLoopDisable")
Mockito.verify(commandQueue, Mockito.times(1)).cancelTempBasal(eq(true), anyObject())
}
}
}

View file

@ -3,7 +3,7 @@ package app.aaps.plugins.automation.actions
import app.aaps.core.interfaces.plugin.PluginType
import app.aaps.core.interfaces.queue.Callback
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.Test
import org.mockito.Mockito
@ -24,15 +24,15 @@ class ActionLoopEnableTest : ActionsTestBase() {
}
@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() {
Assertions.assertEquals("Enable loop", sut.shortDescription())
assertThat(sut.shortDescription()).isEqualTo("Enable loop")
}
@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() {
@ -52,4 +52,4 @@ class ActionLoopEnableTest : ActionsTestBase() {
Mockito.verify(loopPlugin, Mockito.times(1)).setPluginEnabled(PluginType.LOOP, true)
Mockito.verify(configBuilder, Mockito.times(1)).storeSettings("ActionLoopEnable")
}
}
}

View file

@ -6,7 +6,7 @@ import app.aaps.database.impl.transactions.CancelCurrentOfflineEventIfAnyTransac
import app.aaps.database.impl.transactions.Transaction
import app.aaps.plugins.automation.R
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.Test
import org.mockito.Mockito.`when`
@ -25,15 +25,15 @@ class ActionLoopResumeTest : ActionsTestBase() {
}
@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() {
Assertions.assertEquals("Resume loop", sut.shortDescription())
assertThat(sut.shortDescription()).isEqualTo("Resume loop")
}
@Test fun iconTest() {
Assertions.assertEquals(R.drawable.ic_replay_24dp, sut.icon())
assertThat(sut.icon()).isEqualTo(R.drawable.ic_replay_24dp)
}
@Test fun doActionTest() {
@ -64,4 +64,4 @@ class ActionLoopResumeTest : ActionsTestBase() {
})
//Mockito.verify(loopPlugin, Mockito.times(1)).suspendTo(0)
}
}
}

View file

@ -3,7 +3,7 @@ package app.aaps.plugins.automation.actions
import app.aaps.core.interfaces.queue.Callback
import app.aaps.plugins.automation.R
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.Test
import org.mockito.Mockito
@ -24,16 +24,16 @@ class ActionLoopSuspendTest : ActionsTestBase() {
}
@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() {
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() {
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() {
@ -57,11 +57,11 @@ class ActionLoopSuspendTest : ActionsTestBase() {
a.minutes = InputDuration(20, InputDuration.TimeUnit.MINUTES)
val b = ActionLoopSuspend(injector)
b.apply(a)
Assertions.assertEquals(20, b.minutes.getMinutes().toLong())
assertThat(b.minutes.getMinutes().toLong()).isEqualTo(20)
}
@Test fun hasDialogTest() {
val a = ActionLoopSuspend(injector)
Assertions.assertTrue(a.hasDialog())
assertThat(a.hasDialog()).isTrue()
}
}
}

View file

@ -14,13 +14,14 @@ import app.aaps.shared.tests.TestBase
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
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.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class ActionNotificationTest : TestBase() {
@ -60,22 +61,22 @@ class ActionNotificationTest : TestBase() {
}
@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() {
sut.text = InputString("Asd")
Assertions.assertEquals("Notification: %s", sut.shortDescription())
assertThat(sut.shortDescription()).isEqualTo("Notification: %s")
}
@Test fun iconTest() {
Assertions.assertEquals(R.drawable.ic_notifications, sut.icon())
assertThat(sut.icon()).isEqualTo(R.drawable.ic_notifications)
}
@Test fun doActionTest() {
sut.doAction(object : Callback() {
override fun run() {
Assertions.assertTrue(result.success)
assertThat(result.success).isTrue()
}
})
Mockito.verify(rxBusMocked, Mockito.times(2)).send(anyObject())
@ -83,20 +84,21 @@ class ActionNotificationTest : TestBase() {
}
@Test fun hasDialogTest() {
Assertions.assertTrue(sut.hasDialog())
assertThat(sut.hasDialog())
}
@Test fun toJSONTest() {
sut.text = InputString("Asd")
Assertions.assertEquals(
"{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionNotification\"}",
sut.toJSON()
JSONAssert.assertEquals(
"""{"data":{"text":"Asd"},"type":"ActionNotification"}""",
sut.toJSON(),
true,
)
}
@Test fun fromJSONTest() {
sut.text = InputString("Asd")
sut.fromJSON("{\"text\":\"Asd\"}")
Assertions.assertEquals("Asd", sut.text.value)
sut.fromJSON("""{"text":"Asd"}""")
assertThat(sut.text.value).isEqualTo("Asd")
}
}
}

View file

@ -4,11 +4,12 @@ import app.aaps.core.interfaces.queue.Callback
import app.aaps.plugins.automation.R
import app.aaps.plugins.automation.elements.InputDuration
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.Test
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class ActionProfileSwitchPercentTest : ActionsTestBase() {
@ -24,17 +25,17 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() {
}
@Test fun friendlyNameTest() {
Assertions.assertEquals(R.string.profilepercentage, sut.friendlyName())
assertThat(sut.friendlyName()).isEqualTo(R.string.profilepercentage)
}
@Test fun shortDescriptionTest() {
sut.pct = InputPercent(100.0)
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() {
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() {
@ -43,25 +44,25 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() {
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
sut.doAction(object : Callback() {
override fun run() {
Assertions.assertTrue(result.success)
assertThat(result.success).isTrue()
}
})
Mockito.verify(profileFunction, Mockito.times(1)).createProfileSwitch(30, 110, 0)
}
@Test fun hasDialogTest() {
Assertions.assertTrue(sut.hasDialog())
assertThat(sut.hasDialog()).isTrue()
}
@Test fun toJSONTest() {
sut.pct = InputPercent(100.0)
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() {
sut.fromJSON("{\"percentage\":100,\"durationInMinutes\":30}")
Assertions.assertEquals(100.0, sut.pct.value, 0.001)
Assertions.assertEquals(30.0, sut.duration.getMinutes().toDouble(), 0.001)
sut.fromJSON("""{"percentage":100,"durationInMinutes":30}""")
assertThat(sut.pct.value).isWithin(0.001).of(100.0)
assertThat(sut.duration.getMinutes().toDouble()).isWithin(0.001).of(30.0)
}
}
}

View file

@ -3,7 +3,7 @@ package app.aaps.plugins.automation.actions
import app.aaps.core.interfaces.queue.Callback
import app.aaps.plugins.automation.R
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.Test
import org.mockito.ArgumentMatchers.anyLong
@ -11,13 +11,14 @@ import org.mockito.Mockito
import org.mockito.Mockito.anyInt
import org.mockito.Mockito.anyString
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
private const val STRING_JSON = """{"data":{"profileToSwitchTo":"Test"},"type":"ActionProfileSwitch"}"""
class ActionProfileSwitchTest : ActionsTestBase() {
private lateinit var sut: ActionProfileSwitch
private val stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"ActionProfileSwitch\"}"
@BeforeEach fun setUp() {
`when`(rh.gs(R.string.profilename)).thenReturn("Change profile to")
`when`(rh.gs(R.string.changengetoprofilename)).thenReturn("Change profile to %s")
@ -30,11 +31,11 @@ class ActionProfileSwitchTest : ActionsTestBase() {
}
@Test fun friendlyName() {
Assertions.assertEquals(R.string.profilename, sut.friendlyName())
assertThat(sut.friendlyName()).isEqualTo(R.string.profilename)
}
@Test fun shortDescriptionTest() {
Assertions.assertEquals("Change profile to ", sut.shortDescription())
assertThat(sut.shortDescription()).isEqualTo("Change profile to ")
}
@Test fun doAction() {
@ -43,7 +44,7 @@ class ActionProfileSwitchTest : ActionsTestBase() {
sut.inputProfileName = InputProfileName(rh, activePlugin, "")
sut.doAction(object : Callback() {
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.doAction(object : Callback() {
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.doAction(object : Callback() {
override fun run() {
Assertions.assertTrue(result.success)
Assertions.assertEquals("Already set", result.comment)
assertThat(result.success).isTrue()
assertThat(result.comment).isEqualTo("Already set")
}
})
@ -72,8 +73,8 @@ class ActionProfileSwitchTest : ActionsTestBase() {
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
sut.doAction(object : Callback() {
override fun run() {
Assertions.assertFalse(result.success)
Assertions.assertEquals("not exists", result.comment)
assertThat(result.success).isFalse()
assertThat(result.comment).isEqualTo("not exists")
}
})
@ -83,29 +84,28 @@ class ActionProfileSwitchTest : ActionsTestBase() {
sut.inputProfileName = InputProfileName(rh, activePlugin, TESTPROFILENAME)
sut.doAction(object : Callback() {
override fun run() {
Assertions.assertTrue(result.success)
Assertions.assertEquals("OK", result.comment)
assertThat(result.success).isTrue()
assertThat(result.comment).isEqualTo("OK")
}
})
Mockito.verify(profileFunction, Mockito.times(1)).createProfileSwitch(anyObject(), anyString(), anyInt(), anyInt(), anyInt(), anyLong())
}
@Test fun hasDialogTest() {
Assertions.assertTrue(sut.hasDialog())
assertThat(sut.hasDialog()).isTrue()
}
@Test fun toJSONTest() {
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
Assertions.assertEquals(stringJson, sut.toJSON())
JSONAssert.assertEquals(STRING_JSON, sut.toJSON(), true)
}
@Test fun fromJSONTest() {
val data = "{\"profileToSwitchTo\":\"Test\"}"
sut.fromJSON(data)
Assertions.assertEquals("Test", sut.inputProfileName.value)
sut.fromJSON("""{"profileToSwitchTo":"Test"}""")
assertThat(sut.inputProfileName.value).isEqualTo("Test")
}
@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)
}
}
}

View file

@ -3,11 +3,12 @@ package app.aaps.plugins.automation.actions
import app.aaps.core.interfaces.queue.Callback
import app.aaps.plugins.automation.R
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.Test
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class ActionSendSMSTest : ActionsTestBase() {
@ -23,15 +24,15 @@ class ActionSendSMSTest : ActionsTestBase() {
}
@Test fun friendlyNameTest() {
Assertions.assertEquals(R.string.sendsmsactiondescription, sut.friendlyName())
assertThat(sut.friendlyName()).isEqualTo(R.string.sendsmsactiondescription)
}
@Test fun shortDescriptionTest() {
Assertions.assertEquals("Send SMS: ", sut.shortDescription())
assertThat(sut.shortDescription()).isEqualTo("Send SMS: ")
}
@Test fun iconTest() {
Assertions.assertEquals(R.drawable.ic_notifications, sut.icon())
assertThat(sut.icon()).isEqualTo(R.drawable.ic_notifications)
}
@Test fun doActionTest() {
@ -39,22 +40,22 @@ class ActionSendSMSTest : ActionsTestBase() {
sut.text = InputString("Asd")
sut.doAction(object : Callback() {
override fun run() {
Assertions.assertTrue(result.success)
assertThat(result.success).isTrue()
}
})
}
@Test fun hasDialogTest() {
Assertions.assertTrue(sut.hasDialog())
assertThat(sut.hasDialog()).isTrue()
}
@Test fun toJSONTest() {
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() {
sut.fromJSON("{\"text\":\"Asd\"}")
Assertions.assertEquals("Asd", sut.text.value)
sut.fromJSON("""{"text":"Asd"}""")
assertThat(sut.text.value).isEqualTo("Asd")
}
}
}

View file

@ -9,11 +9,12 @@ import app.aaps.plugins.automation.R
import app.aaps.plugins.automation.elements.InputDuration
import app.aaps.plugins.automation.elements.InputTempTarget
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.Test
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class ActionStartTempTargetTest : ActionsTestBase() {
@ -27,18 +28,18 @@ class ActionStartTempTargetTest : ActionsTestBase() {
}
@Test fun friendlyNameTest() {
Assertions.assertEquals(R.string.starttemptarget, sut.friendlyName())
assertThat(sut.friendlyName()).isEqualTo(R.string.starttemptarget)
}
@Test fun shortDescriptionTest() {
sut.value = InputTempTarget(profileFunction)
sut.value.value = 100.0
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() {
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() {
@ -78,27 +79,27 @@ class ActionStartTempTargetTest : ActionsTestBase() {
sut.doAction(object : Callback() {
override fun run() {
Assertions.assertTrue(result.success)
assertThat(result.success).isTrue()
}
})
Mockito.verify(repository, Mockito.times(1)).runTransactionForResult(anyObject<Transaction<InsertAndCancelCurrentTemporaryTargetTransaction.TransactionResult>>())
}
@Test fun hasDialogTest() {
Assertions.assertTrue(sut.hasDialog())
assertThat(sut.hasDialog()).isTrue()
}
@Test fun toJSONTest() {
sut.value = InputTempTarget(profileFunction)
sut.value.value = 100.0
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() {
sut.fromJSON("{\"value\":100,\"durationInMinutes\":30,\"units\":\"mg/dl\"}")
Assertions.assertEquals(GlucoseUnit.MGDL, sut.value.units)
Assertions.assertEquals(100.0, sut.value.value, 0.001)
Assertions.assertEquals(30.0, sut.duration.getMinutes().toDouble(), 0.001)
sut.fromJSON("""{"value":100,"durationInMinutes":30,"units":"mg/dl"}""")
assertThat(sut.value.units).isEqualTo(GlucoseUnit.MGDL)
assertThat(sut.value.value).isWithin(0.001).of(100.0)
assertThat(sut.duration.getMinutes().toDouble()).isWithin(0.001).of(30.0)
}
}
}

View file

@ -2,7 +2,7 @@ package app.aaps.plugins.automation.actions
import app.aaps.core.interfaces.queue.Callback
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.Test
import org.mockito.Mockito.`when`
@ -20,25 +20,25 @@ class ActionStopProcessingTest : ActionsTestBase() {
@Test
fun friendlyNameTest() {
Assertions.assertEquals(R.string.stop_processing, sut.friendlyName())
assertThat(sut.friendlyName()).isEqualTo(R.string.stop_processing)
}
@Test
fun shortDescriptionTest() {
Assertions.assertEquals("Stop processing", sut.shortDescription())
assertThat(sut.shortDescription()).isEqualTo("Stop processing")
}
@Test
fun iconTest() {
Assertions.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
assertThat(sut.icon()).isEqualTo(R.drawable.ic_stop_24dp)
}
@Test
fun doActionTest() {
sut.doAction(object : Callback() {
override fun run() {
Assertions.assertTrue(result.success)
assertThat(result.success).isTrue()
}
})
}
}
}

View file

@ -6,11 +6,12 @@ import app.aaps.database.impl.transactions.CancelCurrentTemporaryTargetIfAnyTran
import app.aaps.database.impl.transactions.Transaction
import app.aaps.plugins.automation.R
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.Test
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class ActionStopTempTargetTest : ActionsTestBase() {
@ -24,15 +25,15 @@ class ActionStopTempTargetTest : ActionsTestBase() {
}
@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() {
Assertions.assertEquals("Stop temp target", sut.shortDescription())
assertThat(sut.shortDescription()).isEqualTo("Stop temp target")
}
@Test fun iconTest() {
Assertions.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
assertThat(sut.icon()).isEqualTo(R.drawable.ic_stop_24dp)
}
@Test fun doActionTest() {
@ -52,22 +53,22 @@ class ActionStopTempTargetTest : ActionsTestBase() {
sut.doAction(object : Callback() {
override fun run() {
Assertions.assertTrue(result.success)
assertThat(result.success).isTrue()
}
})
Mockito.verify(repository, Mockito.times(1)).runTransactionForResult((anyObject<Transaction<CancelCurrentTemporaryTargetIfAnyTransaction.TransactionResult>>()))
}
@Test fun hasDialogTest() {
Assertions.assertFalse(sut.hasDialog())
assertThat(sut.hasDialog()).isFalse()
}
@Test fun toJSONTest() {
Assertions.assertEquals("{\"type\":\"ActionStopTempTarget\"}", sut.toJSON())
JSONAssert.assertEquals("""{"type":"ActionStopTempTarget"}""", sut.toJSON(), true)
}
@Test fun fromJSONTest() {
sut.fromJSON("{\"reason\":\"Test\"}")
Assertions.assertNotNull(sut)
sut.fromJSON("""{"reason":"Test"}""")
assertThat(sut).isNotNull()
}
}
}

View file

@ -1,18 +1,18 @@
package app.aaps.plugins.automation.elements
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
class ComparatorConnectTest : TriggerTestBase() {
@Test fun labelsTest() {
Assertions.assertEquals(2, ComparatorConnect.Compare.labels(rh).size)
assertThat(ComparatorConnect.Compare.labels(rh)).hasSize(2)
}
@Test fun setValueTest() {
val c = ComparatorConnect(rh)
c.value = ComparatorConnect.Compare.ON_DISCONNECT
Assertions.assertEquals(ComparatorConnect.Compare.ON_DISCONNECT, c.value)
assertThat(c.value).isEqualTo(ComparatorConnect.Compare.ON_DISCONNECT)
}
}
}

View file

@ -1,18 +1,18 @@
package app.aaps.plugins.automation.elements
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
class ComparatorExistsTest : TriggerTestBase() {
@Test fun labelsTest() {
Assertions.assertEquals(2, ComparatorExists.Compare.labels(rh).size)
assertThat(ComparatorExists.Compare.labels(rh)).hasSize(2)
}
@Test fun setValueTest() {
val c = ComparatorExists(rh)
c.value = ComparatorExists.Compare.NOT_EXISTS
Assertions.assertEquals(ComparatorExists.Compare.NOT_EXISTS, c.value)
assertThat(c.value).isEqualTo(ComparatorExists.Compare.NOT_EXISTS)
}
}
}

View file

@ -1,35 +1,35 @@
package app.aaps.plugins.automation.elements
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
class ComparatorTest : TriggerTestBase() {
@Test
fun checkTest() {
Assertions.assertTrue(Comparator.Compare.IS_EQUAL.check(1, 1))
Assertions.assertTrue(Comparator.Compare.IS_LESSER.check(1, 2))
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(1, 2))
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 2))
Assertions.assertTrue(Comparator.Compare.IS_GREATER.check(2, 1))
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 1))
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 2))
Assertions.assertFalse(Comparator.Compare.IS_LESSER.check(2, 1))
Assertions.assertFalse(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 1))
Assertions.assertFalse(Comparator.Compare.IS_GREATER.check(1, 2))
Assertions.assertFalse(Comparator.Compare.IS_EQUAL_OR_GREATER.check(1, 2))
// Assertions.assertTrue(Comparator.Compare.IS_NOT_AVAILABLE.check<Int?>(1, null))
assertThat(Comparator.Compare.IS_EQUAL.check(1, 1)).isTrue()
assertThat(Comparator.Compare.IS_LESSER.check(1, 2)).isTrue()
assertThat(Comparator.Compare.IS_EQUAL_OR_LESSER.check(1, 2)).isTrue()
assertThat(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 2)).isTrue()
assertThat(Comparator.Compare.IS_GREATER.check(2, 1)).isTrue()
assertThat(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 1)).isTrue()
assertThat(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 2)).isTrue()
assertThat(Comparator.Compare.IS_LESSER.check(2, 1)).isFalse()
assertThat(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 1)).isFalse()
assertThat(Comparator.Compare.IS_GREATER.check(1, 2)).isFalse()
assertThat(Comparator.Compare.IS_EQUAL_OR_GREATER.check(1, 2)).isFalse()
// assertThat(Comparator.Compare.IS_NOT_AVAILABLE.check<Int?>(1, null)).isTrue()
}
@Test
fun labelsTest() {
Assertions.assertEquals(6, Comparator.Compare.labels(rh).size)
assertThat(Comparator.Compare.labels(rh)).hasSize(6)
}
@Test
fun setValueTest() {
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)
}
}
}

View file

@ -2,7 +2,7 @@ package app.aaps.plugins.automation.elements
import app.aaps.core.interfaces.db.GlucoseUnit
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.Test
import org.mockito.Mockito.`when`
@ -12,16 +12,16 @@ class InputBgTest : TriggerTestBase() {
@Test
fun setValueTest() {
var i: InputBg = InputBg(profileFunction).setUnits(GlucoseUnit.MMOL).setValue(5.0)
Assertions.assertEquals(5.0, i.value, 0.01)
Assertions.assertEquals(InputBg.MMOL_MIN, i.minValue, 0.01)
assertThat(i.value).isWithin(0.01).of(5.0)
assertThat(i.minValue).isWithin(0.01).of(InputBg.MMOL_MIN)
i = InputBg(profileFunction).setValue(100.0).setUnits(GlucoseUnit.MGDL)
Assertions.assertEquals(100.0, i.value, 0.01)
Assertions.assertEquals(InputBg.MGDL_MIN, i.minValue, 0.01)
Assertions.assertEquals(GlucoseUnit.MGDL, i.units)
assertThat(i.value).isWithin(0.01).of(100.0)
assertThat(i.minValue).isWithin(0.01).of(InputBg.MGDL_MIN)
assertThat(i.units).isEqualTo(GlucoseUnit.MGDL)
}
@BeforeEach
fun prepare() {
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
}
}
}

View file

@ -1,19 +1,19 @@
package app.aaps.plugins.automation.elements
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
class InputCarePortalEventTest : TriggerTestBase() {
@Test
fun labelsTest() {
Assertions.assertEquals(4, InputCarePortalMenu.EventType.labels(rh).size)
assertThat(InputCarePortalMenu.EventType.labels(rh)).hasSize(4)
}
@Test
fun setValueTest() {
val cp = InputCarePortalMenu(rh, InputCarePortalMenu.EventType.EXERCISE)
Assertions.assertEquals(InputCarePortalMenu.EventType.EXERCISE, cp.value)
assertThat(cp.value).isEqualTo(InputCarePortalMenu.EventType.EXERCISE)
}
}
}

View file

@ -1,20 +1,20 @@
package app.aaps.plugins.automation.elements
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
class InputDurationTest : TriggerTestBase() {
@Test fun setValueTest() {
var i = InputDuration(5, InputDuration.TimeUnit.MINUTES)
Assertions.assertEquals(5, i.value)
Assertions.assertEquals(InputDuration.TimeUnit.MINUTES, i.unit)
assertThat(i.value).isEqualTo(5)
assertThat(i.unit).isEqualTo(InputDuration.TimeUnit.MINUTES)
i = InputDuration(5, InputDuration.TimeUnit.HOURS)
Assertions.assertEquals(5, i.value)
Assertions.assertEquals(InputDuration.TimeUnit.HOURS, i.unit)
Assertions.assertEquals(5 * 60, i.getMinutes())
assertThat(i.value).isEqualTo(5)
assertThat(i.unit).isEqualTo(InputDuration.TimeUnit.HOURS)
assertThat(i.getMinutes()).isEqualTo(5 * 60)
i.setMinutes(60)
Assertions.assertEquals(1, i.value)
assertThat(i.value).isEqualTo(1)
}
}
}

View file

@ -1,7 +1,7 @@
package app.aaps.plugins.automation.elements
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
class InputInsulinTest : TriggerTestBase() {
@ -9,6 +9,6 @@ class InputInsulinTest : TriggerTestBase() {
@Test fun setValueTest() {
val i = InputInsulin()
i.value = 5.0
Assertions.assertEquals(5.0, i.value, 0.01)
assertThat(i.value).isWithin(0.01).of(5.0)
}
}
}

View file

@ -1,7 +1,7 @@
package app.aaps.plugins.automation.elements
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
class InputPercentTest : TriggerTestBase() {
@ -9,6 +9,6 @@ class InputPercentTest : TriggerTestBase() {
@Test fun setValueTest() {
val i = InputPercent()
i.value = 10.0
Assertions.assertEquals(10.0, i.value, 0.01)
assertThat(i.value).isWithin(0.01).of(10.0)
}
}
}

View file

@ -1,15 +1,15 @@
package app.aaps.plugins.automation.elements
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
class InputProfileNameTest : TriggerTestBase() {
@Test fun setValue() {
val inputProfileName = InputProfileName(rh, activePlugin, "Test")
Assertions.assertEquals("Test", inputProfileName.value)
assertThat(inputProfileName.value).isEqualTo("Test")
inputProfileName.value = "Test2"
Assertions.assertEquals("Test2", inputProfileName.value)
assertThat(inputProfileName.value).isEqualTo("Test2")
}
}
}

View file

@ -1,7 +1,7 @@
package app.aaps.plugins.automation.elements
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
class InputStringTest : TriggerTestBase() {
@ -9,6 +9,6 @@ class InputStringTest : TriggerTestBase() {
@Test fun setValueTest() {
val i = InputString()
i.value = "asd"
Assertions.assertEquals("asd", i.value)
assertThat(i.value).isEqualTo("asd")
}
}
}

View file

@ -2,7 +2,7 @@ package app.aaps.plugins.automation.elements
import app.aaps.core.interfaces.db.GlucoseUnit
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
class InputTempTargetTest : TriggerTestBase() {
@ -11,10 +11,10 @@ class InputTempTargetTest : TriggerTestBase() {
val i = InputTempTarget(profileFunction)
i.units = GlucoseUnit.MMOL
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.value = 100.0
Assertions.assertEquals(100.0, i.value, 0.01)
Assertions.assertEquals(GlucoseUnit.MGDL, i.units)
assertThat(i.value).isWithin(0.01).of(100.0)
assertThat(i.units).isEqualTo(GlucoseUnit.MGDL)
}
}
}

View file

@ -1,16 +1,17 @@
package app.aaps.plugins.automation.elements
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 kotlin.test.assertIs
class LabelWithElementTest : TriggerTestBase() {
@Test
fun constructorTest() {
val l = LabelWithElement(rh, "A", "B", InputInsulin())
Assertions.assertEquals("A", l.textPre)
Assertions.assertEquals("B", l.textPost)
Assertions.assertEquals(InputInsulin::class.java, l.element!!.javaClass)
assertThat(l.textPre).isEqualTo("A")
assertThat(l.textPost).isEqualTo("B")
assertIs<InputInsulin>(l.element)
}
}
}

View file

@ -3,7 +3,7 @@ package app.aaps.plugins.automation.elements
import app.aaps.shared.tests.TestBase
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import org.junit.jupiter.api.Assertions
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
class LayoutBuilderTest : TestBase() {
@ -14,15 +14,15 @@ class LayoutBuilderTest : TestBase() {
val layoutBuilder = LayoutBuilder()
val inputInsulin = InputInsulin()
layoutBuilder.add(inputInsulin)
Assertions.assertEquals(1, layoutBuilder.mElements.size)
assertThat(layoutBuilder.mElements).hasSize(1)
}
@Test fun addConditionalTest() {
val layoutBuilder = LayoutBuilder()
val inputInsulin = InputInsulin()
layoutBuilder.maybeAdd(inputInsulin, true)
Assertions.assertEquals(1, layoutBuilder.mElements.size)
assertThat(layoutBuilder.mElements).hasSize(1)
layoutBuilder.maybeAdd(inputInsulin, false)
Assertions.assertEquals(1, layoutBuilder.mElements.size)
assertThat(layoutBuilder.mElements).hasSize(1)
}
}
}

View file

@ -2,7 +2,7 @@ package app.aaps.plugins.automation.elements
import app.aaps.plugins.automation.triggers.TriggerDummy
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.mockito.Mockito.`when`
@ -10,9 +10,9 @@ class StaticLabelTest : TriggerTestBase() {
@Test fun constructor() {
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")
sl = StaticLabel(rh, app.aaps.core.ui.R.string.pumplimit, TriggerDummy(injector))
Assertions.assertEquals("pump limit", sl.label)
assertThat(sl.label).isEqualTo("pump limit")
}
}
}

View file

@ -5,11 +5,11 @@ import app.aaps.plugins.automation.elements.Comparator
import app.aaps.plugins.main.iob.iobCobCalculator.data.AutosensDataObject
import com.google.common.truth.Truth.assertThat
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class TriggerAutosensValueTest : TriggerTestBase() {
@ -20,53 +20,53 @@ class TriggerAutosensValueTest : TriggerTestBase() {
var t = TriggerAutosensValue(injector)
t.autosens.value = 110.0
t.comparator.value = Comparator.Compare.IS_EQUAL
Assertions.assertEquals(110.0, t.autosens.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
Assertions.assertFalse(t.shouldRun())
assertThat(t.autosens.value).isWithin(0.01).of(110.0)
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t.shouldRun()).isFalse()
t = TriggerAutosensValue(injector)
t.autosens.value = 100.0
t.comparator.value = Comparator.Compare.IS_EQUAL
Assertions.assertEquals(100.0, t.autosens.value, 0.01)
Assertions.assertTrue(t.shouldRun())
assertThat(t.autosens.value).isWithin(0.01).of(100.0)
assertThat(t.shouldRun()).isTrue()
t = TriggerAutosensValue(injector)
t.autosens.value = 50.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
t = TriggerAutosensValue(injector)
t.autosens.value = 310.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
t = TriggerAutosensValue(injector)
t.autosens.value = 420.0
t.comparator.value = Comparator.Compare.IS_EQUAL
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
t = TriggerAutosensValue(injector)
t.autosens.value = 390.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
t = TriggerAutosensValue(injector)
t.autosens.value = 390.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
t = TriggerAutosensValue(injector)
t.autosens.value = 20.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
t = TriggerAutosensValue(injector)
t.autosens.value = 390.0
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))
t = TriggerAutosensValue(injector)
t.autosens.value = 80.0
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
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(null)
t = TriggerAutosensValue(injector)
t.comparator.value = Comparator.Compare.IS_NOT_AVAILABLE
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
}
@Test
@ -75,8 +75,8 @@ class TriggerAutosensValueTest : TriggerTestBase() {
t.autosens.value = 213.0
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
val t1 = t.duplicate() as TriggerAutosensValue
Assertions.assertEquals(213.0, t1.autosens.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
assertThat(t1.autosens.value).isWithin(0.01).of(213.0)
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
}
private var asJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"value\":410},\"type\":\"TriggerAutosensValue\"}"
@ -86,7 +86,7 @@ class TriggerAutosensValueTest : TriggerTestBase() {
val t = TriggerAutosensValue(injector)
t.autosens.value = 410.0
t.comparator.value = Comparator.Compare.IS_EQUAL
Assertions.assertEquals(asJson, t.toJSON())
JSONAssert.assertEquals(asJson, t.toJSON(), true)
}
@Test
@ -95,15 +95,13 @@ class TriggerAutosensValueTest : TriggerTestBase() {
t.autosens.value = 410.0
t.comparator.value = Comparator.Compare.IS_EQUAL
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerAutosensValue
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(410.0, t2.autosens.value, 0.01)
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t2.autosens.value).isWithin(0.01).of(410.0)
}
@Test fun iconTest() {
assertThat(TriggerAutosensValue(injector).icon().get()).isEqualTo(R.drawable.ic_as)
}
private fun generateAutosensData(): AutosensDataObject {
return AutosensDataObject(injector)
}
}
private fun generateAutosensData() = AutosensDataObject(injector)
}

View file

@ -3,8 +3,8 @@ package app.aaps.plugins.automation.triggers
import app.aaps.plugins.automation.elements.ComparatorConnect
import com.google.common.truth.Truth.assertThat
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.skyscreamer.jsonassert.JSONAssert
class TriggerBTDeviceTest : TriggerTestBase() {
@ -19,14 +19,14 @@ class TriggerBTDeviceTest : TriggerTestBase() {
@Test fun toJSON() {
val t = TriggerBTDevice(injector)
t.btDevice.value = someName
Assertions.assertEquals(btJson, t.toJSON())
JSONAssert.assertEquals(btJson, t.toJSON(), true)
}
@Test
fun fromJSON() {
val t2 = TriggerDummy(injector).instantiate(JSONObject(btJson)) as TriggerBTDevice
Assertions.assertEquals(ComparatorConnect.Compare.ON_CONNECT, t2.comparator.value)
Assertions.assertEquals("Headset", t2.btDevice.value)
assertThat(t2.comparator.value).isEqualTo(ComparatorConnect.Compare.ON_CONNECT)
assertThat(t2.btDevice.value).isEqualTo("Headset")
}
@Test
@ -40,7 +40,7 @@ class TriggerBTDeviceTest : TriggerTestBase() {
it.btDevice.value = someName
}
val t1 = t.duplicate() as TriggerBTDevice
Assertions.assertEquals("Headset", t1.btDevice.value)
Assertions.assertEquals(ComparatorConnect.Compare.ON_DISCONNECT, t.comparator.value)
assertThat(t1.btDevice.value).isEqualTo("Headset")
assertThat(t.comparator.value).isEqualTo(ComparatorConnect.Compare.ON_DISCONNECT)
}
}
}

View file

@ -6,10 +6,11 @@ import app.aaps.database.entities.GlucoseValue
import app.aaps.plugins.automation.elements.Comparator
import com.google.common.truth.Truth.assertThat
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.Test
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class TriggerBgTest : TriggerTestBase() {
@ -22,37 +23,37 @@ class TriggerBgTest : TriggerTestBase() {
fun shouldRunTest() {
`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOneCurrentRecordBgData())
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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())
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
}
@Test
fun copyConstructorTest() {
val t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerBg
Assertions.assertEquals(213.0, t1.bg.value, 0.01)
Assertions.assertEquals(GlucoseUnit.MGDL, t1.bg.units)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
assertThat(t1.bg.value).isWithin(0.01).of(213.0)
assertThat(t1.bg.units).isEqualTo(GlucoseUnit.MGDL)
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\"}"
@ -60,16 +61,16 @@ class TriggerBgTest : TriggerTestBase() {
@Test
fun toJSONTest() {
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
fun fromJSONTest() {
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
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(4.1, t2.bg.value, 0.01)
Assertions.assertEquals(GlucoseUnit.MMOL, t2.bg.units)
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t2.bg.value).isWithin(0.01).of(4.1)
assertThat(t2.bg.units).isEqualTo(GlucoseUnit.MMOL)
}
@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))
return list
}
}
}

View file

@ -7,9 +7,9 @@ import com.google.common.truth.Truth.assertThat
import io.reactivex.rxjava3.core.Single
import org.json.JSONException
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
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
var t = TriggerBolusAgo(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL)
Assertions.assertEquals(110, t.minutesAgo.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
Assertions.assertFalse(t.shouldRun())
assertThat(t.minutesAgo.value).isEqualTo(110)
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t.shouldRun()).isFalse()
t = TriggerBolusAgo(injector).setValue(10).comparator(Comparator.Compare.IS_EQUAL)
Assertions.assertEquals(10, t.minutesAgo.value)
Assertions.assertTrue(t.shouldRun())
assertThat(t.minutesAgo.value).isEqualTo(10)
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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
`when`(repository.getLastBolusRecordOfTypeWrapped(Bolus.Type.NORMAL)).thenReturn(
Single.just(
@ -62,30 +62,30 @@ class TriggerBolusAgoTest : TriggerTestBase() {
)
)
t = TriggerBolusAgo(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
}
@Test fun copyConstructorTest() {
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerBolusAgo
Assertions.assertEquals(213, t1.minutesAgo.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
assertThat(t1.minutesAgo.value).isEqualTo(213)
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
}
private var lbJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"minutesAgo\":410},\"type\":\"TriggerBolusAgo\"}"
@Test fun toJSONTest() {
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() {
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerBolusAgo
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(410, t2.minutesAgo.value)
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t2.minutesAgo.value).isEqualTo(410)
}
@Test fun iconTest() {
assertThat(TriggerBolusAgo(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_bolus)
}
}
}

View file

@ -4,11 +4,11 @@ import app.aaps.core.interfaces.iob.CobInfo
import app.aaps.plugins.automation.elements.Comparator
import com.google.common.truth.Truth.assertThat
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class TriggerCOBTest : TriggerTestBase() {
@ -20,44 +20,44 @@ class TriggerCOBTest : TriggerTestBase() {
// COB value is 6
`when`(iobCobCalculator.getCobInfo("AutomationTriggerCOB")).thenReturn(CobInfo(0, 6.0, 2.0))
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
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)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
}
@Test fun copyConstructorTest() {
val t: TriggerCOB = TriggerCOB(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assertions.assertEquals(213.0, t.cob.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
assertThat(t.cob.value).isWithin(0.01).of(213.0)
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
}
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"carbs\":4},\"type\":\"TriggerCOB\"}"
@Test fun toJSONTest() {
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
fun fromJSONTest() {
val t: TriggerCOB = TriggerCOB(injector).setValue(4.0).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerCOB
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(4.0, t2.cob.value, 0.01)
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t2.cob.value).isWithin(0.01).of(4.0)
}
@Test fun iconTest() {
assertThat(TriggerCOB(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_cp_bolus_carbs)
}
}
}

View file

@ -1,7 +1,7 @@
package app.aaps.plugins.automation.triggers
import kotlin.test.assertIs
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class TriggerDummyTest : TriggerTestBase() {
@ -9,13 +9,13 @@ class TriggerDummyTest : TriggerTestBase() {
@Test
fun instantiateTest() {
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\"}"))
Assertions.assertTrue(trigger is TriggerDummy)
assertIs<TriggerDummy>(trigger)
trigger = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"TriggerDummy\"}"))
Assertions.assertTrue(trigger is TriggerDummy)
assertIs<TriggerDummy>(trigger)
}
}
}

View file

@ -3,19 +3,20 @@ package app.aaps.plugins.automation.triggers
import app.aaps.database.entities.HeartRate
import app.aaps.plugins.automation.R
import app.aaps.plugins.automation.elements.Comparator
import com.google.common.truth.Truth.assertThat
import io.reactivex.rxjava3.core.Single
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyNoMoreInteractions
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class TriggerHeartRateTest : TriggerTestBase() {
@Test
fun friendlyName() {
Assertions.assertEquals(R.string.triggerHeartRate, TriggerHeartRate(injector).friendlyName())
assertThat(TriggerHeartRate(injector).friendlyName()).isEqualTo(R.string.triggerHeartRate)
}
@Test
@ -23,7 +24,7 @@ class TriggerHeartRateTest : TriggerTestBase() {
val t = TriggerHeartRate(injector)
`when`(rh.gs(Comparator.Compare.IS_EQUAL_OR_GREATER.stringRes)).thenReturn(">")
`when`(rh.gs(R.string.triggerHeartRateDesc, ">", 80.0)).thenReturn("test")
Assertions.assertEquals("test", t.friendlyDescription())
assertThat(t.friendlyDescription()).isEqualTo("test")
}
@Test
@ -33,16 +34,16 @@ class TriggerHeartRateTest : TriggerTestBase() {
comparator.value = Comparator.Compare.IS_GREATER
}
val dup = t.duplicate() as TriggerHeartRate
Assertions.assertNotSame(t, dup)
Assertions.assertEquals(100.0, dup.heartRate.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_GREATER, dup.comparator.value)
assertThat(dup).isNotSameInstanceAs(t)
assertThat(dup.heartRate.value).isWithin(0.01).of(100.0)
assertThat(dup.comparator.value).isEqualTo(Comparator.Compare.IS_GREATER)
}
@Test
fun shouldRunNotAvailable() {
val t = TriggerHeartRate(injector).apply { comparator.value = Comparator.Compare.IS_NOT_AVAILABLE }
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
verifyNoMoreInteractions(repository)
}
@ -53,7 +54,7 @@ class TriggerHeartRateTest : TriggerTestBase() {
comparator.value = Comparator.Compare.IS_GREATER
}
`when`(repository.getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)).thenReturn(Single.just(emptyList()))
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
verify(repository).getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)
verifyNoMoreInteractions(repository)
}
@ -69,7 +70,7 @@ class TriggerHeartRateTest : TriggerTestBase() {
HeartRate(duration = 300_000, timestamp = now, beatsPerMinute = 60.0, device = "test"),
)
`when`(repository.getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)).thenReturn(Single.just(hrs))
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
verify(repository).getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)
verifyNoMoreInteractions(repository)
}
@ -84,7 +85,7 @@ class TriggerHeartRateTest : TriggerTestBase() {
HeartRate(duration = 300_000, timestamp = now, beatsPerMinute = 120.0, device = "test"),
)
`when`(repository.getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)).thenReturn(Single.just(hrs))
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
verify(repository).getHeartRatesFromTime(now - t.averageHeartRateDurationMillis)
verifyNoMoreInteractions(repository)
}
@ -95,9 +96,9 @@ class TriggerHeartRateTest : TriggerTestBase() {
heartRate.value = 100.0
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
@ -107,7 +108,7 @@ class TriggerHeartRateTest : TriggerTestBase() {
"""{"data":{"comparator":"IS_GREATER","heartRate":100},"type":"TriggerHeartRate"}"""
)
) as TriggerHeartRate
Assertions.assertEquals(Comparator.Compare.IS_GREATER, t.comparator.value)
Assertions.assertEquals(100.0, t.heartRate.value, 0.01)
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_GREATER)
assertThat(t.heartRate.value).isWithin(0.01).of(100.0)
}
}
}

View file

@ -5,11 +5,11 @@ import app.aaps.plugins.automation.R
import app.aaps.plugins.automation.elements.Comparator
import com.google.common.truth.Truth.assertThat
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class TriggerIobTest : TriggerTestBase() {
@ -20,43 +20,43 @@ class TriggerIobTest : TriggerTestBase() {
@Test fun shouldRunTest() {
`when`(iobCobCalculator.calculateFromTreatmentsAndTemps(ArgumentMatchers.anyLong(), anyObject())).thenReturn(generateIobRecordData())
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
t = TriggerIob(injector).setValue(0.9).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
}
@Test fun copyConstructorTest() {
val t: TriggerIob = TriggerIob(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assertions.assertEquals(213.0, t.insulin.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
assertThat(t.insulin.value).isWithin(0.01).of(213.0)
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
}
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"insulin\":4.1},\"type\":\"TriggerIob\"}"
@Test fun toJSONTest() {
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
fun fromJSONTest() {
val t: TriggerIob = TriggerIob(injector).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerIob
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(4.1, t2.insulin.value, 0.01)
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t2.insulin.value).isWithin(0.01).of(4.1)
}
@Test fun iconTest() {
@ -68,4 +68,4 @@ class TriggerIobTest : TriggerTestBase() {
iobTotal.iob = 1.0
return iobTotal
}
}
}

View file

@ -6,7 +6,6 @@ import app.aaps.plugins.automation.elements.InputLocationMode
import com.google.common.truth.Truth.assertThat
import org.json.JSONException
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
@ -24,10 +23,10 @@ class TriggerLocationTest : TriggerTestBase() {
t.distance.setValue(2.0)
t.modeSelected.value = InputLocationMode.Mode.INSIDE
val t1 = t.duplicate() as TriggerLocation
Assertions.assertEquals(213.0, t1.latitude.value, 0.01)
Assertions.assertEquals(212.0, t1.longitude.value, 0.01)
Assertions.assertEquals(2.0, t1.distance.value, 0.01)
Assertions.assertEquals(InputLocationMode.Mode.INSIDE, t1.modeSelected.value)
assertThat(t1.latitude.value).isWithin(0.01).of(213.0)
assertThat(t1.longitude.value).isWithin(0.01).of(212.0)
assertThat(t1.distance.value).isWithin(0.01).of(2.0)
assertThat(t1.modeSelected.value).isEqualTo(InputLocationMode.Mode.INSIDE)
}
@Test fun shouldRunTest() {
@ -37,12 +36,12 @@ class TriggerLocationTest : TriggerTestBase() {
t.distance.setValue(2.0)
// t.modeSelected.setValue(InputLocationMode.Mode.OUTSIDE);
`when`(locationDataContainer.lastLocation).thenReturn(null)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocation())
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
t = TriggerLocation(injector)
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
t = TriggerLocation(injector)
@ -51,9 +50,9 @@ class TriggerLocationTest : TriggerTestBase() {
`when`(locationDataContainer.lastLocation).thenReturn(null)
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocationOut())
t.modeSelected.value = InputLocationMode.Mode.GOING_IN
Assertions.assertEquals(t.lastMode, InputLocationMode.Mode.OUTSIDE)
Assertions.assertEquals(t.currentMode(5.0), InputLocationMode.Mode.INSIDE)
Assertions.assertTrue(t.shouldRun())
assertThat(InputLocationMode.Mode.OUTSIDE).isEqualTo(t.lastMode)
assertThat(InputLocationMode.Mode.INSIDE).isEqualTo(t.currentMode(5.0))
assertThat(t.shouldRun()).isTrue()
//Test of GOING_OUT - last mode should be INSIDE, and current mode should be OUTSIDE
// Currently unavailable due to problems with Location mocking
@ -67,7 +66,7 @@ class TriggerLocationTest : TriggerTestBase() {
t.distance.setValue(2.0)
t.modeSelected.value = InputLocationMode.Mode.OUTSIDE
// t.modeSelected = t.modeSelected.value
Assertions.assertEquals(locationJson, t.toJSON())
assertThat(t.toJSON()).isEqualTo(locationJson)
}
@Test @Throws(JSONException::class) fun fromJSONTest() {
@ -77,18 +76,18 @@ class TriggerLocationTest : TriggerTestBase() {
t.distance.setValue(2.0)
t.modeSelected.value = InputLocationMode.Mode.INSIDE
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerLocation
Assertions.assertEquals(t.latitude.value, t2.latitude.value, 0.01)
Assertions.assertEquals(t.longitude.value, t2.longitude.value, 0.01)
Assertions.assertEquals(t.distance.value, t2.distance.value, 0.01)
Assertions.assertEquals(t.modeSelected.value, t2.modeSelected.value)
assertThat(t2.latitude.value).isWithin(0.01).of(t.latitude.value)
assertThat(t2.longitude.value).isWithin(0.01).of(t.longitude.value)
assertThat(t2.distance.value).isWithin(0.01).of(t.distance.value)
assertThat(t2.modeSelected.value).isEqualTo(t.modeSelected.value)
}
@Test fun friendlyNameTest() {
Assertions.assertEquals(R.string.location, TriggerLocation(injector).friendlyName())
assertThat(TriggerLocation(injector).friendlyName()).isEqualTo(R.string.location)
}
@Test fun friendlyDescriptionTest() {
Assertions.assertEquals(null, TriggerLocation(injector).friendlyDescription()) //not mocked }
assertThat(TriggerLocation(injector).friendlyDescription()).isNull() //not mocked }
}
@Test fun iconTest() {
@ -110,4 +109,4 @@ class TriggerLocationTest : TriggerTestBase() {
newLocation.accuracy = 1f
return newLocation
}
}
}

View file

@ -4,10 +4,10 @@ import app.aaps.plugins.automation.R
import app.aaps.plugins.automation.elements.Comparator
import com.google.common.truth.Truth.assertThat
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class TriggerProfilePercentTest : TriggerTestBase() {
@ -17,43 +17,43 @@ class TriggerProfilePercentTest : TriggerTestBase() {
@Test fun shouldRunTest() {
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
t = TriggerProfilePercent(injector).setValue(90.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
}
@Test fun copyConstructorTest() {
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerProfilePercent
Assertions.assertEquals(213.0, t1.pct.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
assertThat( t1.pct.value).isWithin(0.01).of(213.0)
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
}
private val bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"percentage\":110},\"type\":\"TriggerProfilePercent\"}"
@Test fun toJSONTest() {
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() {
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(120.0).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerProfilePercent
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(120.0, t2.pct.value, 0.01)
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t2.pct.value).isWithin(0.01).of(120.0)
}
@Test fun iconTest() {
@ -61,6 +61,6 @@ class TriggerProfilePercentTest : TriggerTestBase() {
}
@Test fun friendlyNameTest() {
Assertions.assertEquals(R.string.profilepercentage, TriggerProfilePercent(injector).friendlyName()) // not mocked
assertThat(TriggerProfilePercent(injector).friendlyName()).isEqualTo(R.string.profilepercentage) // not mocked
}
}
}

View file

@ -4,9 +4,9 @@ import app.aaps.plugins.automation.R
import app.aaps.plugins.automation.elements.Comparator
import com.google.common.truth.Truth.assertThat
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class TriggerPumpLastConnectionTest : TriggerTestBase() {
@ -14,42 +14,42 @@ class TriggerPumpLastConnectionTest : TriggerTestBase() {
fun shouldRunTest() {
// System.currentTimeMillis() is always 0
// 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
var t = TriggerPumpLastConnection(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL)
Assertions.assertEquals(110, t.minutesAgo.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
Assertions.assertFalse(t.shouldRun())
assertThat(t.minutesAgo.value).isEqualTo(110)
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t.shouldRun()).isFalse()
t = TriggerPumpLastConnection(injector).setValue(10).comparator(Comparator.Compare.IS_EQUAL)
Assertions.assertEquals(10, t.minutesAgo.value)
Assertions.assertFalse(t.shouldRun()) // 0 == 10 -> FALSE
assertThat(t.minutesAgo.value).isEqualTo(10)
assertThat(t.shouldRun()).isFalse() // 0 == 10 -> FALSE
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)
Assertions.assertFalse(t.shouldRun()) // 310 <= 0 -> FALSE
assertThat(t.shouldRun()).isFalse() // 310 <= 0 -> FALSE
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() {
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerPumpLastConnection
Assertions.assertEquals(213, t1.minutesAgo.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
assertThat(t1.minutesAgo.value).isEqualTo(213)
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
}
private var lbJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"minutesAgo\":410},\"type\":\"TriggerPumpLastConnection\"}"
@Test fun toJSONTest() {
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
Assertions.assertEquals(lbJson, t.toJSON())
JSONAssert.assertEquals(lbJson, t.toJSON(), true)
}
@Test
fun fromJSONTest() {
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerPumpLastConnection
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(410, t2.minutesAgo.value)
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t2.minutesAgo.value).isEqualTo(410)
}
@Test fun iconTest() {
@ -57,6 +57,6 @@ class TriggerPumpLastConnectionTest : TriggerTestBase() {
}
@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)
}
}
}

View file

@ -2,11 +2,12 @@ package app.aaps.plugins.automation.triggers
import app.aaps.core.interfaces.utils.MidnightTime
import app.aaps.core.interfaces.utils.T
import com.google.common.truth.Truth.assertThat
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.skyscreamer.jsonassert.JSONAssert
class TriggerRecurringTimeTest : TriggerTestBase() {
@ -19,12 +20,12 @@ class TriggerRecurringTimeTest : TriggerTestBase() {
var t: TriggerRecurringTime = TriggerRecurringTime(injector).time(89)
t.days.setAll(true)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
// scheduled 1 min before
t = TriggerRecurringTime(injector).time(94)
t.days.setAll(true)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
}
private var timeJson =
@ -33,13 +34,13 @@ class TriggerRecurringTimeTest : TriggerTestBase() {
@Test
fun toJSONTest() {
val t = TriggerRecurringTime(injector).time(4444)
Assertions.assertEquals(timeJson, t.toJSON())
JSONAssert.assertEquals(timeJson, t.toJSON(), true)
}
@Test
fun fromJSONTest() {
val t = TriggerRecurringTime(injector).time(4444)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerRecurringTime
Assertions.assertEquals(4444, t2.time.value)
assertThat(t2.time.value).isEqualTo(4444)
}
}
}

View file

@ -4,8 +4,8 @@ import app.aaps.plugins.automation.R
import app.aaps.plugins.automation.elements.ComparatorExists
import com.google.common.truth.Truth.assertThat
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.skyscreamer.jsonassert.JSONAssert
class TriggerTempTargetTest : TriggerTestBase() {
@ -13,36 +13,36 @@ class TriggerTempTargetTest : TriggerTestBase() {
@Test fun shouldRunTest() {
`when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(null)
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)
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))
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
}
*/
@Test fun copyConstructorTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
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\"}"
@Test fun toJSONTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
Assertions.assertEquals(ttJson, t.toJSON())
JSONAssert.assertEquals(ttJson, t.toJSON(), true)
}
@Test
fun fromJSONTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
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() {
assertThat(TriggerTempTarget(injector).icon().get()).isEqualTo(R.drawable.ic_keyboard_tab)
}
}
}

View file

@ -8,10 +8,10 @@ import app.aaps.plugins.automation.elements.Comparator
import com.google.common.truth.Truth.assertThat
import io.reactivex.rxjava3.core.Single
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class 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)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
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)
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
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)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
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)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
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)
Assertions.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
assertThat(t.shouldRun()).isFalse()
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()))
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
}
@Test
fun copyConstructorTest() {
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerTempTargetValue
Assertions.assertEquals(140.0, t1.ttValue.value, 0.01)
Assertions.assertEquals(GlucoseUnit.MGDL, t1.ttValue.units)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
assertThat(t1.ttValue.value).isWithin(0.01).of(140.0)
assertThat(t1.ttValue.units).isEqualTo(GlucoseUnit.MGDL)
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\"}"
@ -74,16 +74,16 @@ class TriggerTempTargetValueTest : TriggerTestBase() {
@Test
fun toJSONTest() {
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
fun fromJSONTest() {
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
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(7.7, t2.ttValue.value, 0.01)
Assertions.assertEquals(GlucoseUnit.MMOL, t2.ttValue.units)
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t2.ttValue.value).isWithin(0.01).of(7.7)
assertThat(t2.ttValue.units).isEqualTo(GlucoseUnit.MMOL)
}
@Test

View file

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

View file

@ -4,9 +4,9 @@ import app.aaps.core.interfaces.utils.T
import app.aaps.plugins.automation.R
import com.google.common.truth.Truth.assertThat
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.skyscreamer.jsonassert.JSONAssert
class TriggerTimeTest : TriggerTestBase() {
@ -19,11 +19,11 @@ class TriggerTimeTest : TriggerTestBase() {
// scheduled 1 min before
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
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\"}"
@ -31,14 +31,14 @@ class TriggerTimeTest : TriggerTestBase() {
@Test
fun toJSONTest() {
val t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs())
Assertions.assertEquals(timeJson, t.toJSON())
JSONAssert.assertEquals(timeJson, t.toJSON(), true)
}
@Test
fun fromJSONTest() {
val t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs())
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
@ -46,22 +46,22 @@ class TriggerTimeTest : TriggerTestBase() {
val t = TriggerTime(injector)
t.runAt(now)
val t1 = t.duplicate() as TriggerTime
Assertions.assertEquals(now, t1.time.value)
assertThat(t1.time.value).isEqualTo(now)
}
@Test
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
fun friendlyDescriptionTest() {
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
fun iconTest() {
assertThat(TriggerTime(injector).icon().get()).isEqualTo(app.aaps.core.main.R.drawable.ic_access_alarm_24dp)
}
}
}

View file

@ -6,9 +6,9 @@ import app.aaps.plugins.automation.elements.Comparator
import com.google.common.truth.Truth.assertThat
import org.json.JSONException
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class TriggerWifiSsidTest : TriggerTestBase() {
@ -17,40 +17,40 @@ class TriggerWifiSsidTest : TriggerTestBase() {
`when`(receiverStatusStore.lastNetworkEvent).thenReturn(e)
var t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID 1").comparator(Comparator.Compare.IS_EQUAL)
e.wifiConnected = false
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
e.wifiConnected = true
e.ssid = "otherSSID"
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
e.wifiConnected = true
e.ssid = "aSSID 1"
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
t = TriggerWifiSsid(injector).setValue("aSSID 1").comparator(Comparator.Compare.IS_NOT_AVAILABLE)
e.wifiConnected = false
Assertions.assertTrue(t.shouldRun())
assertThat(t.shouldRun()).isTrue()
// no network data
`when`(receiverStatusStore.lastNetworkEvent).thenReturn(null)
Assertions.assertFalse(t.shouldRun())
assertThat(t.shouldRun()).isFalse()
}
@Test fun copyConstructorTest() {
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerWifiSsid
Assertions.assertEquals("aSSID", t1.ssid.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
assertThat(t1.ssid.value).isEqualTo("aSSID")
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
}
var json = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"ssid\":\"aSSID\"},\"type\":\"TriggerWifiSsid\"}"
@Test fun toJSONTest() {
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() {
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerWifiSsid
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals("aSSID", t2.ssid.value)
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
assertThat(t2.ssid.value).isEqualTo("aSSID")
}
@Test fun iconTest() {
@ -58,10 +58,10 @@ class TriggerWifiSsidTest : TriggerTestBase() {
}
@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() {
Assertions.assertEquals(null, TriggerWifiSsid(injector).friendlyDescription()) //not mocked
assertThat(TriggerWifiSsid(injector).friendlyDescription()).isNull() //not mocked
}
}
}