Rewrites ComboPluginTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-05 22:07:09 -07:00
parent 541e0fc992
commit 852ad019d7

View file

@ -12,11 +12,11 @@ import app.aaps.core.interfaces.sharedPreferences.SP
import app.aaps.core.interfaces.ui.UiInteraction import app.aaps.core.interfaces.ui.UiInteraction
import app.aaps.core.interfaces.utils.DateUtil import app.aaps.core.interfaces.utils.DateUtil
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 info.nightscout.pump.combo.ruffyscripter.RuffyScripter import info.nightscout.pump.combo.ruffyscripter.RuffyScripter
import info.nightscout.pump.combo.ruffyscripter.history.Bolus import info.nightscout.pump.combo.ruffyscripter.history.Bolus
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.Mock import org.mockito.Mock
@ -56,8 +56,8 @@ class ComboPluginTest : TestBase() {
comboPlugin.setPluginEnabled(PluginType.PUMP, true) comboPlugin.setPluginEnabled(PluginType.PUMP, true)
comboPlugin.setValidBasalRateProfileSelectedOnPump(false) comboPlugin.setValidBasalRateProfileSelectedOnPump(false)
val c = comboPlugin.isLoopInvocationAllowed(ConstraintObject(true, aapsLogger)) val c = comboPlugin.isLoopInvocationAllowed(ConstraintObject(true, aapsLogger))
Assertions.assertEquals("Combo: No valid basal rate read from pump", c.getReasons()) assertThat(c.getReasons()).isEqualTo("Combo: No valid basal rate read from pump")
Assertions.assertEquals(false, c.value()) assertThat(c.value()).isFalse()
comboPlugin.setPluginEnabled(PluginType.PUMP, false) comboPlugin.setPluginEnabled(PluginType.PUMP, false)
} }
@ -66,18 +66,16 @@ class ComboPluginTest : TestBase() {
val now = System.currentTimeMillis() val now = System.currentTimeMillis()
val pumpTimestamp = now - now % 1000 val pumpTimestamp = now - now % 1000
// same timestamp, different bolus leads to different fake timestamp // same timestamp, different bolus leads to different fake timestamp
Assertions.assertNotEquals( assertThat(
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.1, true)),
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.3, true)) comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.3, true))
) ).isNotEqualTo(comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.1, true)))
// different timestamp, same bolus leads to different fake timestamp // different timestamp, same bolus leads to different fake timestamp
Assertions.assertNotEquals( assertThat(
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.3, true)),
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp + 60 * 1000, 0.3, true)) comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp + 60 * 1000, 0.3, true))
) ).isNotEqualTo(comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.3, true)))
// generated timestamp has second-precision // generated timestamp has second-precision
val bolus = Bolus(pumpTimestamp, 0.2, true) val bolus = Bolus(pumpTimestamp, 0.2, true)
val calculatedTimestamp = comboPlugin.generatePumpBolusId(bolus) val calculatedTimestamp = comboPlugin.generatePumpBolusId(bolus)
Assertions.assertEquals(calculatedTimestamp, calculatedTimestamp - calculatedTimestamp % 1000) assertThat(calculatedTimestamp - calculatedTimestamp % 1000).isEqualTo(calculatedTimestamp)
} }
} }