Merge pull request #2826 from ryanhaining/assertthat_plugins_constraints

Rewrites plugins/constraints/ tests with matchers
This commit is contained in:
Milos Kozak 2023-09-24 10:34:03 +02:00 committed by GitHub
commit b679fd8158
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 93 additions and 93 deletions

View file

@ -1,6 +1,7 @@
package info.nightscout.plugins.constraints.bgQualityCheck package info.nightscout.plugins.constraints.bgQualityCheck
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.core.constraints.ConstraintObject import info.nightscout.core.constraints.ConstraintObject
@ -15,7 +16,6 @@ import info.nightscout.plugins.constraints.R
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
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
@ -62,16 +62,16 @@ class BgQualityCheckPluginTest : TestBase() {
fun runTest() { fun runTest() {
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(null) `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(null)
plugin.processBgData() plugin.processBgData()
Assertions.assertEquals(BgQualityCheck.State.UNKNOWN, plugin.state) assertThat(plugin.state).isEqualTo(BgQualityCheck.State.UNKNOWN)
Assertions.assertEquals(0, plugin.icon()) assertThat(plugin.icon()).isEqualTo(0)
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true) `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
plugin.processBgData() plugin.processBgData()
Assertions.assertEquals(BgQualityCheck.State.FIVE_MIN_DATA, plugin.state) assertThat(plugin.state).isEqualTo(BgQualityCheck.State.FIVE_MIN_DATA)
Assertions.assertEquals(0, plugin.icon()) assertThat(plugin.icon()).isEqualTo(0)
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false) `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
plugin.processBgData() plugin.processBgData()
Assertions.assertEquals(BgQualityCheck.State.RECALCULATED, plugin.state) assertThat(plugin.state).isEqualTo(BgQualityCheck.State.RECALCULATED)
Assertions.assertEquals(R.drawable.ic_baseline_warning_24_yellow, plugin.icon()) assertThat(plugin.icon()).isEqualTo(R.drawable.ic_baseline_warning_24_yellow)
val superData: MutableList<GlucoseValue> = ArrayList() val superData: MutableList<GlucoseValue> = ArrayList()
superData.add( superData.add(
@ -118,10 +118,10 @@ class BgQualityCheckPluginTest : TestBase() {
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true) `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
plugin.processBgData() plugin.processBgData()
Assertions.assertEquals(BgQualityCheck.State.FIVE_MIN_DATA, plugin.state) assertThat(plugin.state).isEqualTo(BgQualityCheck.State.FIVE_MIN_DATA)
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false) `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
plugin.processBgData() plugin.processBgData()
Assertions.assertEquals(BgQualityCheck.State.RECALCULATED, plugin.state) assertThat(plugin.state).isEqualTo(BgQualityCheck.State.RECALCULATED)
val duplicatedData: MutableList<GlucoseValue> = ArrayList() val duplicatedData: MutableList<GlucoseValue> = ArrayList()
duplicatedData.add( duplicatedData.add(
@ -178,8 +178,8 @@ class BgQualityCheckPluginTest : TestBase() {
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true) `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
plugin.processBgData() plugin.processBgData()
Assertions.assertEquals(BgQualityCheck.State.DOUBLED, plugin.state) assertThat(plugin.state).isEqualTo(BgQualityCheck.State.DOUBLED)
Assertions.assertEquals(R.drawable.ic_baseline_warning_24_red, plugin.icon()) assertThat(plugin.icon()).isEqualTo(R.drawable.ic_baseline_warning_24_red)
val identicalData: MutableList<GlucoseValue> = ArrayList() val identicalData: MutableList<GlucoseValue> = ArrayList()
identicalData.add( identicalData.add(
@ -236,7 +236,7 @@ class BgQualityCheckPluginTest : TestBase() {
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false) `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
plugin.processBgData() plugin.processBgData()
Assertions.assertEquals(BgQualityCheck.State.DOUBLED, plugin.state) assertThat(plugin.state).isEqualTo(BgQualityCheck.State.DOUBLED)
// Flat data Libre // Flat data Libre
val flatData: MutableList<GlucoseValue> = ArrayList() val flatData: MutableList<GlucoseValue> = ArrayList()
@ -344,8 +344,8 @@ class BgQualityCheckPluginTest : TestBase() {
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatData[0])) `when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatData[0]))
plugin.processBgData() plugin.processBgData()
Assertions.assertEquals(BgQualityCheck.State.FLAT, plugin.state) assertThat(plugin.state).isEqualTo(BgQualityCheck.State.FLAT)
Assertions.assertEquals(R.drawable.ic_baseline_trending_flat_24, plugin.icon()) assertThat(plugin.icon()).isEqualTo(R.drawable.ic_baseline_trending_flat_24)
// Flat data Libre // Flat data Libre
val flatDataDexcom: MutableList<GlucoseValue> = ArrayList() val flatDataDexcom: MutableList<GlucoseValue> = ArrayList()
@ -453,8 +453,8 @@ class BgQualityCheckPluginTest : TestBase() {
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatDataDexcom[0])) `when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatDataDexcom[0]))
plugin.processBgData() plugin.processBgData()
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state) assertThat(plugin.state).isNotEqualTo(BgQualityCheck.State.FLAT)
Assertions.assertNotEquals(R.drawable.ic_baseline_trending_flat_24, plugin.icon()) assertThat(plugin.icon()).isNotEqualTo(R.drawable.ic_baseline_trending_flat_24)
// not enough data // not enough data
val incompleteData: MutableList<GlucoseValue> = ArrayList() val incompleteData: MutableList<GlucoseValue> = ArrayList()
@ -481,7 +481,7 @@ class BgQualityCheckPluginTest : TestBase() {
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(incompleteData) `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(incompleteData)
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(incompleteData[0])) `when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(incompleteData[0]))
plugin.processBgData()// must be more than 5 values plugin.processBgData()// must be more than 5 values
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state) assertThat(plugin.state).isNotEqualTo(BgQualityCheck.State.FLAT)
flatData.add( flatData.add(
GlucoseValue( GlucoseValue(
raw = 0.0, raw = 0.0,
@ -553,19 +553,19 @@ class BgQualityCheckPluginTest : TestBase() {
) )
) )
plugin.processBgData() // must be at least 45 min old plugin.processBgData() // must be at least 45 min old
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state) assertThat(plugin.state).isNotEqualTo(BgQualityCheck.State.FLAT)
} }
@Test @Test
fun applyMaxIOBConstraintsTest() { fun applyMaxIOBConstraintsTest() {
plugin.state = BgQualityCheck.State.UNKNOWN plugin.state = BgQualityCheck.State.UNKNOWN
Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001) assertThat(plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value()).isWithin(0.001).of(10.0)
plugin.state = BgQualityCheck.State.FIVE_MIN_DATA plugin.state = BgQualityCheck.State.FIVE_MIN_DATA
Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001) assertThat(plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value()).isWithin(0.001).of(10.0)
plugin.state = BgQualityCheck.State.RECALCULATED plugin.state = BgQualityCheck.State.RECALCULATED
Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001) assertThat(plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value()).isWithin(0.001).of(10.0)
plugin.state = BgQualityCheck.State.DOUBLED plugin.state = BgQualityCheck.State.DOUBLED
Assertions.assertEquals(0.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001) assertThat(plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value()).isWithin(0.001).of(0.0)
} }
} }

View file

@ -1,13 +1,13 @@
package info.nightscout.plugins.constraints.dstHelper package info.nightscout.plugins.constraints.dstHelper
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.interfaces.aps.Loop import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
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
@ -41,31 +41,31 @@ class DstHelperPluginTest : TestBase() {
val df: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ITALIAN) val df: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ITALIAN)
var dateBeforeDST = df.parse("2018-03-25 01:55") var dateBeforeDST = df.parse("2018-03-25 01:55")
cal.time = dateBeforeDST!! cal.time = dateBeforeDST!!
Assertions.assertEquals(false, plugin.wasDST(cal)) assertThat(plugin.wasDST(cal)).isFalse()
Assertions.assertEquals(true, plugin.willBeDST(cal)) assertThat(plugin.willBeDST(cal)).isTrue()
TimeZone.setDefault(tz) TimeZone.setDefault(tz)
cal = Calendar.getInstance(tz, Locale.ITALIAN) cal = Calendar.getInstance(tz, Locale.ITALIAN)
dateBeforeDST = df.parse("2018-03-25 03:05") dateBeforeDST = df.parse("2018-03-25 03:05")
cal.time = dateBeforeDST!! cal.time = dateBeforeDST!!
Assertions.assertEquals(true, plugin.wasDST(cal)) assertThat(plugin.wasDST(cal)).isTrue()
Assertions.assertEquals(false, plugin.willBeDST(cal)) assertThat(plugin.willBeDST(cal)).isFalse()
TimeZone.setDefault(tz) TimeZone.setDefault(tz)
cal = Calendar.getInstance(tz, Locale.ITALIAN) cal = Calendar.getInstance(tz, Locale.ITALIAN)
dateBeforeDST = df.parse("2018-03-25 02:05") //Cannot happen!!! dateBeforeDST = df.parse("2018-03-25 02:05") //Cannot happen!!!
cal.time = dateBeforeDST!! cal.time = dateBeforeDST!!
Assertions.assertEquals(true, plugin.wasDST(cal)) assertThat(plugin.wasDST(cal)).isTrue()
Assertions.assertEquals(false, plugin.willBeDST(cal)) assertThat(plugin.willBeDST(cal)).isFalse()
TimeZone.setDefault(tz) TimeZone.setDefault(tz)
cal = Calendar.getInstance(tz, Locale.ITALIAN) cal = Calendar.getInstance(tz, Locale.ITALIAN)
dateBeforeDST = df.parse("2018-03-25 05:55") //Cannot happen!!! dateBeforeDST = df.parse("2018-03-25 05:55") //Cannot happen!!!
cal.time = dateBeforeDST!! cal.time = dateBeforeDST!!
Assertions.assertEquals(true, plugin.wasDST(cal)) assertThat(plugin.wasDST(cal)).isTrue()
Assertions.assertEquals(false, plugin.willBeDST(cal)) assertThat(plugin.willBeDST(cal)).isFalse()
TimeZone.setDefault(tz) TimeZone.setDefault(tz)
cal = Calendar.getInstance(tz, Locale.ITALIAN) cal = Calendar.getInstance(tz, Locale.ITALIAN)
dateBeforeDST = df.parse("2018-03-25 06:05") //Cannot happen!!! dateBeforeDST = df.parse("2018-03-25 06:05") //Cannot happen!!!
cal.time = dateBeforeDST!! cal.time = dateBeforeDST!!
Assertions.assertEquals(false, plugin.wasDST(cal)) assertThat(plugin.wasDST(cal)).isFalse()
Assertions.assertEquals(false, plugin.willBeDST(cal)) assertThat(plugin.willBeDST(cal)).isFalse()
} }
} }

View file

@ -1,6 +1,7 @@
package info.nightscout.plugins.constraints.objectives package info.nightscout.plugins.constraints.objectives
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.core.constraints.ConstraintObject import info.nightscout.core.constraints.ConstraintObject
@ -12,7 +13,6 @@ import info.nightscout.plugins.constraints.objectives.objectives.Objective
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
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
@ -50,29 +50,29 @@ class ObjectivesPluginTest : TestBase() {
@Test fun notStartedObjectivesShouldLimitLoopInvocation() { @Test fun notStartedObjectivesShouldLimitLoopInvocation() {
objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].startedOn = 0 objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].startedOn = 0
val c = objectivesPlugin.isLoopInvocationAllowed(ConstraintObject(true, aapsLogger)) val c = objectivesPlugin.isLoopInvocationAllowed(ConstraintObject(true, aapsLogger))
Assertions.assertEquals("Objectives: Objective 1 not started", c.getReasons()) assertThat(c.getReasons()).isEqualTo("Objectives: Objective 1 not started")
Assertions.assertEquals(false, c.value()) assertThat(c.value()).isFalse()
objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].startedOn = dateUtil.now() objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].startedOn = dateUtil.now()
} }
@Test fun notStartedObjective6ShouldLimitClosedLoop() { @Test fun notStartedObjective6ShouldLimitClosedLoop() {
objectivesPlugin.objectives[Objectives.MAXIOB_ZERO_CL_OBJECTIVE].startedOn = 0 objectivesPlugin.objectives[Objectives.MAXIOB_ZERO_CL_OBJECTIVE].startedOn = 0
val c = objectivesPlugin.isClosedLoopAllowed(ConstraintObject(true, aapsLogger)) val c = objectivesPlugin.isClosedLoopAllowed(ConstraintObject(true, aapsLogger))
Assertions.assertEquals(true, c.getReasons().contains("Objective 6 not started")) assertThat(c.getReasons()).contains("Objective 6 not started")
Assertions.assertEquals(false, c.value()) assertThat(c.value()).isFalse()
} }
@Test fun notStartedObjective8ShouldLimitAutosensMode() { @Test fun notStartedObjective8ShouldLimitAutosensMode() {
objectivesPlugin.objectives[Objectives.AUTOSENS_OBJECTIVE].startedOn = 0 objectivesPlugin.objectives[Objectives.AUTOSENS_OBJECTIVE].startedOn = 0
val c = objectivesPlugin.isAutosensModeEnabled(ConstraintObject(true, aapsLogger)) val c = objectivesPlugin.isAutosensModeEnabled(ConstraintObject(true, aapsLogger))
Assertions.assertEquals(true, c.getReasons().contains("Objective 8 not started")) assertThat(c.getReasons()).contains("Objective 8 not started")
Assertions.assertEquals(false, c.value()) assertThat(c.value()).isFalse()
} }
@Test fun notStartedObjective10ShouldLimitSMBMode() { @Test fun notStartedObjective10ShouldLimitSMBMode() {
objectivesPlugin.objectives[Objectives.SMB_OBJECTIVE].startedOn = 0 objectivesPlugin.objectives[Objectives.SMB_OBJECTIVE].startedOn = 0
val c = objectivesPlugin.isSMBModeEnabled(ConstraintObject(true, aapsLogger)) val c = objectivesPlugin.isSMBModeEnabled(ConstraintObject(true, aapsLogger))
Assertions.assertEquals(true, c.getReasons().contains("Objective 9 not started")) assertThat(c.getReasons()).contains("Objective 9 not started")
Assertions.assertEquals(false, c.value()) assertThat(c.value()).isFalse()
} }
} }

View file

@ -1,7 +1,7 @@
package info.nightscout.plugins.constraints.signatureVerifier package info.nightscout.plugins.constraints.signatureVerifier
import app.aaps.shared.tests.TestBase import app.aaps.shared.tests.TestBase
import org.junit.jupiter.api.Assertions import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class SignatureVerifierPluginTest : TestBase() { class SignatureVerifierPluginTest : TestBase() {
@ -25,6 +25,6 @@ class SignatureVerifierPluginTest : TestBase() {
fun singleCharUnMapTest() { fun singleCharUnMapTest() {
@Suppress("SpellCheckingInspection") val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε" @Suppress("SpellCheckingInspection") val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε"
val unmapped = singleCharUnMap(key) val unmapped = singleCharUnMap(key)
Assertions.assertEquals("32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95", unmapped) assertThat(unmapped).isEqualTo("32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95")
} }
} }

View file

@ -1,6 +1,7 @@
package info.nightscout.plugins.constraints.signatureVerifier package info.nightscout.plugins.constraints.signatureVerifier
import app.aaps.shared.tests.TestBase import app.aaps.shared.tests.TestBase
import com.google.common.truth.Truth.assertThat
import dagger.Lazy import dagger.Lazy
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.interfaces.receivers.ReceiverStatusStore
@ -11,7 +12,6 @@ import info.nightscout.plugins.constraints.versionChecker.numericVersionPart
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyInt
@ -39,97 +39,97 @@ class VersionCheckerUtilsKtTest : TestBase() {
@Test @Test
fun `should handle invalid version`() { fun `should handle invalid version`() {
Assertions.assertArrayEquals(intArrayOf(), versionCheckerUtils.versionDigits("definitely not version string")) assertThat(versionCheckerUtils.versionDigits("definitely not version string")).isEmpty()
} }
@Test @Test
fun `should handle empty version`() { fun `should handle empty version`() {
Assertions.assertArrayEquals(intArrayOf(), versionCheckerUtils.versionDigits("")) assertThat(versionCheckerUtils.versionDigits("")).isEmpty()
} }
@Test @Test
fun `should parse 2 digit version`() { fun `should parse 2 digit version`() {
Assertions.assertArrayEquals(intArrayOf(0, 999), versionCheckerUtils.versionDigits("0.999-beta")) assertThat(versionCheckerUtils.versionDigits("0.999-beta")).asList().containsExactly(0, 999).inOrder()
} }
@Test @Test
fun `should parse 3 digit version`() { fun `should parse 3 digit version`() {
Assertions.assertArrayEquals(intArrayOf(6, 83, 93), versionCheckerUtils.versionDigits("6.83.93")) assertThat(versionCheckerUtils.versionDigits("6.83.93")).asList().containsExactly(6, 83, 93).inOrder()
} }
@Test @Test
fun `should parse 4 digit version`() { fun `should parse 4 digit version`() {
Assertions.assertArrayEquals(intArrayOf(42, 7, 13, 101), versionCheckerUtils.versionDigits("42.7.13.101")) assertThat(versionCheckerUtils.versionDigits("42.7.13.101")).asList().containsExactly(42, 7, 13, 101).inOrder()
} }
@Test @Test
fun `should parse 4 digit version with extra`() { fun `should parse 4 digit version with extra`() {
Assertions.assertArrayEquals(intArrayOf(1, 2, 3, 4), versionCheckerUtils.versionDigits("1.2.3.4-RC5")) assertThat(versionCheckerUtils.versionDigits("1.2.3.4-RC5")).asList().containsExactly(1, 2, 3, 4).inOrder()
} }
@Test @Test
fun `should parse version but only 4 digits are taken`() { fun `should parse version but only 4 digits are taken`() {
Assertions.assertArrayEquals(intArrayOf(67, 8, 31, 5), versionCheckerUtils.versionDigits("67.8.31.5.153.4.2")) assertThat(versionCheckerUtils.versionDigits("67.8.31.5.153.4.2")).asList().containsExactly(67, 8, 31, 5).inOrder()
} }
@Test @Test
fun `should keep 2 digit version`() { fun `should keep 2 digit version`() {
Assertions.assertEquals("1.2", "1.2".numericVersionPart()) assertThat("1.2".numericVersionPart()).isEqualTo("1.2")
} }
@Test @Test
fun `should keep 3 digit version`() { fun `should keep 3 digit version`() {
Assertions.assertEquals("1.2.3", "1.2.3".numericVersionPart()) assertThat("1.2.3".numericVersionPart()).isEqualTo("1.2.3")
} }
@Test @Test
fun `should keep 4 digit version`() { fun `should keep 4 digit version`() {
Assertions.assertEquals("1.2.3.4", "1.2.3.4".numericVersionPart()) assertThat("1.2.3.4".numericVersionPart()).isEqualTo("1.2.3.4")
} }
@Test @Test
fun `should strip 2 digit version RC`() { fun `should strip 2 digit version RC`() {
Assertions.assertEquals("1.2", "1.2-RC1".numericVersionPart()) assertThat("1.2-RC1".numericVersionPart()).isEqualTo("1.2")
} }
@Test @Test
fun `should strip 2 digit version RC old format`() { fun `should strip 2 digit version RC old format`() {
Assertions.assertEquals("1.2", "1.2RC1".numericVersionPart()) assertThat("1.2RC1".numericVersionPart()).isEqualTo("1.2")
} }
@Test @Test
fun `should strip 2 digit version RC without digit`() { fun `should strip 2 digit version RC without digit`() {
Assertions.assertEquals("1.2", "1.2-RC".numericVersionPart()) assertThat("1.2-RC".numericVersionPart()).isEqualTo("1.2")
} }
@Test @Test
fun `should strip 2 digit version dev`() { fun `should strip 2 digit version dev`() {
Assertions.assertEquals("1.2", "1.2-dev".numericVersionPart()) assertThat("1.2-dev".numericVersionPart()).isEqualTo("1.2")
} }
@Test @Test
fun `should strip 2 digit version dev old format 1`() { fun `should strip 2 digit version dev old format 1`() {
Assertions.assertEquals("1.2", "1.2dev".numericVersionPart()) assertThat("1.2dev".numericVersionPart()).isEqualTo("1.2")
} }
@Test @Test
fun `should strip 2 digit version dev old format 2`() { fun `should strip 2 digit version dev old format 2`() {
Assertions.assertEquals("1.2", "1.2dev-a3".numericVersionPart()) assertThat("1.2dev-a3".numericVersionPart()).isEqualTo("1.2")
} }
@Test @Test
fun `should strip 3 digit version RC`() { fun `should strip 3 digit version RC`() {
Assertions.assertEquals("1.2.3", "1.2.3-RC1".numericVersionPart()) assertThat("1.2.3-RC1".numericVersionPart()).isEqualTo("1.2.3")
} }
@Test @Test
fun `should strip 4 digit version RC`() { fun `should strip 4 digit version RC`() {
Assertions.assertEquals("1.2.3.4", "1.2.3.4-RC5".numericVersionPart()) assertThat("1.2.3.4-RC5".numericVersionPart()).isEqualTo("1.2.3.4")
} }
@Test @Test
fun `should strip even with dot`() { fun `should strip even with dot`() {
Assertions.assertEquals("1.2", "1.2.RC5".numericVersionPart()) assertThat("1.2.RC5".numericVersionPart()).isEqualTo("1.2")
} }
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ -143,7 +143,7 @@ class VersionCheckerUtilsKtTest : TestBase() {
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle) val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
Assertions.assertEquals("2.2.2", detectedVersion) assertThat(detectedVersion).isEqualTo("2.2.2")
} }
// In case we merge a "x.x.x-dev" into master, don't see it as update. // In case we merge a "x.x.x-dev" into master, don't see it as update.
@ -157,14 +157,14 @@ class VersionCheckerUtilsKtTest : TestBase() {
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle) val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
Assertions.assertEquals(null, detectedVersion) assertThat(detectedVersion).isNull()
} }
@Test @Test
fun findVersionMatchesDoesNotMatchErrorResponse() { fun findVersionMatchesDoesNotMatchErrorResponse() {
val buildGradle = """<html><body>Balls! No build.gradle here. Move along</body><html>""" val buildGradle = """<html><body>Balls! No build.gradle here. Move along</body><html>"""
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle) val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
Assertions.assertEquals(null, detectedVersion) assertThat(detectedVersion).isNull()
} }
@Test @Test
@ -375,7 +375,7 @@ class VersionCheckerUtilsKtTest : TestBase() {
@BeforeEach @BeforeEach
fun `set time`() { fun `set time`() {
`when`(dateUtil.now()).thenReturn(10000000000L) `when`(dateUtil.now()).thenReturn(10000000000L)
Assertions.assertEquals(10000000000L, dateUtil.now()) assertThat(dateUtil.now()).isEqualTo(10000000000L)
`when`(rh.gs(anyInt(), anyString())).thenReturn("") `when`(rh.gs(anyInt(), anyString())).thenReturn("")
} }

View file

@ -1,13 +1,13 @@
package info.nightscout.plugins.constraints.storage package info.nightscout.plugins.constraints.storage
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.core.constraints.ConstraintObject import info.nightscout.core.constraints.ConstraintObject
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
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
@ -42,9 +42,9 @@ class StorageConstraintPluginTest : TestBase() {
val mocked = MockedStorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, uiInteraction) val mocked = MockedStorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, uiInteraction)
// Set free space under 200(Mb) to disable loop // Set free space under 200(Mb) to disable loop
mocked.memSize = 150L mocked.memSize = 150L
Assertions.assertEquals(false, mocked.isClosedLoopAllowed(ConstraintObject(true, aapsLogger)).value()) assertThat(mocked.isClosedLoopAllowed(ConstraintObject(true, aapsLogger)).value()).isFalse()
// Set free space over 200(Mb) to enable loop // Set free space over 200(Mb) to enable loop
mocked.memSize = 300L mocked.memSize = 300L
Assertions.assertEquals(true, mocked.isClosedLoopAllowed(ConstraintObject(true, aapsLogger)).value()) assertThat(mocked.isClosedLoopAllowed(ConstraintObject(true, aapsLogger)).value()).isTrue()
} }
} }

View file

@ -1,10 +1,10 @@
package info.nightscout.plugins.constraints.versionChecker package info.nightscout.plugins.constraints.versionChecker
import com.google.common.truth.Truth.assertThat
import info.nightscout.plugins.constraints.versionChecker.AllowedVersions import info.nightscout.plugins.constraints.versionChecker.AllowedVersions
import org.joda.time.LocalDate import org.joda.time.LocalDate
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class AllowedVersionsTest { class AllowedVersionsTest {
@ -45,14 +45,14 @@ class AllowedVersionsTest {
@Test @Test
fun generateSupportedVersionsTest() { fun generateSupportedVersionsTest() {
val definition = generateSupportedVersions() val definition = generateSupportedVersions()
Assertions.assertNull(AllowedVersions().findByApi(definition, 0)) assertThat(AllowedVersions().findByApi(definition, 0)).isNull()
Assertions.assertFalse(AllowedVersions().findByApi(definition, 1)?.has("supported") ?: true) assertThat(AllowedVersions().findByApi(definition, 1)!!.has("supported")).isFalse()
Assertions.assertFalse(AllowedVersions().findByApi(definition, 23)?.has("supported") ?: true) assertThat(AllowedVersions().findByApi(definition, 23)!!.has("supported")).isFalse()
Assertions.assertEquals("2.6.2", AllowedVersions().findByApi(definition, 24)?.getString("supported")) assertThat(AllowedVersions().findByApi(definition, 24)!!.getString("supported")).isEqualTo("2.6.2")
Assertions.assertEquals("2.6.2", AllowedVersions().findByApi(definition, 25)?.getString("supported")) assertThat(AllowedVersions().findByApi(definition, 25)!!.getString("supported")).isEqualTo("2.6.2")
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 26)?.getString("supported")) assertThat(AllowedVersions().findByApi(definition, 26)!!.getString("supported")).isEqualTo("2.8.2")
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 27)?.getString("supported")) assertThat(AllowedVersions().findByApi(definition, 27)!!.getString("supported")).isEqualTo("2.8.2")
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 28)?.getString("supported")) assertThat(AllowedVersions().findByApi(definition, 28)!!.getString("supported")).isEqualTo("2.8.2")
} }
@Test @Test
@ -62,9 +62,9 @@ class AllowedVersionsTest {
"[{\"minAndroid\":1,\"maxAndroid\":23},{\"minAndroid\":24,\"maxAndroid\":25,\"supported\":\"2.6.2\"},{\"minAndroid\":26,\"maxAndroid\":27,\"supported\":\"2.8.2\"},{\"minAndroid\":28,\"maxAndroid\":99,\"supported\":\"2.8.2\"},{\"endDate\":\"2021-11-07\",\"version\":\"2.9.0-beta1\"},{\"endDate\":\"2021-11-02\",\"version\":\"3.0-beta1\"},{\"endDate\":\"2021-11-04\",\"version\":\"3.0-beta2\"},{\"endDate\":\"2021-11-10\",\"version\":\"3.0-beta3\"},{\"endDate\":\"2021-11-14\",\"version\":\"3.0-beta4\"}\n" + "[{\"minAndroid\":1,\"maxAndroid\":23},{\"minAndroid\":24,\"maxAndroid\":25,\"supported\":\"2.6.2\"},{\"minAndroid\":26,\"maxAndroid\":27,\"supported\":\"2.8.2\"},{\"minAndroid\":28,\"maxAndroid\":99,\"supported\":\"2.8.2\"},{\"endDate\":\"2021-11-07\",\"version\":\"2.9.0-beta1\"},{\"endDate\":\"2021-11-02\",\"version\":\"3.0-beta1\"},{\"endDate\":\"2021-11-04\",\"version\":\"3.0-beta2\"},{\"endDate\":\"2021-11-10\",\"version\":\"3.0-beta3\"},{\"endDate\":\"2021-11-14\",\"version\":\"3.0-beta4\"}\n" +
" ,{\"endDate\":\"2021-11-16\",\"version\":\"3.0-beta5\"}\n" + " ,{\"endDate\":\"2021-11-16\",\"version\":\"3.0-beta5\"}\n" +
"]" "]"
Assertions.assertNull(AllowedVersions().findByVersion(definition, "2.6.0")) assertThat(AllowedVersions().findByVersion(definition, "2.6.0")).isNull()
Assertions.assertTrue(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.has("endDate") ?: false) assertThat(AllowedVersions().findByVersion(definition, "2.9.0-beta1")!!.has("endDate")).isTrue()
Assertions.assertEquals("2021-11-07", AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate")) assertThat(AllowedVersions().findByVersion(definition, "2.9.0-beta1")!!.getString("endDate")).isEqualTo("2021-11-07")
} }
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ -73,10 +73,10 @@ class AllowedVersionsTest {
val definition = generateSupportedVersions() val definition = generateSupportedVersions()
val endDate = AllowedVersions().endDateToMilliseconds(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate") ?: "1000/01/01") val endDate = AllowedVersions().endDateToMilliseconds(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate") ?: "1000/01/01")
val dateTime = LocalDate(endDate) val dateTime = LocalDate(endDate)
Assertions.assertEquals(2021, dateTime.year) assertThat(dateTime.year).isEqualTo(2021)
Assertions.assertEquals(11, dateTime.monthOfYear) assertThat(dateTime.monthOfYear).isEqualTo(11)
Assertions.assertEquals(7, dateTime.dayOfMonth) assertThat(dateTime.dayOfMonth).isEqualTo(7)
Assertions.assertNull(AllowedVersions().endDateToMilliseconds("abdef")) assertThat(AllowedVersions().endDateToMilliseconds("abdef")).isNull()
} }
} }