Rewrites DetailedBolusInfoTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-20 22:08:25 -07:00
parent 9958028990
commit 62c5c53304

View file

@ -1,5 +1,6 @@
package info.nightscout.core.data package info.nightscout.core.data
import com.google.common.truth.Truth.assertThat
import android.content.Context import android.content.Context
import com.google.gson.Gson import com.google.gson.Gson
import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.Bolus
@ -8,7 +9,6 @@ import info.nightscout.database.entities.TherapyEvent
import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestBase
import org.apache.commons.lang3.builder.EqualsBuilder import org.apache.commons.lang3.builder.EqualsBuilder
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
@ -18,14 +18,14 @@ class DetailedBolusInfoTest : TestBase() {
@Test fun toStringShouldBeOverloaded() { @Test fun toStringShouldBeOverloaded() {
val detailedBolusInfo = DetailedBolusInfo() val detailedBolusInfo = DetailedBolusInfo()
Assertions.assertEquals(true, detailedBolusInfo.toJsonString().contains("insulin")) assertThat(detailedBolusInfo.toJsonString()).contains("insulin")
} }
@Test fun copyShouldCopyAllProperties() { @Test fun copyShouldCopyAllProperties() {
val d1 = DetailedBolusInfo() val d1 = DetailedBolusInfo()
d1.deliverAtTheLatest = 123 d1.deliverAtTheLatest = 123
val d2 = d1.copy() val d2 = d1.copy()
Assertions.assertTrue(EqualsBuilder.reflectionEquals(d2, d1, arrayListOf("id"))) assertThat(EqualsBuilder.reflectionEquals(d2, d1, arrayListOf("id"))).isTrue()
} }
private fun fromJsonString(json: String): DetailedBolusInfo = private fun fromJsonString(json: String): DetailedBolusInfo =
@ -41,10 +41,10 @@ class DetailedBolusInfoTest : TestBase() {
detailedBolusInfo.eventType = DetailedBolusInfo.EventType.BOLUS_WIZARD detailedBolusInfo.eventType = DetailedBolusInfo.EventType.BOLUS_WIZARD
val serialized = detailedBolusInfo.toJsonString() val serialized = detailedBolusInfo.toJsonString()
val deserialized = fromJsonString(serialized) val deserialized = fromJsonString(serialized)
Assertions.assertEquals(1L, deserialized.bolusCalculatorResult?.timestamp) assertThat(deserialized.bolusCalculatorResult?.timestamp).isEqualTo(1L)
Assertions.assertEquals(DetailedBolusInfo.EventType.BOLUS_WIZARD, deserialized.eventType) assertThat(deserialized.eventType).isEqualTo(DetailedBolusInfo.EventType.BOLUS_WIZARD)
// Context should be excluded // Context should be excluded
Assertions.assertNull(deserialized.context) assertThat(deserialized.context).isNull()
} }
@Test @Test
@ -56,12 +56,12 @@ class DetailedBolusInfoTest : TestBase() {
detailedBolusInfo.glucoseType = DetailedBolusInfo.MeterType.FINGER detailedBolusInfo.glucoseType = DetailedBolusInfo.MeterType.FINGER
val therapyEvent = detailedBolusInfo.createTherapyEvent() val therapyEvent = detailedBolusInfo.createTherapyEvent()
Assertions.assertEquals(1000L, therapyEvent.timestamp) assertThat(therapyEvent.timestamp).isEqualTo(1000L)
Assertions.assertEquals(TherapyEvent.Type.MEAL_BOLUS, therapyEvent.type) assertThat(therapyEvent.type).isEqualTo(TherapyEvent.Type.MEAL_BOLUS)
Assertions.assertEquals(TherapyEvent.GlucoseUnit.MGDL, therapyEvent.glucoseUnit) assertThat(therapyEvent.glucoseUnit).isEqualTo(TherapyEvent.GlucoseUnit.MGDL)
Assertions.assertEquals("note", therapyEvent.note) assertThat(therapyEvent.note).isEqualTo("note")
Assertions.assertEquals(180.0, therapyEvent.glucose) assertThat(therapyEvent.glucose).isEqualTo(180.0)
Assertions.assertEquals(TherapyEvent.MeterType.FINGER, therapyEvent.glucoseType) assertThat(therapyEvent.glucoseType).isEqualTo(TherapyEvent.MeterType.FINGER)
} }
@Test @Test
@ -72,9 +72,9 @@ class DetailedBolusInfoTest : TestBase() {
detailedBolusInfo.insulin = 7.0 detailedBolusInfo.insulin = 7.0
val bolus = detailedBolusInfo.createBolus() val bolus = detailedBolusInfo.createBolus()
Assertions.assertEquals(1000L, bolus.timestamp) assertThat(bolus.timestamp).isEqualTo(1000L)
Assertions.assertEquals(Bolus.Type.SMB, bolus.type) assertThat(bolus.type).isEqualTo(Bolus.Type.SMB)
Assertions.assertEquals(7.0, bolus.amount, 0.01) assertThat(bolus.amount).isWithin(0.01).of(7.0)
} }
@Test @Test
@ -84,8 +84,8 @@ class DetailedBolusInfoTest : TestBase() {
detailedBolusInfo.carbs = 6.0 detailedBolusInfo.carbs = 6.0
val carbs = detailedBolusInfo.createCarbs() val carbs = detailedBolusInfo.createCarbs()
Assertions.assertEquals(1000L, carbs.timestamp) assertThat(carbs.timestamp).isEqualTo(1000L)
Assertions.assertEquals(6.0, carbs.amount, 0.01) assertThat(carbs.amount).isWithin(0.01).of(6.0)
} }
private fun createBolusCalculatorResult(): BolusCalculatorResult = private fun createBolusCalculatorResult(): BolusCalculatorResult =