Merge pull request #2886 from ryanhaining/assertthat_pump_medtrum

Rewrites pump/medtrum/ tests with matchers
This commit is contained in:
Milos Kozak 2023-10-09 12:57:50 +02:00 committed by GitHub
commit fb5f54460d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 284 additions and 301 deletions

View file

@ -7,10 +7,10 @@ import app.aaps.core.interfaces.pump.PumpSync
import app.aaps.core.interfaces.pump.defs.PumpType
import app.aaps.core.interfaces.rx.events.EventOverviewBolusProgress
import app.aaps.core.interfaces.utils.T
import com.google.common.truth.Truth.assertThat
import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.util.MedtrumSnUtil
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.mockito.Mockito.mock
@ -43,7 +43,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
// Expected values
val expectedByteArray = byteArrayOf(7, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -20, 36, 2, 100, -123, 2)
Assertions.assertEquals(expectedByteArray.contentToString(), result?.contentToString())
assertThat(result!!.contentToString()).isEqualTo(expectedByteArray.contentToString())
}
@Test fun buildMedtrumProfileArrayGiveProfileWhenValuesTooHighThenReturnNull() {
@ -60,7 +60,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val result = medtrumPump.buildMedtrumProfileArray(profile)
// Expected values
Assertions.assertNull(result)
assertThat(result).isNull()
}
@Test fun getCurrentHourlyBasalFromMedtrumProfileArrayGivenProfileWhenValuesSetThenReturnCorrectValue() {
@ -88,28 +88,28 @@ class MedtrumPumpTest : MedtrumTestBase() {
val zonedDateTime0399 = localDate.atTime(localTime0399).atZone(ZoneId.systemDefault())
val time0399 = zonedDateTime0399.toInstant().toEpochMilli()
val result = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray!!, time0399)
Assertions.assertEquals(2.1, result, 0.01)
assertThat(result).isWithin(0.01).of(2.1)
// For 22:30
val localTime2230 = LocalTime.of(22, 30)
val zonedDateTime2230 = localDate.atTime(localTime2230).atZone(ZoneId.systemDefault())
val time2230 = zonedDateTime2230.toInstant().toEpochMilli()
val result1 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2230)
Assertions.assertEquals(1.7, result1, 0.01)
assertThat(result1).isWithin(0.01).of(1.7)
// For 23:59
val localTime2359 = LocalTime.of(23, 59)
val zonedDateTime2359 = localDate.atTime(localTime2359).atZone(ZoneId.systemDefault())
val time2359 = zonedDateTime2359.toInstant().toEpochMilli()
val result2 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2359)
Assertions.assertEquals(2.0, result2, 0.01)
assertThat(result2).isWithin(0.01).of(2.0)
// For 00:00
val localTime0000 = LocalTime.of(0, 0)
val zonedDateTime0000 = localDate.atTime(localTime0000).atZone(ZoneId.systemDefault())
val time0000 = zonedDateTime0000.toInstant().toEpochMilli()
val result3 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time0000)
Assertions.assertEquals(2.1, result3, 0.01)
assertThat(result3).isWithin(0.01).of(2.1)
}
@Test fun handleBolusStatusUpdateWhenCalledExpectNewData() {
@ -124,9 +124,9 @@ class MedtrumPumpTest : MedtrumTestBase() {
medtrumPump.handleBolusStatusUpdate(bolusType, bolusCompleted, amount)
// Expected values
Assertions.assertEquals(bolusCompleted, medtrumPump.bolusDone)
Assertions.assertEquals(amount, medtrumPump.bolusAmountDeliveredFlow.value, 0.01)
Assertions.assertEquals(amount, medtrumPump.bolusingTreatment!!.insulin, 0.01)
assertThat(medtrumPump.bolusDone).isEqualTo(bolusCompleted)
assertThat(medtrumPump.bolusAmountDeliveredFlow.value).isWithin(0.01).of(amount)
assertThat(medtrumPump.bolusingTreatment!!.insulin).isWithin(0.01).of(amount)
}
@Test fun handleBasalStatusUpdateWhenBasalTypeIsAbsoluteTempAndTemporaryBasalInfoThenExpectNewData() {
@ -174,12 +174,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(basalType, medtrumPump.lastBasalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
}
@Test fun handleBasalStatusUpdateWhenBasalTypeIsAbsoluteTempAndSameExpectedTemporaryBasalInfoThenExpectNoPumpSync() {
@ -223,12 +223,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
)
// Check that other fields in medtrumPump are updated
Assertions.assertEquals(basalType, medtrumPump.lastBasalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
}
@Test fun handleBasalStatusUpdateWhenBasalTypeIsAbsoluteTempAndNoTemporaryBasalInfoThenExpectNewData() {
@ -274,12 +274,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(basalType, medtrumPump.lastBasalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
}
@Test fun handleBasalStatusUpdateWhenBasalTypeIsRelativeTempAndTemporaryBasalInfoThenExpectNewData() {
@ -329,12 +329,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(basalType, medtrumPump.lastBasalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
}
@Test fun handleBasalStatusUpdateWhenBasalTypeIsSuspendedThenExpectNewData() {
@ -378,12 +378,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(basalType, medtrumPump.lastBasalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
}
@Test fun handleBasalStatusUpdateWhenBasalTypeIsATypeIsSuspendedAndSameExpectedTemporaryBasalInfoThenExpectNoPumpSync() {
@ -424,12 +424,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
anyOrNull()
)
Assertions.assertEquals(basalType, medtrumPump.lastBasalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
}
@Test fun handleBasalStatusUpdateWhenBasalTypeIsSuspendedAndNewerFakeTBRThenExpectInvalidateAndNewData() {
@ -475,12 +475,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(basalType, medtrumPump.lastBasalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
}
@Test fun handleBasalStatusUpdateWhenBasalTypeIsNoneAndThenExpectFakeTBR() {
@ -520,12 +520,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(basalType, medtrumPump.lastBasalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
}
@Test fun handleBasalStatusUpdateWhenBasalTypeIsStandardAndTempBasalExpectedThenExpectSyncStop() {
@ -564,12 +564,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(basalType, medtrumPump.lastBasalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
}
@Test fun handleBasalStatusUpdateWhenBasalTypeIsStandardAndNoTempBasalExpectedThenExpectNoSyncStop() {
@ -605,12 +605,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
anyOrNull()
)
Assertions.assertEquals(basalType, medtrumPump.lastBasalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
}
@Test fun handleNewPatchCalledWhenCalledExpectNewDataPresent() {
@ -626,10 +626,10 @@ class MedtrumPumpTest : MedtrumTestBase() {
medtrumPump.handleNewPatch(newPatchId, newSequenceNumber, newStartTime)
// Expected values
Assertions.assertEquals(newPatchId, medtrumPump.patchId)
Assertions.assertEquals(newSequenceNumber, medtrumPump.currentSequenceNumber)
Assertions.assertEquals(newStartTime, medtrumPump.patchStartTime)
Assertions.assertEquals(1, medtrumPump.syncedSequenceNumber)
assertThat(medtrumPump.patchId).isEqualTo(newPatchId)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(newSequenceNumber)
assertThat(medtrumPump.patchStartTime).isEqualTo(newStartTime)
assertThat(medtrumPump.syncedSequenceNumber).isEqualTo(1)
}
@Test fun handleStopStatusUpdateWhenSequenceThenExpectUpdate() {
@ -644,8 +644,8 @@ class MedtrumPumpTest : MedtrumTestBase() {
medtrumPump.handleStopStatusUpdate(sequence, patchId)
// Expected values
Assertions.assertEquals(patchId, medtrumPump.lastStopPatchId)
Assertions.assertEquals(sequence, medtrumPump.currentSequenceNumber)
assertThat(medtrumPump.lastStopPatchId).isEqualTo(patchId)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(sequence)
}
@Test fun setFakeTBRIfNotSetWhenNoFakeTBRAlreadyRunningExpectPumpSync() {

View file

@ -1,6 +1,6 @@
package info.nightscout.pump.medtrum.comm
import org.junit.jupiter.api.Assertions
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
class WriteCommandPacketsTest {
@ -8,20 +8,20 @@ class WriteCommandPacketsTest {
@Test
fun given14LongCommandExpectOnePacket() {
val input = byteArrayOf(5, 2, 0, 0, 0, 0, -21, 57, -122, -56)
val expect = byteArrayOf(14, 5, 0, 0, 2, 0, 0, 0, 0, -21, 57, -122, -56, -93, 0)
val expected = byteArrayOf(14, 5, 0, 0, 2, 0, 0, 0, 0, -21, 57, -122, -56, -93, 0)
val sequence = 0
val cmdPackets = WriteCommandPackets(input, sequence)
val output = cmdPackets.getNextPacket()
Assertions.assertEquals(expect.contentToString(), output.contentToString())
assertThat(output.contentToString()).isEqualTo(expected.contentToString())
}
@Test
fun given41LongCommandExpectThreePackets() {
val input = byteArrayOf(18, 0, 12, 0, 3, 0, 1, 30, 32, 3, 16, 14, 0, 0, 1, 7, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -20, 36, 2, 100, -123, 2)
val expect1 = byteArrayOf(41, 18, 0, 1, 0, 12, 0, 3, 0, 1, 30, 32, 3, 16, 14, 0, 0, 1, 7, -121)
val expect2 = byteArrayOf(41, 18, 0, 2, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -3)
val expect3 = byteArrayOf(41, 18, 0, 3, -20, 36, 2, 100, -123, 2, -125, -89)
val expected1 = byteArrayOf(41, 18, 0, 1, 0, 12, 0, 3, 0, 1, 30, 32, 3, 16, 14, 0, 0, 1, 7, -121)
val expected2 = byteArrayOf(41, 18, 0, 2, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -3)
val expected3 = byteArrayOf(41, 18, 0, 3, -20, 36, 2, 100, -123, 2, -125, -89)
val sequence = 0
val cmdPackets = WriteCommandPackets(input, sequence)
@ -31,10 +31,10 @@ class WriteCommandPacketsTest {
val output4 = cmdPackets.getNextPacket()
Assertions.assertEquals(expect1.contentToString(), output1.contentToString())
Assertions.assertEquals(expect2.contentToString(), output2.contentToString())
Assertions.assertEquals(expect3.contentToString(), output3.contentToString())
Assertions.assertNull(output4)
Assertions.assertEquals(true, cmdPackets.allPacketsConsumed())
assertThat(output1.contentToString()).isEqualTo(expected1.contentToString())
assertThat(output2.contentToString()).isEqualTo(expected2.contentToString())
assertThat(output3.contentToString()).isEqualTo(expected3.contentToString())
assertThat(output4).isNull()
assertThat(cmdPackets.allPacketsConsumed()).isTrue()
}
}

View file

@ -2,10 +2,10 @@ package info.nightscout.pump.medtrum.comm.packets
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import com.google.common.truth.Truth.assertThat
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.AlarmSetting
import info.nightscout.pump.medtrum.comm.enums.BasalType
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ActivatePacketTest : MedtrumTestBase() {
@ -38,7 +38,7 @@ class ActivatePacketTest : MedtrumTestBase() {
// Expected values
val expectedByteArray = byteArrayOf(18, 0, 12, 1, 6, 0, 0, 30, 32, 3, 16, 14, 0, 0, 1, 3, 16, 14, 0, 0, 1, 2, 12, 12, 12)
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
assertThat(result.contentToString()).isEqualTo(expectedByteArray.contentToString())
}
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
@ -64,15 +64,15 @@ class ActivatePacketTest : MedtrumTestBase() {
val expectedBasalPatchId = 41L
val expectedBasalStart = 1675605528000L
Assertions.assertEquals(true, result)
Assertions.assertEquals(expectedPatchId, medtrumPump.patchId)
Assertions.assertEquals(expectedTime, medtrumPump.lastTimeReceivedFromPump)
Assertions.assertEquals(expectedBasalType, medtrumPump.lastBasalType)
Assertions.assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(expectedBasalPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(expectedBasalStart, medtrumPump.lastBasalStartTime)
Assertions.assertEquals(basalProfile, medtrumPump.actualBasalProfile)
assertThat(result).isTrue()
assertThat(medtrumPump.patchId).isEqualTo(expectedPatchId)
assertThat(medtrumPump.lastTimeReceivedFromPump).isEqualTo(expectedTime)
assertThat(medtrumPump.lastBasalType).isEqualTo(expectedBasalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(expectedBasalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(expectedBasalSequence)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(expectedBasalPatchId)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(expectedBasalStart)
assertThat(medtrumPump.actualBasalProfile).isEqualTo(basalProfile)
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -84,6 +84,6 @@ class ActivatePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertFalse(result)
assertThat(result).isFalse()
}
}

View file

@ -1,11 +1,11 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumPump
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class AuthorizePacketTest : MedtrumTestBase() {
@ -37,8 +37,7 @@ class AuthorizePacketTest : MedtrumTestBase() {
val key = 3364239851
val type = 2
val expectedByteArray = byteArrayOf(opCode.toByte()) + type.toByte() + medtrumPump.patchSessionToken.toByteArray(4) + key.toByteArray(4)
Assertions.assertEquals(10, result.size)
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
assertThat(result).asList().containsExactlyElementsIn(expectedByteArray.toList()).inOrder()
}
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
@ -57,10 +56,10 @@ class AuthorizePacketTest : MedtrumTestBase() {
// Expected values
val swString = "$swVerX.$swVerY.$swVerZ"
Assertions.assertTrue(result)
Assertions.assertFalse(packet.failed)
Assertions.assertEquals(deviceType, medtrumPump.deviceType)
Assertions.assertEquals(swString, medtrumPump.swVersion)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
assertThat(medtrumPump.deviceType).isEqualTo(deviceType)
assertThat(medtrumPump.swVersion).isEqualTo(swString)
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -75,7 +74,7 @@ class AuthorizePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertFalse(result)
Assertions.assertTrue(packet.failed)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
}
}

View file

@ -1,9 +1,9 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class CancelBolusPacketTest : MedtrumTestBase() {
@ -27,8 +27,6 @@ class CancelBolusPacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
val expectedByteArray = byteArrayOf(opCode.toByte()) + 1.toByte()
Assertions.assertEquals(2, result.size)
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
assertThat(result).asList().containsExactly(opCode.toByte(), 1.toByte()).inOrder()
}
}

View file

@ -1,10 +1,10 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.BasalType
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class CancelTempBasalPacketTest : MedtrumTestBase() {
@ -30,8 +30,7 @@ class CancelTempBasalPacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(1, result.size)
Assertions.assertEquals(opCode.toByte(), result[0])
assertThat(result).asList().containsExactly(opCode.toByte())
}
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
@ -49,12 +48,12 @@ class CancelTempBasalPacketTest : MedtrumTestBase() {
val expectedStartTime = 1679575392000L
val expectedPatchId = 146L
Assertions.assertTrue(result)
Assertions.assertEquals(expectedBasalType, medtrumPump.lastBasalType)
Assertions.assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(expectedStartTime, medtrumPump.lastBasalStartTime)
Assertions.assertEquals(expectedPatchId, medtrumPump.lastBasalPatchId)
assertThat(result).isTrue()
assertThat(medtrumPump.lastBasalType).isEqualTo(expectedBasalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(expectedBasalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(expectedBasalSequence)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(expectedStartTime)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(expectedPatchId)
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -66,7 +65,7 @@ class CancelTempBasalPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertFalse(result)
Assertions.assertTrue(packet.failed)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
}
}

View file

@ -1,10 +1,10 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toInt
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ClearPumpAlarmPacketTest : MedtrumTestBase() {
@ -29,8 +29,8 @@ class ClearPumpAlarmPacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(3, result.size)
Assertions.assertEquals(opCode.toByte(), result[0])
Assertions.assertEquals(clearCode, result.copyOfRange(1, 3).toInt())
assertThat(result).hasLength(3)
assertThat(result[0]).isEqualTo(opCode.toByte())
assertThat(result.copyOfRange(1, 3).toInt()).isEqualTo(clearCode)
}
}

View file

@ -1,10 +1,10 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class GetDeviceTypePacketTest : MedtrumTestBase() {
@ -28,8 +28,7 @@ class GetDeviceTypePacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(1, result.size)
Assertions.assertEquals(opCode.toByte(), result[0])
assertThat(result).asList().containsExactly(opCode.toByte())
}
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
@ -45,10 +44,10 @@ class GetDeviceTypePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
Assertions.assertEquals(deviceType, packet.deviceType)
Assertions.assertEquals(deviceSN, packet.deviceSN)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
assertThat(packet.deviceType).isEqualTo(deviceType)
assertThat(packet.deviceSN).isEqualTo(deviceSN)
}
@ -65,9 +64,9 @@ class GetDeviceTypePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response.sliceArray(0..response.size - 2))
// Expected values
Assertions.assertEquals(false, result)
Assertions.assertEquals(true, packet.failed)
Assertions.assertEquals(0, packet.deviceType)
Assertions.assertEquals(0, packet.deviceSN)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
assertThat(packet.deviceType).isEqualTo(0)
assertThat(packet.deviceSN).isEqualTo(0)
}
}

View file

@ -4,10 +4,10 @@ import app.aaps.core.interfaces.pump.DetailedBolusInfo
import app.aaps.core.interfaces.pump.DetailedBolusInfoStorage
import app.aaps.core.interfaces.pump.PumpSync
import app.aaps.core.interfaces.utils.T
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mock
import org.mockito.Mockito
@ -42,7 +42,7 @@ class GetRecordPacketTest : MedtrumTestBase() {
// Expected values
val expected = byteArrayOf(99, 4, 0, -110, 0)
Assertions.assertEquals(expected.contentToString(), result.contentToString())
assertThat(result).asList().containsExactlyElementsIn(expected.toList()).inOrder()
}
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
@ -54,8 +54,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(data)
// Expected values
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -67,8 +67,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(data)
// Expected values
Assertions.assertEquals(false, result)
Assertions.assertEquals(true, packet.failed)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
}
@Test fun handleResponseGivenBolusRecordWhenAndDetailedBolusInfoPresentThenExpectPumpSyncWithTempId() {
@ -100,10 +100,10 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
Assertions.assertEquals(timestamp, medtrumPump.lastBolusTime)
Assertions.assertEquals(amount, medtrumPump.lastBolusAmount, 0.01)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
assertThat(medtrumPump.lastBolusTime).isEqualTo(timestamp)
assertThat(medtrumPump.lastBolusAmount).isWithin(0.01).of(amount)
}
@Test fun handleResponseGivenBolusRecordWhenAndNoDetailedBolusInfoPresentThenExpectPumpSyncWithPumpId() {
@ -129,10 +129,10 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
Assertions.assertEquals(timestamp, medtrumPump.lastBolusTime)
Assertions.assertEquals(amount, medtrumPump.lastBolusAmount, 0.01)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
assertThat(medtrumPump.lastBolusTime).isEqualTo(timestamp)
assertThat(medtrumPump.lastBolusAmount).isWithin(0.01).of(amount)
}
@Test fun handleResponseGivenExtendedBolusRecordThenExpectPumpSyncWithPumpId() {
@ -157,8 +157,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenComboBolusRecordWhenAndNoDetailedBolusInfoPresentThenExpectPumpSyncWithPumpId() {
@ -195,8 +195,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenBasalRecordWhenAbsoluteTempThenExpectPumpSync() {
@ -223,8 +223,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenBasalRecordWhenRelativeTempThenExpectPumpSync() {
@ -251,8 +251,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenBasalRecordWhenSuspendThenExpectPumpSync() {
@ -279,8 +279,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenBasalRecordWhenStandardAndSuspendEndReasonThenExpectPumpSync() {
@ -315,8 +315,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenBasalRecordWhenTempAndSuspendEndReasonThenExpectPumpSync() {
@ -351,8 +351,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenBasalRecordWhenStandardAndSuspendEndReasonAndNewerExistingTBRThenExpectNoPumpSync() {
@ -391,8 +391,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenTDDRecordThenExpectPumpSync() {
@ -421,7 +421,7 @@ class GetRecordPacketTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
)
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
}

View file

@ -1,11 +1,11 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class GetTimePacketTest : MedtrumTestBase() {
@ -30,8 +30,7 @@ class GetTimePacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(1, result.size)
Assertions.assertEquals(opCode.toByte(), result[0])
assertThat(result).asList().containsExactly(opCode.toByte())
}
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
@ -46,9 +45,9 @@ class GetTimePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
Assertions.assertEquals(MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(time), medtrumPump.lastTimeReceivedFromPump)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
assertThat(medtrumPump.lastTimeReceivedFromPump).isEqualTo(MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(time))
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -63,8 +62,8 @@ class GetTimePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response.sliceArray(0..response.size - 2))
// Expected values
Assertions.assertEquals(false, result)
Assertions.assertEquals(true, packet.failed)
Assertions.assertEquals(0, medtrumPump.lastTimeReceivedFromPump)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
assertThat(medtrumPump.lastTimeReceivedFromPump).isEqualTo(0)
}
}

View file

@ -1,10 +1,10 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class MedtrumPacketTest : MedtrumTestBase() {
@ -29,8 +29,7 @@ class MedtrumPacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(result.size, 1)
Assertions.assertEquals(result[0], opCode.toByte())
assertThat(result).asList().containsExactly(opCode.toByte())
}
@Test fun handleResponseGivenResponseWhenOpcodeIsCorrectThenResultTrue() {
@ -45,8 +44,8 @@ class MedtrumPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(result, true)
Assertions.assertEquals(packet.failed, false)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenResponseWhenOpcodeIsIncorrectThenResultFalse() {
@ -61,8 +60,8 @@ class MedtrumPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(result, false)
Assertions.assertEquals(packet.failed, true)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
}
@Test fun handleResponseGivenResponseWhenResponseCodeIsWaitingThenResultFalse() {
@ -77,8 +76,8 @@ class MedtrumPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(result, false)
Assertions.assertEquals(packet.failed, false)
assertThat(result).isFalse()
assertThat(packet.failed).isFalse()
}
@Test fun handleResponseGivenResponseWhenResponseCodeIsErrorThenResultFalse() {
@ -93,8 +92,8 @@ class MedtrumPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(false, result)
Assertions.assertEquals(true, packet.failed)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -108,7 +107,7 @@ class MedtrumPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(false, result)
Assertions.assertEquals(true, packet.failed)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
}
}

View file

@ -1,12 +1,12 @@
package info.nightscout.pump.medtrum.comm.packets
import app.aaps.core.interfaces.rx.events.EventOverviewBolusProgress
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class NotificationPacketTest : MedtrumTestBase() {
@ -30,7 +30,7 @@ class NotificationPacketTest : MedtrumTestBase() {
NotificationPacket(packetInjector).handleNotification(byteArrayOf(state))
// Expected values
Assertions.assertEquals(medtrumPump.pumpState, MedtrumPumpState.fromByte(state))
assertThat(MedtrumPumpState.fromByte(state)).isEqualTo(medtrumPump.pumpState)
}
@Test fun handleNotificationGivenBasalDataThenDataSaved() {
@ -41,12 +41,12 @@ class NotificationPacketTest : MedtrumTestBase() {
NotificationPacket(packetInjector).handleNotification(data)
// Expected values
Assertions.assertEquals(BasalType.ABSOLUTE_TEMP, medtrumPump.lastBasalType)
Assertions.assertEquals(0.85, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(25, medtrumPump.lastBasalSequence)
Assertions.assertEquals(14, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(1685126612000, medtrumPump.lastBasalStartTime)
Assertions.assertEquals(186.80, medtrumPump.reservoir, 0.01)
assertThat(medtrumPump.lastBasalType).isEqualTo(BasalType.ABSOLUTE_TEMP)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(0.85)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(25)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(14)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(1685126612000)
assertThat(medtrumPump.reservoir).isWithin(0.01).of(186.80)
}
@Test fun handleNotificationGivenSequenceAndOtherDataThenDataSaved() {
@ -57,7 +57,7 @@ class NotificationPacketTest : MedtrumTestBase() {
NotificationPacket(packetInjector).handleNotification(data)
// Expected values
Assertions.assertEquals(167, medtrumPump.currentSequenceNumber)
assertThat(medtrumPump.currentSequenceNumber).isEqualTo(167)
}
@Test fun handleNotificationGivenBolusInProgressThenDataSaved() {
@ -69,9 +69,9 @@ class NotificationPacketTest : MedtrumTestBase() {
NotificationPacket(packetInjector).handleNotification(data)
// Expected values
Assertions.assertEquals(false, medtrumPump.bolusDone)
Assertions.assertEquals(0.15, medtrumPump.bolusingTreatment!!.insulin, 0.01)
Assertions.assertEquals(163.5, medtrumPump.reservoir, 0.01)
assertThat(medtrumPump.bolusDone).isFalse()
assertThat(medtrumPump.bolusingTreatment!!.insulin).isWithin(0.01).of(0.15)
assertThat(medtrumPump.reservoir).isWithin(0.01).of(163.5)
}
@Test fun handleNotificationGivenBolusFinishedThenDataSaved() {
@ -83,8 +83,8 @@ class NotificationPacketTest : MedtrumTestBase() {
NotificationPacket(packetInjector).handleNotification(data)
// Expected values
Assertions.assertEquals(true, medtrumPump.bolusDone)
Assertions.assertEquals(1.65, medtrumPump.bolusingTreatment!!.insulin, 0.01)
Assertions.assertEquals(161.95, medtrumPump.reservoir, 0.01)
assertThat(medtrumPump.bolusDone).isTrue()
assertThat(medtrumPump.bolusingTreatment!!.insulin).isWithin(0.01).of(1.65)
assertThat(medtrumPump.reservoir).isWithin(0.01).of(161.95)
}
}

View file

@ -1,9 +1,9 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class PollPatchPacketTest : MedtrumTestBase() {
@ -27,7 +27,6 @@ class PollPatchPacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(1, result.size)
Assertions.assertEquals(opCode.toByte(), result[0])
assertThat(result).asList().containsExactly(opCode.toByte())
}
}

View file

@ -1,9 +1,9 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class PrimePacketTest : MedtrumTestBase() {
@ -27,7 +27,6 @@ class PrimePacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(1, result.size)
Assertions.assertEquals(opCode.toByte(), result[0])
assertThat(result).asList().containsExactly(opCode.toByte())
}
}

View file

@ -1,10 +1,10 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ReadBolusStatePacketTest : MedtrumTestBase() {
@ -31,9 +31,9 @@ class ReadBolusStatePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertTrue(result)
Assertions.assertFalse(packet.failed)
Assertions.assertEquals(bolusData.contentToString(), packet.bolusData.contentToString())
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
assertThat(packet.bolusData).isEqualTo(bolusData)
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -47,8 +47,8 @@ class ReadBolusStatePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(false, result)
Assertions.assertEquals(true, packet.failed)
Assertions.assertEquals(byteArrayOf().contentToString(), packet.bolusData.contentToString())
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
assertThat(packet.bolusData).isEmpty()
}
}

View file

@ -1,9 +1,9 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ResumePumpPacketTest : MedtrumTestBase() {
@ -27,7 +27,6 @@ class ResumePumpPacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(1, result.size)
Assertions.assertEquals(opCode.toByte(), result[0])
assertThat(result).asList().containsExactly(opCode.toByte())
}
}

View file

@ -1,10 +1,10 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.BasalType
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class SetBasalProfilePacketTest : MedtrumTestBase() {
@ -31,7 +31,7 @@ class SetBasalProfilePacketTest : MedtrumTestBase() {
// Expected values
val expected = byteArrayOf(opCode.toByte()) + 1.toByte() + basalProfile
Assertions.assertEquals(expected.contentToString(), result.contentToString())
assertThat(result).asList().containsExactlyElementsIn(expected.toList()).inOrder()
}
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
@ -50,13 +50,13 @@ class SetBasalProfilePacketTest : MedtrumTestBase() {
val expectedStartTime = 1679575392000L
val expectedPatchId = 146L
Assertions.assertTrue(result)
Assertions.assertEquals(expectedBasalType, medtrumPump.lastBasalType)
Assertions.assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(expectedStartTime, medtrumPump.lastBasalStartTime)
Assertions.assertEquals(expectedPatchId, medtrumPump.lastBasalPatchId)
Assertions.assertEquals(basalProfile, medtrumPump.actualBasalProfile)
assertThat(result).isTrue()
assertThat(medtrumPump.lastBasalType).isEqualTo(expectedBasalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(expectedBasalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(expectedBasalSequence)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(expectedStartTime)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(expectedPatchId)
assertThat(medtrumPump.actualBasalProfile).isEqualTo(basalProfile)
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -69,7 +69,7 @@ class SetBasalProfilePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertFalse(result)
Assertions.assertTrue(packet.failed)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
}
}

View file

@ -1,9 +1,9 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class SetBolusMotorPacketTest : MedtrumTestBase() {
@ -27,8 +27,6 @@ class SetBolusMotorPacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
val expectedByteArray = byteArrayOf(opCode.toByte()) + 0.toByte()
Assertions.assertEquals(2, result.size)
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
assertThat(result).asList().containsExactly(opCode.toByte(), 0.toByte()).inOrder()
}
}

View file

@ -1,9 +1,9 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class SetBolusPacketTest : MedtrumTestBase() {
@ -28,6 +28,6 @@ class SetBolusPacketTest : MedtrumTestBase() {
// Expected values
val expected = byteArrayOf(19, 1, 47, 0, 0)
Assertions.assertEquals(expected.contentToString(), result.contentToString())
assertThat(result).asList().containsExactlyElementsIn(expected.toList()).inOrder()
}
}

View file

@ -1,10 +1,10 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.AlarmSetting
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class SetPatchPacketTest : MedtrumTestBase() {
@ -33,6 +33,6 @@ class SetPatchPacketTest : MedtrumTestBase() {
// Expected values
val expected = byteArrayOf(35, 1, 32, 3, 16, 14, 0, 0, 12, 0, 0, 30)
Assertions.assertEquals(expected.contentToString(), result.contentToString())
assertThat(result).asList().containsExactlyElementsIn(expected.toList()).inOrder()
}
}

View file

@ -1,10 +1,10 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.BasalType
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class SetTempBasalPacketTest : MedtrumTestBase() {
@ -31,7 +31,7 @@ class SetTempBasalPacketTest : MedtrumTestBase() {
// Expected values
val expected = byteArrayOf(24, 6, 25, 0, 60, 0)
Assertions.assertEquals(expected.contentToString(), result.contentToString())
assertThat(result.contentToString()).isEqualTo(expected.contentToString())
}
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
@ -52,12 +52,12 @@ class SetTempBasalPacketTest : MedtrumTestBase() {
val expectedStartTime = 1679575112000L
val expectedPatchId = 146L
Assertions.assertTrue(result)
Assertions.assertEquals(expectedBasalType, medtrumPump.lastBasalType)
Assertions.assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
Assertions.assertEquals(expectedStartTime, medtrumPump.lastBasalStartTime)
Assertions.assertEquals(expectedPatchId, medtrumPump.lastBasalPatchId)
assertThat(result).isTrue()
assertThat(medtrumPump.lastBasalType).isEqualTo(expectedBasalType)
assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(expectedBasalRate)
assertThat(medtrumPump.lastBasalSequence).isEqualTo(expectedBasalSequence)
assertThat(medtrumPump.lastBasalStartTime).isEqualTo(expectedStartTime)
assertThat(medtrumPump.lastBasalPatchId).isEqualTo(expectedPatchId)
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -72,6 +72,6 @@ class SetTempBasalPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertFalse(result)
assertThat(result).isFalse()
}
}

View file

@ -1,11 +1,11 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class SetTimePacketTest : MedtrumTestBase() {
@ -30,8 +30,7 @@ class SetTimePacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
val expectedByteArray = byteArrayOf(opCode.toByte()) + 2.toByte() + time.toByteArray(4)
Assertions.assertEquals(6, result.size)
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
val expected = byteArrayOf(opCode.toByte()) + 2.toByte() + time.toByteArray(4)
assertThat(result).asList().containsExactlyElementsIn(expected.toList()).inOrder()
}
}

View file

@ -1,11 +1,11 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class SetTimeZonePacketTest : MedtrumTestBase() {
@ -35,9 +35,8 @@ class SetTimeZonePacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
val expectedByteArray = byteArrayOf(opCode.toByte()) + offsetMinutes.toByteArray(2) + time.toByteArray(4)
Assertions.assertEquals(7, result.size)
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
val expected = byteArrayOf(opCode.toByte()) + offsetMinutes.toByteArray(2) + time.toByteArray(4)
assertThat(result).asList().containsExactlyElementsIn(expected.toList()).inOrder()
}
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
@ -50,7 +49,7 @@ class SetTimeZonePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertTrue(result)
Assertions.assertEquals(offsetMinutes, medtrumPump.pumpTimeZoneOffset)
assertThat(result).isTrue()
assertThat(medtrumPump.pumpTimeZoneOffset).isEqualTo(offsetMinutes)
}
}

View file

@ -1,9 +1,9 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class StopPatchPacketTest : MedtrumTestBase() {
@ -28,8 +28,7 @@ class StopPatchPacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(1, result.size)
Assertions.assertEquals(opCode.toByte(), result[0])
assertThat(result).asList().containsExactly(opCode.toByte())
}
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
@ -43,9 +42,9 @@ class StopPatchPacketTest : MedtrumTestBase() {
// Expected values
val expectedPatchId = 146L
val expectedStopSequence = 23
Assertions.assertTrue(result)
Assertions.assertEquals(expectedPatchId, medtrumPump.lastStopPatchId)
Assertions.assertEquals(expectedStopSequence, medtrumPump.lastStopSequence)
assertThat(result).isTrue()
assertThat(medtrumPump.lastStopPatchId).isEqualTo(expectedPatchId)
assertThat(medtrumPump.lastStopSequence).isEqualTo(expectedStopSequence)
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -57,7 +56,7 @@ class StopPatchPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertFalse(result)
Assertions.assertTrue(packet.failed)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
}
}

View file

@ -1,10 +1,10 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class SubscribePacketTest : MedtrumTestBase() {
@ -28,8 +28,7 @@ class SubscribePacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
val expectedByteArray = byteArrayOf(opCode.toByte()) + 4095.toByteArray(2)
Assertions.assertEquals(3, result.size)
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
val expected = byteArrayOf(opCode.toByte()) + 4095.toByteArray(2)
assertThat(result).asList().containsExactlyElementsIn(expected.toList()).inOrder()
}
}

View file

@ -1,12 +1,12 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import info.nightscout.pump.medtrum.extension.toByteArray
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class SynchronizePacketTest : MedtrumTestBase() {
@ -35,8 +35,7 @@ class SynchronizePacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(1, result.size)
Assertions.assertEquals(opCode.toByte(), result[0])
assertThat(result).asList().containsExactly(opCode.toByte())
}
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
@ -53,9 +52,9 @@ class SynchronizePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
Assertions.assertEquals(state, packet.medtrumPump.pumpState.state)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
assertThat(packet.medtrumPump.pumpState.state).isEqualTo(state)
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -71,13 +70,13 @@ class SynchronizePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(false, result)
Assertions.assertEquals(true, packet.failed)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
}
@Test fun handleResponseContainingSyncDataThenDataSaved() {
// Inputs
val data =
val byteData =
byteArrayOf(
47,
3,
@ -130,21 +129,21 @@ class SynchronizePacketTest : MedtrumTestBase() {
// Call
val packet = SynchronizePacket(packetInjector)
val result = packet.handleResponse(data)
val result = packet.handleResponse(byteData)
// Expected values
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
Assertions.assertEquals(MedtrumPumpState.ACTIVE, packet.medtrumPump.pumpState)
Assertions.assertEquals(BasalType.ABSOLUTE_TEMP, packet.medtrumPump.lastBasalType)
Assertions.assertEquals(0.85, packet.medtrumPump.lastBasalRate, 0.01)
Assertions.assertEquals(25, packet.medtrumPump.lastBasalSequence)
Assertions.assertEquals(14, packet.medtrumPump.lastBasalPatchId)
Assertions.assertEquals(1685126612000, packet.medtrumPump.lastBasalStartTime)
Assertions.assertEquals(8123, packet.medtrumPump.patchAge)
Assertions.assertEquals(186.80, packet.medtrumPump.reservoir, 0.01)
Assertions.assertEquals(1685120120000, packet.medtrumPump.patchStartTime)
Assertions.assertEquals(5.96875, packet.medtrumPump.batteryVoltage_A, 0.01)
Assertions.assertEquals(2.8125, packet.medtrumPump.batteryVoltage_B, 0.01)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
assertThat(packet.medtrumPump.pumpState).isEqualTo(MedtrumPumpState.ACTIVE)
assertThat(packet.medtrumPump.lastBasalType).isEqualTo(BasalType.ABSOLUTE_TEMP)
assertThat(packet.medtrumPump.lastBasalRate).isWithin(0.01).of(0.85)
assertThat(packet.medtrumPump.lastBasalSequence).isEqualTo(25)
assertThat(packet.medtrumPump.lastBasalPatchId).isEqualTo(14)
assertThat(packet.medtrumPump.lastBasalStartTime).isEqualTo(1685126612000)
assertThat(packet.medtrumPump.patchAge).isEqualTo(8123)
assertThat(packet.medtrumPump.reservoir).isWithin(0.01).of(186.80)
assertThat(packet.medtrumPump.patchStartTime).isEqualTo(1685120120000)
assertThat(packet.medtrumPump.batteryVoltage_A).isWithin(0.01).of(5.96875)
assertThat(packet.medtrumPump.batteryVoltage_B).isWithin(0.01).of(2.8125)
}
}

View file

@ -1,6 +1,6 @@
package info.nightscout.pump.medtrum.encryption
import org.junit.jupiter.api.Assertions
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
class CryptTest {
@ -10,9 +10,9 @@ class CryptTest {
val crypt = Crypt()
val input = 2859923929
val expect = 3364239851
val expected = 3364239851L
val output: Long = crypt.keyGen(input)
Assertions.assertEquals(expect, output)
assertThat(output).isEqualTo(expected)
}
@Test
@ -20,8 +20,8 @@ class CryptTest {
val crypt = Crypt()
val input = 2859923929
val expect: Long = 126009121
val expected = 126009121L
val output: Long = crypt.simpleDecrypt(input)
Assertions.assertEquals(expect, output)
assertThat(output).isEqualTo(expected)
}
}