Rewrites WriteCommandPacketsTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-08 16:42:05 -07:00
parent 4653541a7b
commit 82731361c6

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()
}
}