refactor: null safety, update date/time libraries, and migrate tests (#4900)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich
2026-03-23 18:17:50 -05:00
committed by GitHub
parent f826cac6c8
commit 664ebf218e
163 changed files with 503 additions and 4993 deletions
@@ -19,20 +19,18 @@ package org.meshtastic.core.prefs.filter
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import dev.mokkery.every
import dev.mokkery.mock
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.meshtastic.core.di.CoroutineDispatchers
import org.meshtastic.core.repository.FilterPrefs
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class FilterPrefsTest {
@get:Rule val tmpFolder: TemporaryFolder = TemporaryFolder.builder().assureDeletion().build()
@@ -44,23 +42,23 @@ class FilterPrefsTest {
private val testDispatcher = UnconfinedTestDispatcher()
private val testScope = TestScope(testDispatcher)
@Before
@BeforeTest
fun setup() {
dataStore =
PreferenceDataStoreFactory.create(
scope = testScope,
produceFile = { tmpFolder.newFile("test.preferences_pb") },
)
dispatchers = mock()
every { dispatchers.default } returns testDispatcher
dispatchers = CoroutineDispatchers(testDispatcher, testDispatcher, testDispatcher)
filterPrefs = FilterPrefsImpl(dataStore, dispatchers)
}
@Test fun `filterEnabled defaults to false`() = testScope.runTest { assertFalse(filterPrefs.filterEnabled.value) }
@Test
fun `filterWords defaults to empty set`() =
testScope.runTest { assertTrue(filterPrefs.filterWords.value.isEmpty()) }
fun `filterWords defaults to empty set`() = testScope.runTest {
assertTrue(filterPrefs.filterWords.value.isEmpty())
}
@Test
fun `setting filterEnabled updates preference`() = testScope.runTest {
@@ -19,19 +19,17 @@ package org.meshtastic.core.prefs.notification
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import dev.mokkery.every
import dev.mokkery.mock
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.meshtastic.core.di.CoroutineDispatchers
import org.meshtastic.core.repository.NotificationPrefs
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class NotificationPrefsTest {
@get:Rule val tmpFolder: TemporaryFolder = TemporaryFolder.builder().assureDeletion().build()
@@ -43,15 +41,14 @@ class NotificationPrefsTest {
private val testDispatcher = UnconfinedTestDispatcher()
private val testScope = TestScope(testDispatcher)
@Before
@BeforeTest
fun setup() {
dataStore =
PreferenceDataStoreFactory.create(
scope = testScope,
produceFile = { tmpFolder.newFile("test.preferences_pb") },
)
dispatchers = mock()
every { dispatchers.default } returns testDispatcher
dispatchers = CoroutineDispatchers(testDispatcher, testDispatcher, testDispatcher)
notificationPrefs = NotificationPrefsImpl(dataStore, dispatchers)
}
@@ -59,12 +56,14 @@ class NotificationPrefsTest {
fun `messagesEnabled defaults to true`() = testScope.runTest { assertTrue(notificationPrefs.messagesEnabled.value) }
@Test
fun `nodeEventsEnabled defaults to true`() =
testScope.runTest { assertTrue(notificationPrefs.nodeEventsEnabled.value) }
fun `nodeEventsEnabled defaults to true`() = testScope.runTest {
assertTrue(notificationPrefs.nodeEventsEnabled.value)
}
@Test
fun `lowBatteryEnabled defaults to true`() =
testScope.runTest { assertTrue(notificationPrefs.lowBatteryEnabled.value) }
fun `lowBatteryEnabled defaults to true`() = testScope.runTest {
assertTrue(notificationPrefs.lowBatteryEnabled.value)
}
@Test
fun `setting messagesEnabled updates preference`() = testScope.runTest {