-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash an first app start while reading out the theme from prefere…
…nces
- Loading branch information
Showing
3 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...n-app/src/test/kotlin/org/piepmeyer/gauguin/preferences/ApplicationPreferencesImplTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.piepmeyer.gauguin.preferences | ||
|
||
import android.content.SharedPreferences | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.datatest.withData | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.piepmeyer.gauguin.Theme | ||
|
||
class ApplicationPreferencesImplTest : | ||
FunSpec({ | ||
|
||
data class ThemeTestData( | ||
val sharedPreferenceValue: String?, | ||
val expectedTheme: Theme, | ||
) | ||
|
||
withData( | ||
ThemeTestData(null, Theme.DARK), | ||
ThemeTestData("unknown", Theme.DARK), | ||
ThemeTestData("DARK", Theme.DARK), | ||
ThemeTestData("LIGHT", Theme.LIGHT), | ||
ThemeTestData("DYNAMIC_COLORS", Theme.DYNAMIC_COLORS), | ||
ThemeTestData("SYSTEM_DEFAULT", Theme.SYSTEM_DEFAULT), | ||
) { testData -> | ||
val sharedPreferences = | ||
mockk<SharedPreferences> { | ||
every { getString("theme", null) } returns testData.sharedPreferenceValue | ||
} | ||
|
||
val preferences = | ||
ApplicationPreferencesImpl( | ||
mockk(), | ||
sharedPreferences, | ||
) | ||
|
||
preferences.theme shouldBe testData.expectedTheme | ||
} | ||
}) |