Skip to content

Commit da6715a

Browse files
committed
- Prefs Edit section test case added
1 parent d894b5d commit da6715a

File tree

4 files changed

+236
-0
lines changed

4 files changed

+236
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.sample.easyprefs
2+
3+
import android.content.Context
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import androidx.test.platform.app.InstrumentationRegistry
6+
import io.easyprefs.Prefs
7+
import org.junit.Assert.assertEquals
8+
import org.junit.Assert.assertTrue
9+
import org.junit.Before
10+
import org.junit.Test
11+
import org.junit.runner.RunWith
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* See [testing documentation](http://d.android.com/tools/testing).
17+
*/
18+
@RunWith(AndroidJUnit4::class)
19+
class PrefsContextEditTest {
20+
21+
private lateinit var context: Context
22+
23+
@Before
24+
fun initApp() {
25+
//Prefs.initializeApp()
26+
context = InstrumentationRegistry.getInstrumentation().targetContext
27+
}
28+
29+
@Test
30+
fun testRemove() {
31+
assertTrue(Prefs.edit(context).remove(Const.SAMPLE_STRING_KEY))
32+
33+
val data = Prefs.read(context).string(Const.SAMPLE_STRING_KEY, "")
34+
assertEquals("", data)
35+
}
36+
37+
@Test
38+
fun testRemoveAsync() {
39+
Prefs.edit(context).removeAsync(Const.SAMPLE_STRING_KEY_ASYNC)
40+
41+
val data = Prefs.read(context).string(Const.SAMPLE_STRING_KEY_ASYNC, "")
42+
assertEquals("", data)
43+
}
44+
45+
@Test
46+
fun testClear() {
47+
Prefs.edit(context).clear()
48+
49+
val data = Prefs.read(context).string(Const.SAMPLE_STRING_SET_KEY, "")
50+
assertEquals("", data)
51+
}
52+
53+
@Test
54+
fun testClearAsync() {
55+
Prefs.edit(context).clearAsync()
56+
57+
val data = Prefs.read(context).string(Const.SAMPLE_STRING_SET_KEY_ASYNC, "")
58+
assertEquals("", data)
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.sample.easyprefs
2+
3+
import android.content.Context
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import androidx.test.platform.app.InstrumentationRegistry
6+
import io.easyprefs.Prefs
7+
import org.junit.Assert.assertEquals
8+
import org.junit.Assert.assertTrue
9+
import org.junit.Before
10+
import org.junit.Test
11+
import org.junit.runner.RunWith
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* See [testing documentation](http://d.android.com/tools/testing).
17+
*/
18+
@RunWith(AndroidJUnit4::class)
19+
class PrefsEditContextFileTest {
20+
21+
private lateinit var context: Context
22+
23+
@Before
24+
fun initApp() {
25+
//Prefs.initializeApp()
26+
context = InstrumentationRegistry.getInstrumentation().targetContext
27+
}
28+
29+
@Test
30+
fun testRemove() {
31+
assertTrue(Prefs.edit(context, Const.PREF_SAMPLE_FILE).remove(Const.SAMPLE_STRING_KEY))
32+
33+
val data = Prefs.read(context, Const.PREF_SAMPLE_FILE).string(Const.SAMPLE_STRING_KEY, "")
34+
assertEquals("", data)
35+
}
36+
37+
@Test
38+
fun testRemoveAsync() {
39+
Prefs.edit(context, Const.PREF_SAMPLE_FILE).removeAsync(Const.SAMPLE_STRING_KEY_ASYNC)
40+
41+
val data =
42+
Prefs.read(context, Const.PREF_SAMPLE_FILE).string(Const.SAMPLE_STRING_KEY_ASYNC, "")
43+
assertEquals("", data)
44+
}
45+
46+
@Test
47+
fun testClear() {
48+
Prefs.edit(context, Const.PREF_SAMPLE_FILE).clear()
49+
50+
val data =
51+
Prefs.read(context, Const.PREF_SAMPLE_FILE).string(Const.SAMPLE_STRING_SET_KEY, "")
52+
assertEquals("", data)
53+
}
54+
55+
@Test
56+
fun testClearAsync() {
57+
Prefs.edit(context, Const.PREF_SAMPLE_FILE).clearAsync()
58+
59+
val data = Prefs.read(context, Const.PREF_SAMPLE_FILE)
60+
.string(Const.SAMPLE_STRING_SET_KEY_ASYNC, "")
61+
assertEquals("", data)
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.sample.easyprefs
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import io.easyprefs.Prefs
6+
import org.junit.Assert.assertEquals
7+
import org.junit.Assert.assertTrue
8+
import org.junit.Before
9+
import org.junit.Test
10+
import org.junit.runner.RunWith
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* See [testing documentation](http://d.android.com/tools/testing).
16+
*/
17+
@RunWith(AndroidJUnit4::class)
18+
class PrefsEditFileTest {
19+
20+
@Before
21+
fun initApp() {
22+
Prefs.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
23+
}
24+
25+
@Test
26+
fun testRemove() {
27+
assertTrue(Prefs.edit(Const.PREF_SAMPLE_FILE_2).remove(Const.SAMPLE_STRING_KEY))
28+
29+
val data = Prefs.read(Const.PREF_SAMPLE_FILE_2).string(Const.SAMPLE_STRING_KEY, "")
30+
assertEquals("", data)
31+
}
32+
33+
@Test
34+
fun testRemoveAsync() {
35+
Prefs.edit(Const.PREF_SAMPLE_FILE_2).removeAsync(Const.SAMPLE_STRING_KEY_ASYNC)
36+
37+
val data = Prefs.read(Const.PREF_SAMPLE_FILE_2).string(Const.SAMPLE_STRING_KEY_ASYNC, "")
38+
assertEquals("", data)
39+
}
40+
41+
@Test
42+
fun testClear() {
43+
Prefs.edit(Const.PREF_SAMPLE_FILE_2).clear()
44+
45+
val data = Prefs.read(Const.PREF_SAMPLE_FILE_2).string(Const.SAMPLE_STRING_SET_KEY, "")
46+
assertEquals("", data)
47+
}
48+
49+
@Test
50+
fun testClearAsync() {
51+
Prefs.edit(Const.PREF_SAMPLE_FILE_2).clearAsync()
52+
53+
val data =
54+
Prefs.read(Const.PREF_SAMPLE_FILE_2).string(Const.SAMPLE_STRING_SET_KEY_ASYNC, "")
55+
assertEquals("", data)
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.sample.easyprefs
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import io.easyprefs.Prefs
6+
import org.junit.Assert.assertEquals
7+
import org.junit.Assert.assertTrue
8+
import org.junit.Before
9+
import org.junit.Test
10+
import org.junit.runner.RunWith
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* See [testing documentation](http://d.android.com/tools/testing).
16+
*/
17+
@RunWith(AndroidJUnit4::class)
18+
class PrefsEditTest {
19+
20+
@Before
21+
fun initApp() {
22+
Prefs.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
23+
}
24+
25+
@Test
26+
fun testRemove() {
27+
assertTrue(Prefs.edit().remove(Const.SAMPLE_STRING_KEY))
28+
29+
val data = Prefs.read().string(Const.SAMPLE_STRING_KEY, "")
30+
assertEquals("", data)
31+
}
32+
33+
@Test
34+
fun testRemoveAsync() {
35+
Prefs.edit().removeAsync(Const.SAMPLE_STRING_KEY_ASYNC)
36+
37+
val data = Prefs.read().string(Const.SAMPLE_STRING_KEY_ASYNC, "")
38+
assertEquals("", data)
39+
}
40+
41+
@Test
42+
fun testClear() {
43+
Prefs.edit().clear()
44+
45+
val data = Prefs.read().string(Const.SAMPLE_STRING_SET_KEY, "")
46+
assertEquals("", data)
47+
}
48+
49+
@Test
50+
fun testClearAsync() {
51+
Prefs.edit().clearAsync()
52+
53+
val data = Prefs.read().string(Const.SAMPLE_STRING_SET_KEY_ASYNC, "")
54+
assertEquals("", data)
55+
}
56+
}

0 commit comments

Comments
 (0)