Merge remote-tracking branch 'origin/dev' into refactor

This commit is contained in:
Milos Kozak 2023-09-19 14:45:50 +02:00
commit be78449e33
5 changed files with 206 additions and 206 deletions

View file

@ -1,8 +1,8 @@
package info.nightscout.shared.impl.logging package info.nightscout.shared.impl.logging
import com.google.common.truth.Truth.assertThat
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
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
@ -26,13 +26,13 @@ class LImplTest {
@Test @Test
fun findByName() { fun findByName() {
Assertions.assertEquals(LTag.APS.name, sut.findByName("APS").name) assertThat(sut.findByName("APS").name).isEqualTo(LTag.APS.name)
Assertions.assertEquals("NONEXISTENT", sut.findByName("APS2").name) assertThat(sut.findByName("APS2").name).isEqualTo("NONEXISTENT")
} }
@Test @Test
fun getLogElements() { fun getLogElements() {
Assertions.assertTrue(sut.getLogElements().isNotEmpty()) assertThat(sut.getLogElements()).isNotEmpty()
} }
@Test @Test
@ -40,6 +40,6 @@ class LImplTest {
val element = sut.findByName("APS") val element = sut.findByName("APS")
element.enabled = false element.enabled = false
sut.resetToDefaults() sut.resetToDefaults()
Assertions.assertTrue(element.enabled) assertThat(element.enabled).isTrue()
} }
} }

View file

