Rewrites EventDataTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-18 23:50:16 -07:00
parent c5c9aea6d3
commit 8664bc7170

View file

@ -1,7 +1,7 @@
package info.nightscout.rx.weardata package info.nightscout.rx.weardata
import com.google.common.truth.Truth.assertThat
import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.ExperimentalSerializationApi
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.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.api.extension.ExtendWith
@ -21,132 +21,132 @@ class EventDataTest {
@Test @Test
fun serializationTest() { fun serializationTest() {
EventData.ActionPong(1, 2).let { EventData.ActionPong(1, 2).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.WearException(1, byteArrayOf(0xAA.toByte()), "board", "fingerprint", "sdk", "model", "manufacturer", "product").let { EventData.WearException(1, byteArrayOf(0xAA.toByte()), "board", "fingerprint", "sdk", "model", "manufacturer", "product").let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.Error(1).let { EventData.Error(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.CancelBolus(1).let { EventData.CancelBolus(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionResendData("data").let { EventData.ActionResendData("data").let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionPumpStatus(1).let { EventData.ActionPumpStatus(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionLoopStatus(1).let { EventData.ActionLoopStatus(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionTddStatus(1).let { EventData.ActionTddStatus(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionECarbsPreCheck(1, 2, 3).let { EventData.ActionECarbsPreCheck(1, 2, 3).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionBolusPreCheck(1.0, 2).let { EventData.ActionBolusPreCheck(1.0, 2).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionFillPreCheck(1.0).let { EventData.ActionFillPreCheck(1.0).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionFillPresetPreCheck(1).let { EventData.ActionFillPresetPreCheck(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionProfileSwitchSendInitialData(1).let { EventData.ActionProfileSwitchSendInitialData(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionProfileSwitchPreCheck(1, 2).let { EventData.ActionProfileSwitchPreCheck(1, 2).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionWizardPreCheck(1, 2).let { EventData.ActionWizardPreCheck(1, 2).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionQuickWizardPreCheck("guid").let { EventData.ActionQuickWizardPreCheck("guid").let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionHeartRate(1, 2, 3.0, "device").let { EventData.ActionHeartRate(1, 2, 3.0, "device").let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.CANCEL).let { EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.CANCEL).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionWizardConfirmed(1).let { EventData.ActionWizardConfirmed(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionTempTargetConfirmed(false).let { EventData.ActionTempTargetConfirmed(false).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionBolusConfirmed(1.0, 2).let { EventData.ActionBolusConfirmed(1.0, 2).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionECarbsConfirmed(1, 2, 3).let { EventData.ActionECarbsConfirmed(1, 2, 3).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionFillConfirmed(1.0).let { EventData.ActionFillConfirmed(1.0).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionProfileSwitchConfirmed(1, 2).let { EventData.ActionProfileSwitchConfirmed(1, 2).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.OpenLoopRequestConfirmed(1).let { EventData.OpenLoopRequestConfirmed(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.CancelNotification(1).let { EventData.CancelNotification(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
// EventData.ActionGetCustomWatchface(EventData.ActionSetCustomWatchface(CwfData())).let { // EventData.ActionGetCustomWatchface(EventData.ActionSetCustomWatchface(CwfData())).let {
// Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) // assertThat( EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
// Assertions.assertEquals(it, EventData.deserialize(it.serialize())) // assertThat( EventData.deserialize(it.serialize())).isEqualTo(it)
// } // }
EventData.ActionPing(1).let { EventData.ActionPing(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.OpenSettings(1).let { EventData.OpenSettings(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.BolusProgress(1, "status").let { EventData.BolusProgress(1, "status").let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0).let { EventData.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.GraphData(arrayListOf(EventData.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0))).let { EventData.GraphData(arrayListOf(EventData.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0))).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.TreatmentData( EventData.TreatmentData(
arrayListOf(EventData.TreatmentData.TempBasal(1, 2.0, 3, 4.0, 5.0)), arrayListOf(EventData.TreatmentData.TempBasal(1, 2.0, 3, 4.0, 5.0)),
@ -154,44 +154,44 @@ class EventDataTest {
arrayListOf(EventData.TreatmentData.Treatment(1, 2.0, 3.0, true, isValid = true)), arrayListOf(EventData.TreatmentData.Treatment(1, 2.0, 3.0, true, isValid = true)),
arrayListOf(EventData.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0)) arrayListOf(EventData.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0))
).let { ).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.Preferences(1, wearControl = true, true, 2, 3, 4.0, 5.0, 6.0, 7, 8).let { EventData.Preferences(1, wearControl = true, true, 2, 3, 4.0, 5.0, 6.0, 7, 8).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.QuickWizard(arrayListOf(EventData.QuickWizard.QuickWizardEntry("1", "2", 3, 4, 5))).let { EventData.QuickWizard(arrayListOf(EventData.QuickWizard.QuickWizardEntry("1", "2", 3, 4, 5))).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
// EventData.ActionSetCustomWatchface().let { // EventData.ActionSetCustomWatchface().let {
// Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) // assertThat( EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
// Assertions.assertEquals(it, EventData.deserialize(it.serialize())) // assertThat( EventData.deserialize(it.serialize())).isEqualTo(it)
// } // }
EventData.ActionrequestCustomWatchface(true).let { EventData.ActionrequestCustomWatchface(true).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionrequestSetDefaultWatchface(1).let { EventData.ActionrequestSetDefaultWatchface(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ActionProfileSwitchOpenActivity(1, 2).let { EventData.ActionProfileSwitchOpenActivity(1, 2).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.OpenLoopRequest("1", "2", null).let { EventData.OpenLoopRequest("1", "2", null).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.ConfirmAction("1", "2", null).let { EventData.ConfirmAction("1", "2", null).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
EventData.SnoozeAlert(1).let { EventData.SnoozeAlert(1).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
} }
} }
} }