Rewrites CarbTimerImplTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-04 20:34:25 -07:00
parent fdc9ac1bf6
commit 584c014263

View file

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