@ -1,8 +1,8 @@
package info.nightscout.shared.impl.sharedPreferences package info.nightscout.shared.impl.sharedPreferences
import com.google.common.truth.Truth.assertThat
import android.content.Context import android.content.Context
import info.nightscout.shared.impl.SharedPreferencesMock import info.nightscout.shared.impl.SharedPreferencesMock
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
@ -34,153 +34,153 @@ class SPImplementationTest {
@Test @Test
fun edit() { fun edit() {
sut.edit { putBoolean("test", true) } sut.edit { putBoolean("test", true) }
Assertions.assertTrue(sut.getBoolean("test", false)) assertThat(sut.getBoolean("test", false)).isTrue()
sut.edit { remove("test") } sut.edit { remove("test") }
Assertions.assertFalse(sut.contains("test")) assertThat(sut.contains("test")).isFalse()
sut.edit { putBoolean(someResource, true) } sut.edit { putBoolean(someResource, true) }
Assertions.assertTrue(sut.getBoolean(someResource, false)) assertThat(sut.getBoolean(someResource, false)).isTrue()
sut.edit { remove(someResource) } sut.edit { remove(someResource) }
Assertions.assertFalse(sut.contains(someResource)) assertThat(sut.contains(someResource)).isFalse()
sut.edit(commit = true) { putDouble("test", 1.0) } 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) } 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() } sut.edit { clear() }
Assertions.assertFalse(sut.contains(someResource2)) assertThat(sut.contains(someResource2)).isFalse()
sut.edit { putInt("test", 1) } sut.edit { putInt("test", 1) }
Assertions.assertEquals(1, sut.getInt("test", 2)) assertThat(sut.getInt("test", 2)).isEqualTo(1)
sut.edit { putInt(someResource, 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 { clear() }
sut.edit { putLong("test", 1L) } sut.edit { putLong("test", 1L) }
Assertions.assertEquals(1L, sut.getLong("test", 2L)) assertThat(sut.getLong("test", 2L)).isEqualTo(1L)
sut.edit { putLong(someResource, 1) } sut.edit { putLong(someResource, 1) }
Assertions.assertEquals(1L, sut.getLong(someResource, 2L)) assertThat(sut.getLong(someResource, 2L)).isEqualTo(1L)
sut.edit { clear() } sut.edit { clear() }
sut.edit { putString("test", "string") } sut.edit { putString("test", "string") }
Assertions.assertEquals("string", sut.getString("test", "a")) assertThat(sut.getString("test", "a")).isEqualTo("string")
sut.edit { putString(someResource, "string") } sut.edit { putString(someResource, "string") }
Assertions.assertEquals("string", sut.getString(someResource, "a")) assertThat(sut.getString(someResource, "a")).isEqualTo("string")
sut.edit { clear() } sut.edit { clear() }
} }
@Test @Test
fun clear() { fun clear() {
sut.putBoolean("test", true) sut.putBoolean("test", true)
Assertions.assertTrue(sut.getAll().containsKey("test")) assertThat(sut.getAll()).containsKey("test")
sut.clear() sut.clear()
Assertions.assertFalse(sut.getAll().containsKey("test")) assertThat(sut.getAll()).doesNotContainKey("test")
} }
@Test @Test
fun contains() { fun contains() {
sut.putBoolean("test", true) sut.putBoolean("test", true)
Assertions.assertTrue(sut.contains("test")) assertThat(sut.contains("test")).isTrue()
sut.putBoolean(someResource, true) sut.putBoolean(someResource, true)
Assertions.assertTrue(sut.contains(someResource)) assertThat(sut.contains(someResource)).isTrue()
} }
@Test @Test
fun remove() { fun remove() {
sut.putBoolean("test", true) sut.putBoolean("test", true)
sut.remove("test") sut.remove("test")
Assertions.assertFalse(sut.contains("test")) assertThat(sut.contains("test")).isFalse()
sut.putBoolean(someResource, true) sut.putBoolean(someResource, true)
sut.remove(someResource) sut.remove(someResource)
Assertions.assertFalse(sut.contains(someResource)) assertThat(sut.contains(someResource)).isFalse()
} }
@Test @Test
fun getString() { fun getString() {
sut.putString("test", "string") sut.putString("test", "string")
Assertions.assertTrue(sut.getString("test", "") == "string") assertThat(sut.getString("test", "")).isEqualTo("string")
Assertions.assertTrue(sut.getString("test1", "") == "") assertThat(sut.getString("test1", "")).isEmpty()
sut.putString(someResource, "string") sut.putString(someResource, "string")
Assertions.assertTrue(sut.getString(someResource, "") == "string") assertThat(sut.getString(someResource, "")).isEqualTo("string")
Assertions.assertTrue(sut.getString(someResource2, "") == "") assertThat(sut.getString(someResource2, "")).isEmpty()
} }
@Test @Test
fun getStringOrNull() { fun getStringOrNull() {
sut.putString("test", "string") sut.putString("test", "string")
Assertions.assertTrue(sut.getStringOrNull("test", "") == "string") assertThat(sut.getStringOrNull("test", "")).isEqualTo("string")
Assertions.assertNull(sut.getStringOrNull("test1", null)) assertThat(sut.getStringOrNull("test1", null)).isNull()
sut.putString(someResource, "string") sut.putString(someResource, "string")
Assertions.assertTrue(sut.getStringOrNull(someResource, null) == "string") assertThat(sut.getStringOrNull(someResource, null)).isEqualTo("string")
Assertions.assertNull(sut.getStringOrNull(someResource2, null)) assertThat(sut.getStringOrNull(someResource2, null)).isNull()
} }
@Test @Test
fun getBoolean() { fun getBoolean() {
sut.putBoolean("test", true) sut.putBoolean("test", true)
Assertions.assertTrue(sut.getBoolean("test", false)) assertThat(sut.getBoolean("test", false)).isTrue()
sut.putBoolean(someResource, true) sut.putBoolean(someResource, true)
Assertions.assertTrue(sut.getBoolean(someResource, false)) assertThat(sut.getBoolean(someResource, false)).isTrue()
sut.putString("string_key", "a") sut.putString("string_key", "a")
Assertions.assertTrue(sut.getBoolean("string_key", true)) assertThat(sut.getBoolean("string_key", true)).isTrue()
sut.putString(someResource, "a") sut.putString(someResource, "a")
Assertions.assertTrue(sut.getBoolean(someResource, true)) assertThat(sut.getBoolean(someResource, true)).isTrue()
} }
@Test @Test
fun getDouble() { fun getDouble() {
sut.putDouble("test", 1.0) sut.putDouble("test", 1.0)
Assertions.assertEquals(1.0, sut.getDouble("test", 2.0)) assertThat(sut.getDouble("test", 2.0)).isEqualTo(1.0)
Assertions.assertEquals(2.0, sut.getDouble("test1", 2.0)) assertThat(sut.getDouble("test1", 2.0)).isEqualTo(2.0)
sut.putDouble(someResource, 1.0) sut.putDouble(someResource, 1.0)
Assertions.assertEquals(1.0, sut.getDouble(someResource, 2.0)) assertThat(sut.getDouble(someResource, 2.0)).isEqualTo(1.0)
Assertions.assertEquals(2.0, sut.getDouble(someResource2, 2.0)) assertThat(sut.getDouble(someResource2, 2.0)).isEqualTo(2.0)
sut.putString("string_key", "a") 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") sut.putString(someResource, "a")
Assertions.assertEquals(1.0, sut.getDouble(someResource, 1.0)) assertThat(sut.getDouble(someResource, 1.0)).isEqualTo(1.0)
} }
@Test @Test
fun getInt() { fun getInt() {
sut.putInt("test", 1) sut.putInt("test", 1)
Assertions.assertEquals(1, sut.getInt("test", 2)) assertThat(sut.getInt("test", 2)).isEqualTo(1)
Assertions.assertEquals(2, sut.getInt("test1", 2)) assertThat(sut.getInt("test1", 2)).isEqualTo(2)
sut.putInt(someResource, 1) sut.putInt(someResource, 1)
Assertions.assertEquals(1, sut.getInt(someResource, 2)) assertThat(sut.getInt(someResource, 2)).isEqualTo(1)
Assertions.assertEquals(2, sut.getInt(someResource2, 2)) assertThat(sut.getInt(someResource2, 2)).isEqualTo(2)
sut.putString("string_key", "a") 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") sut.putString(someResource, "a")
Assertions.assertEquals(1, sut.getInt(someResource, 1)) assertThat(sut.getInt(someResource, 1)).isEqualTo(1)
} }
@Test @Test
fun getLong() { fun getLong() {
sut.putLong("test", 1L) sut.putLong("test", 1L)
Assertions.assertEquals(1L, sut.getLong("test", 2L)) assertThat(sut.getLong("test", 2L)).isEqualTo(1L)
Assertions.assertEquals(2L, sut.getLong("test1", 2L)) assertThat(sut.getLong("test1", 2L)).isEqualTo(2L)
sut.putLong(someResource, 1L) sut.putLong(someResource, 1L)
Assertions.assertEquals(1L, sut.getLong(someResource, 2L)) assertThat(sut.getLong(someResource, 2L)).isEqualTo(1L)
Assertions.assertEquals(2L, sut.getLong(someResource2, 2L)) assertThat(sut.getLong(someResource2, 2L)).isEqualTo(2L)
sut.putString("string_key", "a") 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") sut.putString(someResource, "a")
Assertions.assertEquals(1L, sut.getLong(someResource, 1L)) assertThat(sut.getLong(someResource, 1L)).isEqualTo(1L)
} }
@Test @Test
fun incLong() { fun incLong() {
sut.incLong(someResource) sut.incLong(someResource)
Assertions.assertEquals(1L, sut.getLong(someResource, 3L)) assertThat(sut.getLong(someResource, 3L)).isEqualTo(1L)
sut.incLong(someResource) sut.incLong(someResource)
Assertions.assertEquals(2L, sut.getLong(someResource, 3L)) assertThat(sut.getLong(someResource, 3L)).isEqualTo(2L)
} }
@Test @Test
fun incInt() { fun incInt() {
sut.incInt(someResource) sut.incInt(someResource)
Assertions.assertEquals(1, sut.getInt(someResource, 3)) assertThat(sut.getInt(someResource, 3)).isEqualTo(1)
sut.incInt(someResource) sut.incInt(someResource)
Assertions.assertEquals(2, sut.getInt(someResource, 3)) assertThat(sut.getInt(someResource, 3)).isEqualTo(2)
} }
} }

