Merge pull request #2826 from ryanhaining/assertthat_plugins_constraints
Rewrites plugins/constraints/ tests with matchers
This commit is contained in:
commit
b679fd8158
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.plugins.constraints.bgQualityCheck
|
||||
|
||||
import app.aaps.shared.tests.TestBase
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
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.utils.DateUtil
|
||||
import info.nightscout.shared.utils.T
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.ArgumentMatchers.any
|
||||
|
@ -62,16 +62,16 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
fun runTest() {
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(null)
|
||||
plugin.processBgData()
|
||||
Assertions.assertEquals(BgQualityCheck.State.UNKNOWN, plugin.state)
|
||||
Assertions.assertEquals(0, plugin.icon())
|
||||
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.UNKNOWN)
|
||||
assertThat(plugin.icon()).isEqualTo(0)
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
||||
plugin.processBgData()
|
||||
Assertions.assertEquals(BgQualityCheck.State.FIVE_MIN_DATA, plugin.state)
|
||||
Assertions.assertEquals(0, plugin.icon())
|
||||
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.FIVE_MIN_DATA)
|
||||
assertThat(plugin.icon()).isEqualTo(0)
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
||||
plugin.processBgData()
|
||||
Assertions.assertEquals(BgQualityCheck.State.RECALCULATED, plugin.state)
|
||||
Assertions.assertEquals(R.drawable.ic_baseline_warning_24_yellow, plugin.icon())
|
||||
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.RECALCULATED)
|
||||
assertThat(plugin.icon()).isEqualTo(R.drawable.ic_baseline_warning_24_yellow)
|
||||
|
||||
val superData: MutableList<GlucoseValue> = ArrayList()
|
||||
superData.add(
|
||||
|
@ -118,10 +118,10 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
||||
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)
|
||||
plugin.processBgData()
|
||||
Assertions.assertEquals(BgQualityCheck.State.RECALCULATED, plugin.state)
|
||||
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.RECALCULATED)
|
||||
|
||||
val duplicatedData: MutableList<GlucoseValue> = ArrayList()
|
||||
duplicatedData.add(
|
||||
|
@ -178,8 +178,8 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
||||
plugin.processBgData()
|
||||
Assertions.assertEquals(BgQualityCheck.State.DOUBLED, plugin.state)
|
||||
Assertions.assertEquals(R.drawable.ic_baseline_warning_24_red, plugin.icon())
|
||||
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.DOUBLED)
|
||||
assertThat(plugin.icon()).isEqualTo(R.drawable.ic_baseline_warning_24_red)
|
||||
|
||||
val identicalData: MutableList<GlucoseValue> = ArrayList()
|
||||
identicalData.add(
|
||||
|
@ -236,7 +236,7 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
||||
plugin.processBgData()
|
||||
Assertions.assertEquals(BgQualityCheck.State.DOUBLED, plugin.state)
|
||||
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.DOUBLED)
|
||||
|
||||
// Flat data Libre
|
||||
val flatData: MutableList<GlucoseValue> = ArrayList()
|
||||
|
@ -344,8 +344,8 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatData[0]))
|
||||
|
||||
plugin.processBgData()
|
||||
Assertions.assertEquals(BgQualityCheck.State.FLAT, plugin.state)
|
||||
Assertions.assertEquals(R.drawable.ic_baseline_trending_flat_24, plugin.icon())
|
||||
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.FLAT)
|
||||
assertThat(plugin.icon()).isEqualTo(R.drawable.ic_baseline_trending_flat_24)
|
||||
|
||||
// Flat data Libre
|
||||
val flatDataDexcom: MutableList<GlucoseValue> = ArrayList()
|
||||
|
@ -453,8 +453,8 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatDataDexcom[0]))
|
||||
|
||||
plugin.processBgData()
|
||||
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state)
|
||||
Assertions.assertNotEquals(R.drawable.ic_baseline_trending_flat_24, plugin.icon())
|
||||
assertThat(plugin.state).isNotEqualTo(BgQualityCheck.State.FLAT)
|
||||
assertThat(plugin.icon()).isNotEqualTo(R.drawable.ic_baseline_trending_flat_24)
|
||||
|
||||
// not enough data
|
||||
val incompleteData: MutableList<GlucoseValue> = ArrayList()
|
||||
|
@ -481,7 +481,7 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(incompleteData)
|
||||
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(incompleteData[0]))
|
||||
plugin.processBgData()// must be more than 5 values
|
||||
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state)
|
||||
assertThat(plugin.state).isNotEqualTo(BgQualityCheck.State.FLAT)
|
||||
flatData.add(
|
||||
GlucoseValue(
|
||||
raw = 0.0,
|
||||
|
@ -553,19 +553,19 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
)
|
||||
)
|
||||
plugin.processBgData() // must be at least 45 min old
|
||||
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state)
|
||||
assertThat(plugin.state).isNotEqualTo(BgQualityCheck.State.FLAT)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun applyMaxIOBConstraintsTest() {
|
||||
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
|
||||
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
|
||||
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
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package info.nightscout.plugins.constraints.dstHelper
|
||||
|
||||
import app.aaps.shared.tests.TestBase
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.interfaces.aps.Loop
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mock
|
||||
|
@ -41,31 +41,31 @@ class DstHelperPluginTest : TestBase() {
|
|||
val df: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ITALIAN)
|
||||
var dateBeforeDST = df.parse("2018-03-25 01:55")
|
||||
cal.time = dateBeforeDST!!
|
||||
Assertions.assertEquals(false, plugin.wasDST(cal))
|
||||
Assertions.assertEquals(true, plugin.willBeDST(cal))
|
||||
assertThat(plugin.wasDST(cal)).isFalse()
|
||||
assertThat(plugin.willBeDST(cal)).isTrue()
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 03:05")
|
||||
cal.time = dateBeforeDST!!
|
||||
Assertions.assertEquals(true, plugin.wasDST(cal))
|
||||
Assertions.assertEquals(false, plugin.willBeDST(cal))
|
||||
assertThat(plugin.wasDST(cal)).isTrue()
|
||||
assertThat(plugin.willBeDST(cal)).isFalse()
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 02:05") //Cannot happen!!!
|
||||
cal.time = dateBeforeDST!!
|
||||
Assertions.assertEquals(true, plugin.wasDST(cal))
|
||||
Assertions.assertEquals(false, plugin.willBeDST(cal))
|
||||
assertThat(plugin.wasDST(cal)).isTrue()
|
||||
assertThat(plugin.willBeDST(cal)).isFalse()
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 05:55") //Cannot happen!!!
|
||||
cal.time = dateBeforeDST!!
|
||||
Assertions.assertEquals(true, plugin.wasDST(cal))
|
||||
Assertions.assertEquals(false, plugin.willBeDST(cal))
|
||||
assertThat(plugin.wasDST(cal)).isTrue()
|
||||
assertThat(plugin.willBeDST(cal)).isFalse()
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 06:05") //Cannot happen!!!
|
||||
cal.time = dateBeforeDST!!
|
||||
Assertions.assertEquals(false, plugin.wasDST(cal))
|
||||
Assertions.assertEquals(false, plugin.willBeDST(cal))
|
||||
assertThat(plugin.wasDST(cal)).isFalse()
|
||||
assertThat(plugin.willBeDST(cal)).isFalse()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.plugins.constraints.objectives
|
||||
|
||||
import app.aaps.shared.tests.TestBase
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
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.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mock
|
||||
|
@ -50,29 +50,29 @@ class ObjectivesPluginTest : TestBase() {
|
|||
@Test fun notStartedObjectivesShouldLimitLoopInvocation() {
|
||||
objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].startedOn = 0
|
||||
val c = objectivesPlugin.isLoopInvocationAllowed(ConstraintObject(true, aapsLogger))
|
||||
Assertions.assertEquals("Objectives: Objective 1 not started", c.getReasons())
|
||||
Assertions.assertEquals(false, c.value())
|
||||
assertThat(c.getReasons()).isEqualTo("Objectives: Objective 1 not started")
|
||||
assertThat(c.value()).isFalse()
|
||||
objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].startedOn = dateUtil.now()
|
||||
}
|
||||
|
||||
@Test fun notStartedObjective6ShouldLimitClosedLoop() {
|
||||
objectivesPlugin.objectives[Objectives.MAXIOB_ZERO_CL_OBJECTIVE].startedOn = 0
|
||||
val c = objectivesPlugin.isClosedLoopAllowed(ConstraintObject(true, aapsLogger))
|
||||
Assertions.assertEquals(true, c.getReasons().contains("Objective 6 not started"))
|
||||
Assertions.assertEquals(false, c.value())
|
||||
assertThat(c.getReasons()).contains("Objective 6 not started")
|
||||
assertThat(c.value()).isFalse()
|
||||
}
|
||||
|
||||
@Test fun notStartedObjective8ShouldLimitAutosensMode() {
|
||||
objectivesPlugin.objectives[Objectives.AUTOSENS_OBJECTIVE].startedOn = 0
|
||||
val c = objectivesPlugin.isAutosensModeEnabled(ConstraintObject(true, aapsLogger))
|
||||
Assertions.assertEquals(true, c.getReasons().contains("Objective 8 not started"))
|
||||
Assertions.assertEquals(false, c.value())
|
||||
assertThat(c.getReasons()).contains("Objective 8 not started")
|
||||
assertThat(c.value()).isFalse()
|
||||
}
|
||||
|
||||
@Test fun notStartedObjective10ShouldLimitSMBMode() {
|
||||
objectivesPlugin.objectives[Objectives.SMB_OBJECTIVE].startedOn = 0
|
||||
val c = objectivesPlugin.isSMBModeEnabled(ConstraintObject(true, aapsLogger))
|
||||
Assertions.assertEquals(true, c.getReasons().contains("Objective 9 not started"))
|
||||
Assertions.assertEquals(false, c.value())
|
||||
assertThat(c.getReasons()).contains("Objective 9 not started")
|
||||
assertThat(c.value()).isFalse()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package info.nightscout.plugins.constraints.signatureVerifier
|
||||
|
||||
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
|
||||
|
||||
class SignatureVerifierPluginTest : TestBase() {
|
||||
|
@ -25,6 +25,6 @@ class SignatureVerifierPluginTest : TestBase() {
|
|||
fun singleCharUnMapTest() {
|
||||
@Suppress("SpellCheckingInspection") val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε"
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.plugins.constraints.signatureVerifier
|
||||
|
||||
import app.aaps.shared.tests.TestBase
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import dagger.Lazy
|
||||
import info.nightscout.interfaces.Config
|
||||
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.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.ArgumentMatchers.anyInt
|
||||
|
@ -39,97 +39,97 @@ class VersionCheckerUtilsKtTest : TestBase() {
|
|||
|
||||
@Test
|
||||
fun `should handle invalid version`() {
|
||||
Assertions.assertArrayEquals(intArrayOf(), versionCheckerUtils.versionDigits("definitely not version string"))
|
||||
assertThat(versionCheckerUtils.versionDigits("definitely not version string")).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should handle empty version`() {
|
||||
Assertions.assertArrayEquals(intArrayOf(), versionCheckerUtils.versionDigits(""))
|
||||
assertThat(versionCheckerUtils.versionDigits("")).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
fun `should keep 2 digit version`() {
|
||||
Assertions.assertEquals("1.2", "1.2".numericVersionPart())
|
||||
assertThat("1.2".numericVersionPart()).isEqualTo("1.2")
|
||||
}
|
||||
|
||||
@Test
|
||||
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
|
||||
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
|
||||
fun `should strip 2 digit version RC`() {
|
||||
Assertions.assertEquals("1.2", "1.2-RC1".numericVersionPart())
|
||||
assertThat("1.2-RC1".numericVersionPart()).isEqualTo("1.2")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version RC old format`() {
|
||||
Assertions.assertEquals("1.2", "1.2RC1".numericVersionPart())
|
||||
assertThat("1.2RC1".numericVersionPart()).isEqualTo("1.2")
|
||||
}
|
||||
|
||||
@Test
|
||||
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
|
||||
fun `should strip 2 digit version dev`() {
|
||||
Assertions.assertEquals("1.2", "1.2-dev".numericVersionPart())
|
||||
assertThat("1.2-dev".numericVersionPart()).isEqualTo("1.2")
|
||||
}
|
||||
|
||||
@Test
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
fun `should strip even with dot`() {
|
||||
Assertions.assertEquals("1.2", "1.2.RC5".numericVersionPart())
|
||||
assertThat("1.2.RC5".numericVersionPart()).isEqualTo("1.2")
|
||||
}
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
|
@ -143,7 +143,7 @@ class VersionCheckerUtilsKtTest : TestBase() {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
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.
|
||||
|
@ -157,14 +157,14 @@ class VersionCheckerUtilsKtTest : TestBase() {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
|
||||
Assertions.assertEquals(null, detectedVersion)
|
||||
assertThat(detectedVersion).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findVersionMatchesDoesNotMatchErrorResponse() {
|
||||
val buildGradle = """<html><body>Balls! No build.gradle here. Move along</body><html>"""
|
||||
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
|
||||
Assertions.assertEquals(null, detectedVersion)
|
||||
assertThat(detectedVersion).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -375,7 +375,7 @@ class VersionCheckerUtilsKtTest : TestBase() {
|
|||
@BeforeEach
|
||||
fun `set time`() {
|
||||
`when`(dateUtil.now()).thenReturn(10000000000L)
|
||||
Assertions.assertEquals(10000000000L, dateUtil.now())
|
||||
assertThat(dateUtil.now()).isEqualTo(10000000000L)
|
||||
|
||||
`when`(rh.gs(anyInt(), anyString())).thenReturn("")
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package info.nightscout.plugins.constraints.storage
|
||||
|
||||
import app.aaps.shared.tests.TestBase
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.core.constraints.ConstraintObject
|
||||
import info.nightscout.interfaces.ui.UiInteraction
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mock
|
||||
|
@ -42,9 +42,9 @@ class StorageConstraintPluginTest : TestBase() {
|
|||
val mocked = MockedStorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, uiInteraction)
|
||||
// Set free space under 200(Mb) to disable loop
|
||||
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
|
||||
mocked.memSize = 300L
|
||||
Assertions.assertEquals(true, mocked.isClosedLoopAllowed(ConstraintObject(true, aapsLogger)).value())
|
||||
assertThat(mocked.isClosedLoopAllowed(ConstraintObject(true, aapsLogger)).value()).isTrue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package info.nightscout.plugins.constraints.versionChecker
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import info.nightscout.plugins.constraints.versionChecker.AllowedVersions
|
||||
import org.joda.time.LocalDate
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class AllowedVersionsTest {
|
||||
|
@ -45,14 +45,14 @@ class AllowedVersionsTest {
|
|||
@Test
|
||||
fun generateSupportedVersionsTest() {
|
||||
val definition = generateSupportedVersions()
|
||||
Assertions.assertNull(AllowedVersions().findByApi(definition, 0))
|
||||
Assertions.assertFalse(AllowedVersions().findByApi(definition, 1)?.has("supported") ?: true)
|
||||
Assertions.assertFalse(AllowedVersions().findByApi(definition, 23)?.has("supported") ?: true)
|
||||
Assertions.assertEquals("2.6.2", AllowedVersions().findByApi(definition, 24)?.getString("supported"))
|
||||
Assertions.assertEquals("2.6.2", AllowedVersions().findByApi(definition, 25)?.getString("supported"))
|
||||
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 26)?.getString("supported"))
|
||||
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 27)?.getString("supported"))
|
||||
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 28)?.getString("supported"))
|
||||
assertThat(AllowedVersions().findByApi(definition, 0)).isNull()
|
||||
assertThat(AllowedVersions().findByApi(definition, 1)!!.has("supported")).isFalse()
|
||||
assertThat(AllowedVersions().findByApi(definition, 23)!!.has("supported")).isFalse()
|
||||
assertThat(AllowedVersions().findByApi(definition, 24)!!.getString("supported")).isEqualTo("2.6.2")
|
||||
assertThat(AllowedVersions().findByApi(definition, 25)!!.getString("supported")).isEqualTo("2.6.2")
|
||||
assertThat(AllowedVersions().findByApi(definition, 26)!!.getString("supported")).isEqualTo("2.8.2")
|
||||
assertThat(AllowedVersions().findByApi(definition, 27)!!.getString("supported")).isEqualTo("2.8.2")
|
||||
assertThat(AllowedVersions().findByApi(definition, 28)!!.getString("supported")).isEqualTo("2.8.2")
|
||||
}
|
||||
|
||||
@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" +
|
||||
" ,{\"endDate\":\"2021-11-16\",\"version\":\"3.0-beta5\"}\n" +
|
||||
"]"
|
||||
Assertions.assertNull(AllowedVersions().findByVersion(definition, "2.6.0"))
|
||||
Assertions.assertTrue(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.has("endDate") ?: false)
|
||||
Assertions.assertEquals("2021-11-07", AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate"))
|
||||
assertThat(AllowedVersions().findByVersion(definition, "2.6.0")).isNull()
|
||||
assertThat(AllowedVersions().findByVersion(definition, "2.9.0-beta1")!!.has("endDate")).isTrue()
|
||||
assertThat(AllowedVersions().findByVersion(definition, "2.9.0-beta1")!!.getString("endDate")).isEqualTo("2021-11-07")
|
||||
}
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
|
@ -73,10 +73,10 @@ class AllowedVersionsTest {
|
|||
val definition = generateSupportedVersions()
|
||||
val endDate = AllowedVersions().endDateToMilliseconds(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate") ?: "1000/01/01")
|
||||
val dateTime = LocalDate(endDate)
|
||||
Assertions.assertEquals(2021, dateTime.year)
|
||||
Assertions.assertEquals(11, dateTime.monthOfYear)
|
||||
Assertions.assertEquals(7, dateTime.dayOfMonth)
|
||||
assertThat(dateTime.year).isEqualTo(2021)
|
||||
assertThat(dateTime.monthOfYear).isEqualTo(11)
|
||||
assertThat(dateTime.dayOfMonth).isEqualTo(7)
|
||||
|
||||
Assertions.assertNull(AllowedVersions().endDateToMilliseconds("abdef"))
|
||||
assertThat(AllowedVersions().endDateToMilliseconds("abdef")).isNull()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue