Merge pull request #2800 from ryanhaining/assertthat_app_wear_shared
Rewrites app-wear-shared/ tests to use assertThat and matchers
This commit is contained in:
commit
434986fddf
4 changed files with 205 additions and 205 deletions
|
@ -1,8 +1,8 @@
|
|||
package info.nightscout.shared.impl.logging
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import info.nightscout.rx.logging.LTag
|
||||
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.junit.jupiter.api.extension.ExtendWith
|
||||
|
@ -26,13 +26,13 @@ class LImplTest {
|
|||
|
||||
@Test
|
||||
fun findByName() {
|
||||
Assertions.assertEquals(LTag.APS.name, sut.findByName("APS").name)
|
||||
Assertions.assertEquals("NONEXISTENT", sut.findByName("APS2").name)
|
||||
assertThat(sut.findByName("APS").name).isEqualTo(LTag.APS.name)
|
||||
assertThat(sut.findByName("APS2").name).isEqualTo("NONEXISTENT")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getLogElements() {
|
||||
Assertions.assertTrue(sut.getLogElements().isNotEmpty())
|
||||
assertThat(sut.getLogElements()).isNotEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -40,6 +40,6 @@ class LImplTest {
|
|||
val element = sut.findByName("APS")
|
||||
element.enabled = false
|
||||
sut.resetToDefaults()
|
||||
Assertions.assertTrue(element.enabled)
|
||||
assertThat(element.enabled).isTrue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package info.nightscout.shared.impl.sharedPreferences
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import android.content.Context
|
||||
import info.nightscout.shared.impl.SharedPreferencesMock
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
@ -34,153 +34,153 @@ class SPImplementationTest {
|
|||
@Test
|
||||
fun edit() {
|
||||
sut.edit { putBoolean("test", true) }
|
||||
Assertions.assertTrue(sut.getBoolean("test", false))
|
||||
assertThat(sut.getBoolean("test", false)).isTrue()
|
||||
sut.edit { remove("test") }
|
||||
Assertions.assertFalse(sut.contains("test"))
|
||||
assertThat(sut.contains("test")).isFalse()
|
||||
sut.edit { putBoolean(someResource, true) }
|
||||
Assertions.assertTrue(sut.getBoolean(someResource, false))
|
||||
assertThat(sut.getBoolean(someResource, false)).isTrue()
|
||||
sut.edit { remove(someResource) }
|
||||
Assertions.assertFalse(sut.contains(someResource))
|
||||
assertThat(sut.contains(someResource)).isFalse()
|
||||
|
||||
sut.edit(commit = true) { putDouble("test", 1.0) }
|
||||
Assertions.assertEquals(1.0, sut.getDouble("test", 2.0))
|
||||
assertThat(sut.getDouble("test", 2.0)).isEqualTo(1.0)
|
||||
sut.edit { putDouble(someResource, 1.0) }
|
||||
Assertions.assertEquals(1.0, sut.getDouble(someResource, 2.0))
|
||||
assertThat(sut.getDouble(someResource, 2.0)).isEqualTo(1.0)
|
||||
sut.edit { clear() }
|
||||
Assertions.assertFalse(sut.contains(someResource2))
|
||||
assertThat(sut.contains(someResource2)).isFalse()
|
||||
|
||||
sut.edit { putInt("test", 1) }
|
||||
Assertions.assertEquals(1, sut.getInt("test", 2))
|
||||
assertThat(sut.getInt("test", 2)).isEqualTo(1)
|
||||
sut.edit { putInt(someResource, 1) }
|
||||
Assertions.assertEquals(1, sut.getInt(someResource, 2))
|
||||
assertThat(sut.getInt(someResource, 2)).isEqualTo(1)
|
||||
sut.edit { clear() }
|
||||
|
||||
sut.edit { putLong("test", 1L) }
|
||||
Assertions.assertEquals(1L, sut.getLong("test", 2L))
|
||||
assertThat(sut.getLong("test", 2L)).isEqualTo(1L)
|
||||
sut.edit { putLong(someResource, 1) }
|
||||
Assertions.assertEquals(1L, sut.getLong(someResource, 2L))
|
||||
assertThat(sut.getLong(someResource, 2L)).isEqualTo(1L)
|
||||
sut.edit { clear() }
|
||||
|
||||
sut.edit { putString("test", "string") }
|
||||
Assertions.assertEquals("string", sut.getString("test", "a"))
|
||||
assertThat(sut.getString("test", "a")).isEqualTo("string")
|
||||
sut.edit { putString(someResource, "string") }
|
||||
Assertions.assertEquals("string", sut.getString(someResource, "a"))
|
||||
assertThat(sut.getString(someResource, "a")).isEqualTo("string")
|
||||
sut.edit { clear() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clear() {
|
||||
sut.putBoolean("test", true)
|
||||
Assertions.assertTrue(sut.getAll().containsKey("test"))
|
||||
assertThat(sut.getAll()).containsKey("test")
|
||||
sut.clear()
|
||||
Assertions.assertFalse(sut.getAll().containsKey("test"))
|
||||
assertThat(sut.getAll()).doesNotContainKey("test")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun contains() {
|
||||
sut.putBoolean("test", true)
|
||||
Assertions.assertTrue(sut.contains("test"))
|
||||
assertThat(sut.contains("test")).isTrue()
|
||||
sut.putBoolean(someResource, true)
|
||||
Assertions.assertTrue(sut.contains(someResource))
|
||||
assertThat(sut.contains(someResource)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun remove() {
|
||||
sut.putBoolean("test", true)
|
||||
sut.remove("test")
|
||||
Assertions.assertFalse(sut.contains("test"))
|
||||
assertThat(sut.contains("test")).isFalse()
|
||||
sut.putBoolean(someResource, true)
|
||||
sut.remove(someResource)
|
||||
Assertions.assertFalse(sut.contains(someResource))
|
||||
assertThat(sut.contains(someResource)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getString() {
|
||||
sut.putString("test", "string")
|
||||
Assertions.assertTrue(sut.getString("test", "") == "string")
|
||||
Assertions.assertTrue(sut.getString("test1", "") == "")
|
||||
assertThat(sut.getString("test", "")).isEqualTo("string")
|
||||
assertThat(sut.getString("test1", "")).isEmpty()
|
||||
sut.putString(someResource, "string")
|
||||
Assertions.assertTrue(sut.getString(someResource, "") == "string")
|
||||
Assertions.assertTrue(sut.getString(someResource2, "") == "")
|
||||
assertThat(sut.getString(someResource, "")).isEqualTo("string")
|
||||
assertThat(sut.getString(someResource2, "")).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getStringOrNull() {
|
||||
sut.putString("test", "string")
|
||||
Assertions.assertTrue(sut.getStringOrNull("test", "") == "string")
|
||||
Assertions.assertNull(sut.getStringOrNull("test1", null))
|
||||
assertThat(sut.getStringOrNull("test", "")).isEqualTo("string")
|
||||
assertThat(sut.getStringOrNull("test1", null)).isNull()
|
||||
sut.putString(someResource, "string")
|
||||
Assertions.assertTrue(sut.getStringOrNull(someResource, null) == "string")
|
||||
Assertions.assertNull(sut.getStringOrNull(someResource2, null))
|
||||
assertThat(sut.getStringOrNull(someResource, null)).isEqualTo("string")
|
||||
assertThat(sut.getStringOrNull(someResource2, null)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getBoolean() {
|
||||
sut.putBoolean("test", true)
|
||||
Assertions.assertTrue(sut.getBoolean("test", false))
|
||||
assertThat(sut.getBoolean("test", false)).isTrue()
|
||||
sut.putBoolean(someResource, true)
|
||||
Assertions.assertTrue(sut.getBoolean(someResource, false))
|
||||
assertThat(sut.getBoolean(someResource, false)).isTrue()
|
||||
sut.putString("string_key", "a")
|
||||
Assertions.assertTrue(sut.getBoolean("string_key", true))
|
||||
assertThat(sut.getBoolean("string_key", true)).isTrue()
|
||||
sut.putString(someResource, "a")
|
||||
Assertions.assertTrue(sut.getBoolean(someResource, true))
|
||||
assertThat(sut.getBoolean(someResource, true)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getDouble() {
|
||||
sut.putDouble("test", 1.0)
|
||||
Assertions.assertEquals(1.0, sut.getDouble("test", 2.0))
|
||||
Assertions.assertEquals(2.0, sut.getDouble("test1", 2.0))
|
||||
assertThat(sut.getDouble("test", 2.0)).isEqualTo(1.0)
|
||||
assertThat(sut.getDouble("test1", 2.0)).isEqualTo(2.0)
|
||||
sut.putDouble(someResource, 1.0)
|
||||
Assertions.assertEquals(1.0, sut.getDouble(someResource, 2.0))
|
||||
Assertions.assertEquals(2.0, sut.getDouble(someResource2, 2.0))
|
||||
assertThat(sut.getDouble(someResource, 2.0)).isEqualTo(1.0)
|
||||
assertThat(sut.getDouble(someResource2, 2.0)).isEqualTo(2.0)
|
||||
sut.putString("string_key", "a")
|
||||
Assertions.assertEquals(1.0, sut.getDouble("string_key", 1.0))
|
||||
assertThat(sut.getDouble("string_key", 1.0)).isEqualTo(1.0)
|
||||
sut.putString(someResource, "a")
|
||||
Assertions.assertEquals(1.0, sut.getDouble(someResource, 1.0))
|
||||
assertThat(sut.getDouble(someResource, 1.0)).isEqualTo(1.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getInt() {
|
||||
sut.putInt("test", 1)
|
||||
Assertions.assertEquals(1, sut.getInt("test", 2))
|
||||
Assertions.assertEquals(2, sut.getInt("test1", 2))
|
||||
assertThat(sut.getInt("test", 2)).isEqualTo(1)
|
||||
assertThat(sut.getInt("test1", 2)).isEqualTo(2)
|
||||
sut.putInt(someResource, 1)
|
||||
Assertions.assertEquals(1, sut.getInt(someResource, 2))
|
||||
Assertions.assertEquals(2, sut.getInt(someResource2, 2))
|
||||
assertThat(sut.getInt(someResource, 2)).isEqualTo(1)
|
||||
assertThat(sut.getInt(someResource2, 2)).isEqualTo(2)
|
||||
sut.putString("string_key", "a")
|
||||
Assertions.assertEquals(1, sut.getInt("string_key", 1))
|
||||
assertThat(sut.getInt("string_key", 1)).isEqualTo(1)
|
||||
sut.putString(someResource, "a")
|
||||
Assertions.assertEquals(1, sut.getInt(someResource, 1))
|
||||
assertThat(sut.getInt(someResource, 1)).isEqualTo(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getLong() {
|
||||
sut.putLong("test", 1L)
|
||||
Assertions.assertEquals(1L, sut.getLong("test", 2L))
|
||||
Assertions.assertEquals(2L, sut.getLong("test1", 2L))
|
||||
assertThat(sut.getLong("test", 2L)).isEqualTo(1L)
|
||||
assertThat(sut.getLong("test1", 2L)).isEqualTo(2L)
|
||||
sut.putLong(someResource, 1L)
|
||||
Assertions.assertEquals(1L, sut.getLong(someResource, 2L))
|
||||
Assertions.assertEquals(2L, sut.getLong(someResource2, 2L))
|
||||
assertThat(sut.getLong(someResource, 2L)).isEqualTo(1L)
|
||||
assertThat(sut.getLong(someResource2, 2L)).isEqualTo(2L)
|
||||
sut.putString("string_key", "a")
|
||||
Assertions.assertEquals(1L, sut.getLong("string_key", 1L))
|
||||
assertThat(sut.getLong("string_key", 1L)).isEqualTo(1L)
|
||||
sut.putString(someResource, "a")
|
||||
Assertions.assertEquals(1L, sut.getLong(someResource, 1L))
|
||||
assertThat(sut.getLong(someResource, 1L)).isEqualTo(1L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun incLong() {
|
||||
sut.incLong(someResource)
|
||||
Assertions.assertEquals(1L, sut.getLong(someResource, 3L))
|
||||
assertThat(sut.getLong(someResource, 3L)).isEqualTo(1L)
|
||||
sut.incLong(someResource)
|
||||
Assertions.assertEquals(2L, sut.getLong(someResource, 3L))
|
||||
assertThat(sut.getLong(someResource, 3L)).isEqualTo(2L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun incInt() {
|
||||
sut.incInt(someResource)
|
||||
Assertions.assertEquals(1, sut.getInt(someResource, 3))
|
||||
assertThat(sut.getInt(someResource, 3)).isEqualTo(1)
|
||||
sut.incInt(someResource)
|
||||
Assertions.assertEquals(2, sut.getInt(someResource, 3))
|
||||
assertThat(sut.getInt(someResource, 3)).isEqualTo(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package info.nightscout.rx.weardata
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
@ -21,132 +21,132 @@ class EventDataTest {
|
|||
@Test
|
||||
fun serializationTest() {
|
||||
EventData.ActionPong(1, 2).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.WearException(1, byteArrayOf(0xAA.toByte()), "board", "fingerprint", "sdk", "model", "manufacturer", "product").let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.Error(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.CancelBolus(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionResendData("data").let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionPumpStatus(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionLoopStatus(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionTddStatus(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionECarbsPreCheck(1, 2, 3).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionBolusPreCheck(1.0, 2).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionFillPreCheck(1.0).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionFillPresetPreCheck(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionProfileSwitchSendInitialData(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionProfileSwitchPreCheck(1, 2).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionWizardPreCheck(1, 2).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionQuickWizardPreCheck("guid").let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionHeartRate(1, 2, 3.0, "device").let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.CANCEL).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionWizardConfirmed(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionTempTargetConfirmed(false).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionBolusConfirmed(1.0, 2).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionECarbsConfirmed(1, 2, 3).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionFillConfirmed(1.0).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionProfileSwitchConfirmed(1, 2).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.OpenLoopRequestConfirmed(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.CancelNotification(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
// EventData.ActionGetCustomWatchface(EventData.ActionSetCustomWatchface(CwfData())).let {
|
||||
// Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
// Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
// assertThat( EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
// assertThat( EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
// }
|
||||
EventData.ActionPing(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.OpenSettings(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.BolusProgress(1, "status").let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.GraphData(arrayListOf(EventData.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0))).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.TreatmentData(
|
||||
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.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0))
|
||||
).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.Preferences(1, wearControl = true, true, 2, 3, 4.0, 5.0, 6.0, 7, 8).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.QuickWizard(arrayListOf(EventData.QuickWizard.QuickWizardEntry("1", "2", 3, 4, 5))).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
// EventData.ActionSetCustomWatchface().let {
|
||||
// Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
// Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
// assertThat( EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
// assertThat( EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
// }
|
||||
EventData.ActionrequestCustomWatchface(true).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionrequestSetDefaultWatchface(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ActionProfileSwitchOpenActivity(1, 2).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.OpenLoopRequest("1", "2", null).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.ConfirmAction("1", "2", null).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
EventData.SnoozeAlert(1).let {
|
||||
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
|
||||
Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
|
||||
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
|
||||
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package info.nightscout.shared
|
||||
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
|
@ -8,105 +8,105 @@ class SafeParseTest {
|
|||
|
||||
@Test fun stringToDoubleTest() {
|
||||
// correct values
|
||||
Assertions.assertEquals(0.1234, SafeParse.stringToDouble("0.1234"), 0.001)
|
||||
Assertions.assertEquals(0.1234, SafeParse.stringToDouble("0,1234"), 0.001)
|
||||
Assertions.assertEquals(0.5436564812, SafeParse.stringToDouble(".5436564812"), 0.001)
|
||||
Assertions.assertEquals(0.5436564812, SafeParse.stringToDouble(",5436564812"), 0.001)
|
||||
Assertions.assertEquals(1000500100900.0, SafeParse.stringToDouble("1000500100900"), 0.001)
|
||||
Assertions.assertEquals(42.0, SafeParse.stringToDouble("42"), 0.001)
|
||||
assertThat(SafeParse.stringToDouble("0.1234")).isWithin(0.001).of(0.1234)
|
||||
assertThat(SafeParse.stringToDouble("0,1234")).isWithin(0.001).of(0.1234)
|
||||
assertThat(SafeParse.stringToDouble(".5436564812")).isWithin(0.001).of(0.5436564812)
|
||||
assertThat(SafeParse.stringToDouble(",5436564812")).isWithin(0.001).of(0.5436564812)
|
||||
assertThat(SafeParse.stringToDouble("1000500100900")).isWithin(0.001).of(1000500100900.0)
|
||||
assertThat(SafeParse.stringToDouble("42")).isWithin(0.001).of(42.0)
|
||||
|
||||
// units or other extra values are not permitted
|
||||
Assertions.assertEquals(0.0, SafeParse.stringToDouble("12 U/h"), 0.001)
|
||||
assertThat(SafeParse.stringToDouble("12 U/h")).isWithin(0.001).of(0.0)
|
||||
|
||||
// strings are not parsable
|
||||
Assertions.assertEquals(0.0, SafeParse.stringToDouble("ala ma kota"), 0.001)
|
||||
assertThat(SafeParse.stringToDouble("ala ma kota")).isWithin(0.001).of(0.0)
|
||||
|
||||
// separator errors
|
||||
Assertions.assertEquals(0.0, SafeParse.stringToDouble("0.1234.5678"), 0.001)
|
||||
Assertions.assertEquals(0.0, SafeParse.stringToDouble("0,1234,5678"), 0.001)
|
||||
assertThat(SafeParse.stringToDouble("0.1234.5678")).isWithin(0.001).of(0.0)
|
||||
assertThat(SafeParse.stringToDouble("0,1234,5678")).isWithin(0.001).of(0.0)
|
||||
|
||||
// various emptiness
|
||||
Assertions.assertEquals(0.0, SafeParse.stringToDouble(""), 0.001)
|
||||
Assertions.assertEquals(0.0, SafeParse.stringToDouble(" "), 0.001)
|
||||
Assertions.assertEquals(0.0, SafeParse.stringToDouble("\n\r"), 0.001)
|
||||
assertThat(SafeParse.stringToDouble("")).isWithin(0.001).of(0.0)
|
||||
assertThat(SafeParse.stringToDouble(" ")).isWithin(0.001).of(0.0)
|
||||
assertThat(SafeParse.stringToDouble("\n\r")).isWithin(0.001).of(0.0)
|
||||
}
|
||||
|
||||
@Test fun stringToIntTest() {
|
||||
// correct values
|
||||
Assertions.assertEquals(1052934, SafeParse.stringToInt("1052934"))
|
||||
Assertions.assertEquals(-42, SafeParse.stringToInt("-42"))
|
||||
Assertions.assertEquals(2147483647, SafeParse.stringToInt("2147483647"))
|
||||
Assertions.assertEquals(-2147483648, SafeParse.stringToInt("-2147483648"))
|
||||
assertThat(SafeParse.stringToInt("1052934")).isEqualTo(1052934)
|
||||
assertThat(SafeParse.stringToInt("-42")).isEqualTo(-42)
|
||||
assertThat(SafeParse.stringToInt("2147483647")).isEqualTo(2147483647)
|
||||
assertThat(SafeParse.stringToInt("-2147483648")).isEqualTo(-2147483648)
|
||||
|
||||
// outside Integer range
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("2147483648"))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("-2147483649"))
|
||||
assertThat(SafeParse.stringToInt("2147483648")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt("-2147483649")).isEqualTo(0)
|
||||
|
||||
// units or other extra values are not permitted
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("12 U/h"))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("0.1234"))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("0,1234"))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt(".5436564812"))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt(",5436564812"))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("42.1234"))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("42,1234"))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("3212.5436564812"))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("3212,5436564812"))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("1000500100900"))
|
||||
assertThat(SafeParse.stringToInt("12 U/h")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt("0.1234")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt("0,1234")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt(".5436564812")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt(",5436564812")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt("42.1234")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt("42,1234")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt("3212.5436564812")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt("3212,5436564812")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt("1000500100900")).isEqualTo(0)
|
||||
|
||||
// strings are not parsable
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("ala ma kota"))
|
||||
assertThat(SafeParse.stringToInt("ala ma kota")).isEqualTo(0)
|
||||
|
||||
// various emptiness
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt(""))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt(" "))
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt("\n\r"))
|
||||
assertThat(SafeParse.stringToInt("")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt(" ")).isEqualTo(0)
|
||||
assertThat(SafeParse.stringToInt("\n\r")).isEqualTo(0)
|
||||
}
|
||||
|
||||
@Test fun stringToLongTest() {
|
||||
// correct values
|
||||
Assertions.assertEquals(1052934L, SafeParse.stringToLong("1052934"))
|
||||
Assertions.assertEquals(-42L, SafeParse.stringToLong("-42"))
|
||||
Assertions.assertEquals(2147483647L, SafeParse.stringToLong("2147483647"))
|
||||
Assertions.assertEquals(-2147483648L, SafeParse.stringToLong("-2147483648"))
|
||||
Assertions.assertEquals(1000500100900L, SafeParse.stringToLong("1000500100900"))
|
||||
assertThat(SafeParse.stringToLong("1052934")).isEqualTo(1052934L)
|
||||
assertThat(SafeParse.stringToLong("-42")).isEqualTo(-42L)
|
||||
assertThat(SafeParse.stringToLong("2147483647")).isEqualTo(2147483647L)
|
||||
assertThat(SafeParse.stringToLong("-2147483648")).isEqualTo(-2147483648L)
|
||||
assertThat(SafeParse.stringToLong("1000500100900")).isEqualTo(1000500100900L)
|
||||
|
||||
// outside Integer range
|
||||
Assertions.assertEquals(2147483648L, SafeParse.stringToLong("2147483648"))
|
||||
Assertions.assertEquals(-2147483649L, SafeParse.stringToLong("-2147483649"))
|
||||
assertThat(SafeParse.stringToLong("2147483648")).isEqualTo(2147483648L)
|
||||
assertThat(SafeParse.stringToLong("-2147483649")).isEqualTo(-2147483649L)
|
||||
|
||||
// units or other extra values are not permitted
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong("12 U/h"))
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong("0.1234"))
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong("0,1234"))
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong(".5436564812"))
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong(",5436564812"))
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong("42.1234"))
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong("42,1234"))
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong("3212.5436564812"))
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong("3212,5436564812"))
|
||||
assertThat(SafeParse.stringToLong("12 U/h")).isEqualTo(0L)
|
||||
assertThat(SafeParse.stringToLong("0.1234")).isEqualTo(0L)
|
||||
assertThat(SafeParse.stringToLong("0,1234")).isEqualTo(0L)
|
||||
assertThat(SafeParse.stringToLong(".5436564812")).isEqualTo(0L)
|
||||
assertThat(SafeParse.stringToLong(",5436564812")).isEqualTo(0L)
|
||||
assertThat(SafeParse.stringToLong("42.1234")).isEqualTo(0L)
|
||||
assertThat(SafeParse.stringToLong("42,1234")).isEqualTo(0L)
|
||||
assertThat(SafeParse.stringToLong("3212.5436564812")).isEqualTo(0L)
|
||||
assertThat(SafeParse.stringToLong("3212,5436564812")).isEqualTo(0L)
|
||||
|
||||
// strings are not parsable
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong("ala ma kota"))
|
||||
assertThat(SafeParse.stringToLong("ala ma kota")).isEqualTo(0L)
|
||||
|
||||
// various emptiness
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong(""))
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong(" "))
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong("\n\r"))
|
||||
assertThat(SafeParse.stringToLong("")).isEqualTo(0L)
|
||||
assertThat(SafeParse.stringToLong(" ")).isEqualTo(0L)
|
||||
assertThat(SafeParse.stringToLong("\n\r")).isEqualTo(0L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun stringToDoubleNullTest() {
|
||||
Assertions.assertEquals(0.0, SafeParse.stringToDouble(null), 0.001)
|
||||
assertThat(SafeParse.stringToDouble(null)).isWithin(0.001).of(0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun stringToIntNullTest() {
|
||||
Assertions.assertEquals(0, SafeParse.stringToInt(null))
|
||||
assertThat(SafeParse.stringToInt(null)).isEqualTo(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun stringToLongNullTest() {
|
||||
Assertions.assertEquals(0L, SafeParse.stringToLong(null))
|
||||
assertThat(SafeParse.stringToLong(null)).isEqualTo(0L)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue