From 82980285de931239a2e244153983bdb5fcc220a4 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 29 Sep 2021 23:18:43 +0200 Subject: [PATCH] fix tests --- .../pump/omnipod/dash/util/FunctionsTest.kt | 110 ++++++++---------- 1 file changed, 49 insertions(+), 61 deletions(-) diff --git a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/FunctionsTest.kt b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/FunctionsTest.kt index c1d290e8fd..03dfebdbe0 100644 --- a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/FunctionsTest.kt +++ b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/FunctionsTest.kt @@ -3,36 +3,25 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.util import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.Profile.ProfileValue import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BasalProgram +import org.junit.Assert import org.junit.Assert.assertEquals -import org.junit.Rule import org.junit.Test -import org.junit.rules.ExpectedException import org.mockito.Mockito -import org.powermock.api.mockito.PowerMockito +import org.mockito.Mockito.`when` class FunctionsTest { - @Rule - @JvmField var thrown = ExpectedException.none() - @Test fun validProfile() { val profile = Mockito.mock(Profile::class.java) - val value1 = Mockito.mock(ProfileValue::class.java) - value1.timeAsSeconds = 0 - value1.value = 0.5 - val value2 = Mockito.mock(ProfileValue::class.java) - value2.timeAsSeconds = 18000 - value2.value = 1.0 - val value3 = Mockito.mock(ProfileValue::class.java) - value3.timeAsSeconds = 50400 - value3.value = 3.05 - PowerMockito.`when`(profile.getBasalValues()).thenReturn( + + `when`(profile.getBasalValues()).thenReturn( arrayOf( - value1, - value2, - value3 + ProfileValue(0, 0.5), + ProfileValue(18000, 1.0), + ProfileValue(50400, 3.05) ) ) + val basalProgram: BasalProgram = mapProfileToBasalProgram(profile) val entries: List = basalProgram.segments assertEquals(3, entries.size) @@ -51,73 +40,72 @@ class FunctionsTest { } @Test fun invalidProfileZeroEntries() { - thrown.expect(IllegalArgumentException::class.java) - thrown.expectMessage("Basal values should contain values") val profile = Mockito.mock(Profile::class.java) - PowerMockito.`when`(profile.getBasalValues()).thenReturn(emptyArray()) - mapProfileToBasalProgram(profile) + + `when`(profile.getBasalValues()).thenReturn(emptyArray()) + + Assert.assertThrows( + "Basal values should contain values", + java.lang.IllegalArgumentException::class.java + ) { + mapProfileToBasalProgram(profile) + } } @Test fun invalidProfileNonZeroOffset() { - thrown.expect(IllegalArgumentException::class.java) - thrown.expectMessage("First basal segment start time should be 0") val profile = Mockito.mock(Profile::class.java) - val value = Mockito.mock(ProfileValue::class.java) - value.timeAsSeconds = 1800 - value.value = 0.5 - PowerMockito.`when`(profile.getBasalValues()).thenReturn( - arrayOf( - value - ) + + `when`(profile.getBasalValues()).thenReturn( + arrayOf(ProfileValue(1800, 0.5)) ) - mapProfileToBasalProgram(profile) + + Assert.assertThrows( + "First basal segment start time should be 0", + java.lang.IllegalArgumentException::class.java + ) { + mapProfileToBasalProgram(profile) + } } @Test fun invalidProfileMoreThan24Hours() { - thrown.expect(IllegalArgumentException::class.java) - thrown.expectMessage("Basal segment start time can not be greater than 86400") - val profile = Mockito.mock(Profile::class.java) - val value1 = Mockito.mock(ProfileValue::class.java) - value1.timeAsSeconds = 0 - value1.value = 0.5 - val value2 = Mockito.mock(ProfileValue::class.java) - value2.timeAsSeconds = 86400 - value2.value = 0.5 - PowerMockito.`when`(profile.getBasalValues()).thenReturn( + + `when`(profile.getBasalValues()).thenReturn( arrayOf( - value1, - value2 + ProfileValue(0, 0.5), + ProfileValue(86400, 0.5) ) ) - mapProfileToBasalProgram(profile) + + Assert.assertThrows( + "Basal segment start time can not be greater than 86400", + java.lang.IllegalArgumentException::class.java + ) { + mapProfileToBasalProgram(profile) + } } @Test fun invalidProfileNegativeOffset() { - thrown.expect(IllegalArgumentException::class.java) - thrown.expectMessage("Basal segment start time can not be less than 0") val profile = Mockito.mock(Profile::class.java) - val value = Mockito.mock(ProfileValue::class.java) - value.timeAsSeconds = -1 - value.value = 0.5 - PowerMockito.`when`(profile.getBasalValues()).thenReturn( - arrayOf( - value - ) + + `when`(profile.getBasalValues()).thenReturn( + arrayOf(ProfileValue(-1, 0.5)) ) - mapProfileToBasalProgram(profile) + + Assert.assertThrows("Basal segment start time can not be less than 0", IllegalArgumentException::class.java) { + mapProfileToBasalProgram(profile) + } } @Test fun roundsToSupportedPrecision() { val profile = Mockito.mock(Profile::class.java) - val value = Mockito.mock(ProfileValue::class.java) - value.timeAsSeconds = 0 - value.value = 0.04 - PowerMockito.`when`(profile.getBasalValues()).thenReturn( + + `when`(profile.getBasalValues()).thenReturn( arrayOf( - value + ProfileValue(0, 0.04) ) ) + val basalProgram: BasalProgram = mapProfileToBasalProgram(profile) val basalProgramElement: BasalProgram.Segment = basalProgram.segments[0] assertEquals(5, basalProgramElement.basalRateInHundredthUnitsPerHour)