mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-14 18:26:11 -04:00
fix(test): Move FossUpgrade tests to testFoss source set for gplay compat
FossUpgrade is foss-flavor-only, so tests referencing it must live in testFoss/ to avoid compilation failures in testGplayDebugUnitTest.
This commit is contained in:
@@ -9,7 +9,6 @@ import eu.darken.capod.main.core.MonitorMode
|
||||
import eu.darken.capod.pods.core.PodDevice
|
||||
import eu.darken.capod.profiles.core.AppleDeviceProfile
|
||||
import eu.darken.capod.profiles.core.DeviceProfilesContainer
|
||||
import eu.darken.capod.common.upgrade.core.FossUpgrade
|
||||
import eu.darken.capod.reaction.core.autoconnect.AutoConnectCondition
|
||||
import io.kotest.matchers.shouldBe
|
||||
import kotlinx.serialization.SerialName
|
||||
@@ -17,7 +16,6 @@ import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.serializer
|
||||
import org.junit.jupiter.api.Test
|
||||
import testhelpers.BaseTest
|
||||
import java.time.Instant
|
||||
|
||||
/**
|
||||
* Tests that verify @SerialName values match @Json(name=...) values,
|
||||
@@ -70,9 +68,6 @@ class DataStoreMigrationCompatTest : BaseTest() {
|
||||
@Test
|
||||
fun `SerialName matches Json name - PodDevice Model`() = verifyEnumSerialNameParity<PodDevice.Model>()
|
||||
|
||||
@Test
|
||||
fun `SerialName matches Json name - FossUpgrade Reason`() = verifyEnumSerialNameParity<FossUpgrade.Reason>()
|
||||
|
||||
@Test
|
||||
fun `Moshi-serialized ThemeMode string is readable by kotlinx`() {
|
||||
// Moshi stores enums as JSON strings like: "theme.mode.dark"
|
||||
@@ -129,15 +124,6 @@ class DataStoreMigrationCompatTest : BaseTest() {
|
||||
result shouldBe AutoConnectCondition.WHEN_SEEN
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Moshi-serialized FossUpgrade JSON is readable by kotlinx`() {
|
||||
// Moshi with JavaInstantAdapter serializes Instant as epoch millis Long
|
||||
val moshiJson = """{"upgradedAt":1709553600000,"reason":"foss.upgrade.reason.donated"}"""
|
||||
val result = json.decodeFromString(serializer<FossUpgrade>(), moshiJson)
|
||||
result.upgradedAt shouldBe Instant.ofEpochMilli(1709553600000)
|
||||
result.reason shouldBe FossUpgrade.Reason.DONATED
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Moshi-serialized DeviceProfilesContainer JSON is readable by kotlinx`() {
|
||||
// This is what Moshi would produce for a container with one Apple profile
|
||||
|
||||
@@ -7,7 +7,6 @@ import eu.darken.capod.common.serialization.InstantEpochMillisSerializer
|
||||
import eu.darken.capod.common.theming.ThemeColor
|
||||
import eu.darken.capod.common.theming.ThemeMode
|
||||
import eu.darken.capod.common.theming.ThemeStyle
|
||||
import eu.darken.capod.common.upgrade.core.FossUpgrade
|
||||
import eu.darken.capod.main.core.MonitorMode
|
||||
import kotlinx.serialization.builtins.nullable
|
||||
import eu.darken.capod.pods.core.PodDevice
|
||||
@@ -206,24 +205,6 @@ class DataStoreValueSerializationTest : BaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `data class round-trip - FossUpgrade nullable`() = runTest2 {
|
||||
val ds = createDataStore()
|
||||
val pref = ds.createValue<FossUpgrade?>("upgrade", null, json)
|
||||
|
||||
pref.value() shouldBe null
|
||||
|
||||
val upgrade = FossUpgrade(
|
||||
upgradedAt = Instant.ofEpochMilli(1709553600000),
|
||||
reason = FossUpgrade.Reason.DONATED,
|
||||
)
|
||||
pref.value(upgrade)
|
||||
val result = pref.value()
|
||||
|
||||
result!!.upgradedAt shouldBe Instant.ofEpochMilli(1709553600000)
|
||||
result.reason shouldBe FossUpgrade.Reason.DONATED
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `InstantEpochMillisSerializer round-trip`() {
|
||||
val instant = Instant.ofEpochMilli(1709553600000)
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package eu.darken.capod.common.datastore
|
||||
|
||||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
|
||||
import com.squareup.moshi.Json as MoshiJson
|
||||
import eu.darken.capod.common.upgrade.core.FossUpgrade
|
||||
import io.kotest.matchers.shouldBe
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.serializer
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import testhelpers.BaseTest
|
||||
import testhelpers.coroutine.runTest2
|
||||
import java.io.File
|
||||
import java.time.Instant
|
||||
|
||||
class FossUpgradeSerializationTest : BaseTest() {
|
||||
|
||||
@TempDir
|
||||
lateinit var tempDir: File
|
||||
|
||||
private var dsCounter = 0
|
||||
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
encodeDefaults = true
|
||||
explicitNulls = false
|
||||
}
|
||||
|
||||
private fun createDataStore() = PreferenceDataStoreFactory.create(
|
||||
produceFile = { File(tempDir, "test_${dsCounter++}.preferences_pb") }
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `data class round-trip - FossUpgrade nullable`() = runTest2 {
|
||||
val ds = createDataStore()
|
||||
val pref = ds.createValue<FossUpgrade?>("upgrade", null, json)
|
||||
|
||||
pref.value() shouldBe null
|
||||
|
||||
val upgrade = FossUpgrade(
|
||||
upgradedAt = Instant.ofEpochMilli(1709553600000),
|
||||
reason = FossUpgrade.Reason.DONATED,
|
||||
)
|
||||
pref.value(upgrade)
|
||||
val result = pref.value()
|
||||
|
||||
result!!.upgradedAt shouldBe Instant.ofEpochMilli(1709553600000)
|
||||
result.reason shouldBe FossUpgrade.Reason.DONATED
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SerialName matches Json name - FossUpgrade Reason`() {
|
||||
val enumClass = FossUpgrade.Reason::class.java
|
||||
for (constant in enumClass.enumConstants!!) {
|
||||
val field = enumClass.getField(constant.name)
|
||||
val moshiAnnotation = field.getAnnotation(MoshiJson::class.java)
|
||||
val serialNameAnnotation = field.getAnnotation(SerialName::class.java)
|
||||
|
||||
if (moshiAnnotation != null && serialNameAnnotation != null) {
|
||||
serialNameAnnotation.value shouldBe moshiAnnotation.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Moshi-serialized FossUpgrade JSON is readable by kotlinx`() {
|
||||
val moshiJson = """{"upgradedAt":1709553600000,"reason":"foss.upgrade.reason.donated"}"""
|
||||
val result = json.decodeFromString(serializer<FossUpgrade>(), moshiJson)
|
||||
result.upgradedAt shouldBe Instant.ofEpochMilli(1709553600000)
|
||||
result.reason shouldBe FossUpgrade.Reason.DONATED
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user