View file

@ -79,7 +79,7 @@ buildscript {
plugins { plugins {
// Test Gradle build, keep disabled under normal circumstances // Test Gradle build, keep disabled under normal circumstances
// id "com.osacky.doctor" version "0.8.1" // id "com.osacky.doctor" version "0.8.1"
id "org.jlleitschuh.gradle.ktlint" version "11.5.1" id "org.jlleitschuh.gradle.ktlint" version "11.6.0"
// Aggregates and/or logs Jacoco test coverage to the Gradle build log // Aggregates and/or logs Jacoco test coverage to the Gradle build log
//id 'org.barfuin.gradle.jacocolog' version '3.1.0' //id 'org.barfuin.gradle.jacocolog' version '3.1.0'
id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false

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

View file

@ -1,6 +1,6 @@
package info.nightscout.shared package info.nightscout.shared
import org.junit.jupiter.api.Assertions import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ -8,105 +8,105 @@ class SafeParseTest {
@Test fun stringToDoubleTest() { @Test fun stringToDoubleTest() {
// correct values // correct values
Assertions.assertEquals(0.1234, SafeParse.stringToDouble("0.1234"), 0.001) assertThat(SafeParse.stringToDouble("0.1234")).isWithin(0.001).of(0.1234)
Assertions.assertEquals(0.1234, SafeParse.stringToDouble("0,1234"), 0.001) assertThat(SafeParse.stringToDouble("0,1234")).isWithin(0.001).of(0.1234)
Assertions.assertEquals(0.5436564812, SafeParse.stringToDouble(".5436564812"), 0.001) assertThat(SafeParse.stringToDouble(".5436564812")).isWithin(0.001).of(0.5436564812)
Assertions.assertEquals(0.5436564812, SafeParse.stringToDouble(",5436564812"), 0.001) assertThat(SafeParse.stringToDouble(",5436564812")).isWithin(0.001).of(0.5436564812)
Assertions.assertEquals(1000500100900.0, SafeParse.stringToDouble("1000500100900"), 0.001) assertThat(SafeParse.stringToDouble("1000500100900")).isWithin(0.001).of(1000500100900.0)
Assertions.assertEquals(42.0, SafeParse.stringToDouble("42"), 0.001) assertThat(SafeParse.stringToDouble("42")).isWithin(0.001).of(42.0)
// units or other extra values are not permitted // 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 // 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 // separator errors
Assertions.assertEquals(0.0, SafeParse.stringToDouble("0.1234.5678"), 0.001) assertThat(SafeParse.stringToDouble("0.1234.5678")).isWithin(0.001).of(0.0)
Assertions.assertEquals(0.0, SafeParse.stringToDouble("0,1234,5678"), 0.001) assertThat(SafeParse.stringToDouble("0,1234,5678")).isWithin(0.001).of(0.0)
// various emptiness // various emptiness
Assertions.assertEquals(0.0, SafeParse.stringToDouble(""), 0.001) assertThat(SafeParse.stringToDouble("")).isWithin(0.001).of(0.0)
Assertions.assertEquals(0.0, SafeParse.stringToDouble(" "), 0.001) assertThat(SafeParse.stringToDouble(" ")).isWithin(0.001).of(0.0)
Assertions.assertEquals(0.0, SafeParse.stringToDouble("\n\r"), 0.001) assertThat(SafeParse.stringToDouble("\n\r")).isWithin(0.001).of(0.0)
} }
@Test fun stringToIntTest() { @Test fun stringToIntTest() {
// correct values // correct values
Assertions.assertEquals(1052934, SafeParse.stringToInt("1052934")) assertThat(SafeParse.stringToInt("1052934")).isEqualTo(1052934)
Assertions.assertEquals(-42, SafeParse.stringToInt("-42")) assertThat(SafeParse.stringToInt("-42")).isEqualTo(-42)
Assertions.assertEquals(2147483647, SafeParse.stringToInt("2147483647")) assertThat(SafeParse.stringToInt("2147483647")).isEqualTo(2147483647)
Assertions.assertEquals(-2147483648, SafeParse.stringToInt("-2147483648")) assertThat(SafeParse.stringToInt("-2147483648")).isEqualTo(-2147483648)
// outside Integer range // outside Integer range
Assertions.assertEquals(0, SafeParse.stringToInt("2147483648")) assertThat(SafeParse.stringToInt("2147483648")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt("-2147483649")) assertThat(SafeParse.stringToInt("-2147483649")).isEqualTo(0)
// units or other extra values are not permitted // units or other extra values are not permitted
Assertions.assertEquals(0, SafeParse.stringToInt("12 U/h")) assertThat(SafeParse.stringToInt("12 U/h")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt("0.1234")) assertThat(SafeParse.stringToInt("0.1234")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt("0,1234")) assertThat(SafeParse.stringToInt("0,1234")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt(".5436564812")) assertThat(SafeParse.stringToInt(".5436564812")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt(",5436564812")) assertThat(SafeParse.stringToInt(",5436564812")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt("42.1234")) assertThat(SafeParse.stringToInt("42.1234")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt("42,1234")) assertThat(SafeParse.stringToInt("42,1234")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt("3212.5436564812")) assertThat(SafeParse.stringToInt("3212.5436564812")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt("3212,5436564812")) assertThat(SafeParse.stringToInt("3212,5436564812")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt("1000500100900")) assertThat(SafeParse.stringToInt("1000500100900")).isEqualTo(0)
// strings are not parsable // strings are not parsable
Assertions.assertEquals(0, SafeParse.stringToInt("ala ma kota")) assertThat(SafeParse.stringToInt("ala ma kota")).isEqualTo(0)
// various emptiness // various emptiness
Assertions.assertEquals(0, SafeParse.stringToInt("")) assertThat(SafeParse.stringToInt("")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt(" ")) assertThat(SafeParse.stringToInt(" ")).isEqualTo(0)
Assertions.assertEquals(0, SafeParse.stringToInt("\n\r")) assertThat(SafeParse.stringToInt("\n\r")).isEqualTo(0)
} }
@Test fun stringToLongTest() { @Test fun stringToLongTest() {
// correct values // correct values
Assertions.assertEquals(1052934L, SafeParse.stringToLong("1052934")) assertThat(SafeParse.stringToLong("1052934")).isEqualTo(1052934L)
Assertions.assertEquals(-42L, SafeParse.stringToLong("-42")) assertThat(SafeParse.stringToLong("-42")).isEqualTo(-42L)
Assertions.assertEquals(2147483647L, SafeParse.stringToLong("2147483647")) assertThat(SafeParse.stringToLong("2147483647")).isEqualTo(2147483647L)
Assertions.assertEquals(-2147483648L, SafeParse.stringToLong("-2147483648")) assertThat(SafeParse.stringToLong("-2147483648")).isEqualTo(-2147483648L)
Assertions.assertEquals(1000500100900L, SafeParse.stringToLong("1000500100900")) assertThat(SafeParse.stringToLong("1000500100900")).isEqualTo(1000500100900L)
// outside Integer range // outside Integer range
Assertions.assertEquals(2147483648L, SafeParse.stringToLong("2147483648")) assertThat(SafeParse.stringToLong("2147483648")).isEqualTo(2147483648L)
Assertions.assertEquals(-2147483649L, SafeParse.stringToLong("-2147483649")) assertThat(SafeParse.stringToLong("-2147483649")).isEqualTo(-2147483649L)
// units or other extra values are not permitted // units or other extra values are not permitted
Assertions.assertEquals(0L, SafeParse.stringToLong("12 U/h")) assertThat(SafeParse.stringToLong("12 U/h")).isEqualTo(0L)
Assertions.assertEquals(0L, SafeParse.stringToLong("0.1234")) assertThat(SafeParse.stringToLong("0.1234")).isEqualTo(0L)
Assertions.assertEquals(0L, SafeParse.stringToLong("0,1234")) assertThat(SafeParse.stringToLong("0,1234")).isEqualTo(0L)
Assertions.assertEquals(0L, SafeParse.stringToLong(".5436564812")) assertThat(SafeParse.stringToLong(".5436564812")).isEqualTo(0L)
Assertions.assertEquals(0L, SafeParse.stringToLong(",5436564812")) assertThat(SafeParse.stringToLong(",5436564812")).isEqualTo(0L)
Assertions.assertEquals(0L, SafeParse.stringToLong("42.1234")) assertThat(SafeParse.stringToLong("42.1234")).isEqualTo(0L)
Assertions.assertEquals(0L, SafeParse.stringToLong("42,1234")) assertThat(SafeParse.stringToLong("42,1234")).isEqualTo(0L)
Assertions.assertEquals(0L, SafeParse.stringToLong("3212.5436564812")) assertThat(SafeParse.stringToLong("3212.5436564812")).isEqualTo(0L)
Assertions.assertEquals(0L, SafeParse.stringToLong("3212,5436564812")) assertThat(SafeParse.stringToLong("3212,5436564812")).isEqualTo(0L)
// strings are not parsable // strings are not parsable
Assertions.assertEquals(0L, SafeParse.stringToLong("ala ma kota")) assertThat(SafeParse.stringToLong("ala ma kota")).isEqualTo(0L)
// various emptiness // various emptiness
Assertions.assertEquals(0L, SafeParse.stringToLong("")) assertThat(SafeParse.stringToLong("")).isEqualTo(0L)
Assertions.assertEquals(0L, SafeParse.stringToLong(" ")) assertThat(SafeParse.stringToLong(" ")).isEqualTo(0L)
Assertions.assertEquals(0L, SafeParse.stringToLong("\n\r")) assertThat(SafeParse.stringToLong("\n\r")).isEqualTo(0L)
} }
@Test @Test
fun stringToDoubleNullTest() { fun stringToDoubleNullTest() {
Assertions.assertEquals(0.0, SafeParse.stringToDouble(null), 0.001) assertThat(SafeParse.stringToDouble(null)).isWithin(0.001).of(0.0)
} }
@Test @Test
fun stringToIntNullTest() { fun stringToIntNullTest() {
Assertions.assertEquals(0, SafeParse.stringToInt(null)) assertThat(SafeParse.stringToInt(null)).isEqualTo(0)
} }
@Test @Test
fun stringToLongNullTest() { fun stringToLongNullTest() {
Assertions.assertEquals(0L, SafeParse.stringToLong(null)) assertThat(SafeParse.stringToLong(null)).isEqualTo(0L)
} }
} }