-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-readme-02.kt
41 lines (31 loc) · 1023 Bytes
/
example-readme-02.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-FileCopyrightText: 2020-2024 Eduard Wolf
//
// SPDX-License-Identifier: Apache-2.0
// This file was automatically generated from README.md by Knit tool. Do not edit.
package net.edwardday.serialization.preferences.example.exampleReadme02
import android.content.*
import kotlin.test.*
import kotlinx.serialization.*
import net.edwardday.serialization.preferences.*
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class ReadmeExample {
val sharedPreferences = createContext().getSharedPreferences("test_preferences", Context.MODE_PRIVATE)
@AfterTest
fun tearDown() {
sharedPreferences.edit().clear().apply()
}
@Test
fun readmeTest() {
val preferences = Preferences(sharedPreferences)
var someFlag: Boolean by preferences.asProperty(default = false)
fun someComputation() {
someFlag = true
}
someComputation()
if (!someFlag) { // reads value from SharedPreferences at key "someFlag"
fail()
}
}
}