Skip to content

Commit 22bc66e

Browse files
committed
added has and remove api and accordingly test cases
1 parent 41f4028 commit 22bc66e

File tree

18 files changed

+711
-26
lines changed

18 files changed

+711
-26
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.sample.easyprefs.kotlin.has
2+
3+
import android.content.Context
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import androidx.test.platform.app.InstrumentationRegistry
6+
import com.sample.easyprefs.kotlin.Const
7+
import io.easyprefs.Prefs
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 PrefsHasContextFileTest {
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 testHasOp() {
31+
assertTrue(Prefs.has(context, Const.PREF_SAMPLE_FILE).key(Const.SAMPLE_STRING_KEY))
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.sample.easyprefs.kotlin.has
2+
3+
import android.content.Context
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import androidx.test.platform.app.InstrumentationRegistry
6+
import com.sample.easyprefs.kotlin.Const
7+
import io.easyprefs.Prefs
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 PrefsHasContextTest {
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 testHasOp() {
31+
assertTrue(Prefs.has(context).key(Const.SAMPLE_STRING_KEY))
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.sample.easyprefs.kotlin.has
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import com.sample.easyprefs.kotlin.Const
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 PrefsHasFileTest {
20+
21+
@Before
22+
fun initApp() {
23+
Prefs.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
24+
}
25+
26+
@Test
27+
fun testHasOp() {
28+
assertTrue(Prefs.has(Const.PREF_SAMPLE_FILE).key(Const.SAMPLE_STRING_KEY))
29+
}
30+
}

app/src/androidTest/java/com/sample/easyprefs/kotlin/secure/SecurePrefsReadAsyncTest.kt renamed to app/src/androidTest/java/com/sample/easyprefs/kotlin/has/PrefsHasTest.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
package com.sample.easyprefs.kotlin.secure
1+
package com.sample.easyprefs.kotlin.has
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import androidx.test.platform.app.InstrumentationRegistry
5+
import com.sample.easyprefs.kotlin.Const
56
import io.easyprefs.Prefs
7+
import org.junit.Assert.assertTrue
68
import org.junit.Before
9+
import org.junit.Test
710
import org.junit.runner.RunWith
811

912
/**
@@ -12,11 +15,15 @@ import org.junit.runner.RunWith
1215
* See [testing documentation](http://d.android.com/tools/testing).
1316
*/
1417
@RunWith(AndroidJUnit4::class)
15-
class SecurePrefsReadAsyncTest {
18+
class PrefsHasTest {
1619

1720
@Before
1821
fun initApp() {
1922
Prefs.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
2023
}
2124

22-
}
25+
@Test
26+
fun testHasOp() {
27+
assertTrue(Prefs.has().key(Const.SAMPLE_STRING_KEY))
28+
}
29+
}

app/src/androidTest/java/com/sample/easyprefs/kotlin/rdwr/PrefsTest.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ class PrefsTest {
8282
.content(Const.SAMPLE_BOOLEAN_KEY_APPLY, p6)
8383
.content(Const.SAMPLE_STRING_SET_KEY_APPLY, p7)
8484
.apply()
85-
}
86-
87-
@Test
88-
fun testReadApplyOp() {
8985

9086
val o1 = Prefs.read().content(Const.SAMPLE_STRING_KEY_APPLY, "")
9187
assertEquals(p1, o1)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.sample.easyprefs.kotlin.remove
2+
3+
import android.content.Context
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import androidx.test.platform.app.InstrumentationRegistry
6+
import com.sample.easyprefs.kotlin.Const
7+
import io.easyprefs.Prefs
8+
import org.junit.Assert.assertEquals
9+
import org.junit.Assert.assertTrue
10+
import org.junit.Before
11+
import org.junit.Test
12+
import org.junit.runner.RunWith
13+
14+
/**
15+
* Instrumented test, which will execute on an Android device.
16+
*
17+
* See [testing documentation](http://d.android.com/tools/testing).
18+
*/
19+
@RunWith(AndroidJUnit4::class)
20+
class PrefsRemoveContextFileTest {
21+
22+
private lateinit var context: Context
23+
24+
@Before
25+
fun initApp() {
26+
//Prefs.initializeApp()
27+
context = InstrumentationRegistry.getInstrumentation().targetContext
28+
}
29+
30+
@Test
31+
fun testClearCommitOp() {
32+
assertTrue(
33+
Prefs.remove(context, Const.PREF_SAMPLE_FILE).key(Const.SAMPLE_STRING_KEY).commit()
34+
)
35+
36+
val data = Prefs.read(context, Const.PREF_SAMPLE_FILE).content(Const.SAMPLE_STRING_KEY, "")
37+
assertEquals("", data)
38+
}
39+
40+
@Test
41+
fun testClearApplyOp() {
42+
Prefs.remove(context, Const.PREF_SAMPLE_FILE).key(Const.SAMPLE_STRING_KEY_APPLY).apply()
43+
44+
val data = Prefs.read(
45+
context,
46+
Const.PREF_SAMPLE_FILE
47+
).content(Const.SAMPLE_STRING_KEY_APPLY, "")
48+
assertEquals("", data)
49+
}
50+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.sample.easyprefs.kotlin.remove
2+
3+
import android.content.Context
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import androidx.test.platform.app.InstrumentationRegistry
6+
import com.sample.easyprefs.kotlin.Const
7+
import io.easyprefs.Prefs
8+
import org.junit.Assert.assertEquals
9+
import org.junit.Assert.assertTrue
10+
import org.junit.Before
11+
import org.junit.Test
12+
import org.junit.runner.RunWith
13+
14+
/**
15+
* Instrumented test, which will execute on an Android device.
16+
*
17+
* See [testing documentation](http://d.android.com/tools/testing).
18+
*/
19+
@RunWith(AndroidJUnit4::class)
20+
class PrefsRemoveContextTest {
21+
22+
private lateinit var context: Context
23+
24+
@Before
25+
fun initApp() {
26+
//Prefs.initializeApp()
27+
context = InstrumentationRegistry.getInstrumentation().targetContext
28+
}
29+
30+
@Test
31+
fun testClearCommitOp() {
32+
assertTrue(Prefs.remove(context).key(Const.SAMPLE_STRING_KEY).commit())
33+
34+
val data = Prefs.read(context).content(Const.SAMPLE_STRING_KEY, "")
35+
assertEquals("", data)
36+
}
37+
38+
@Test
39+
fun testClearApplyOp() {
40+
Prefs.remove(context).key(Const.SAMPLE_STRING_KEY_APPLY).apply()
41+
42+
val data = Prefs.read(context).content(Const.SAMPLE_STRING_KEY_APPLY, "")
43+
assertEquals("", data)
44+
}
45+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.sample.easyprefs.kotlin.remove
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import com.sample.easyprefs.kotlin.Const
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 PrefsRemoveFileTest {
20+
21+
@Before
22+
fun initApp() {
23+
Prefs.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
24+
}
25+
26+
@Test
27+
fun testClearCommitOp() {
28+
assertTrue(Prefs.remove(Const.PREF_SAMPLE_FILE_2).key(Const.SAMPLE_STRING_KEY).commit())
29+
30+
val data = Prefs.read(Const.PREF_SAMPLE_FILE_2).content(Const.SAMPLE_STRING_KEY, "")
31+
assertEquals("", data)
32+
}
33+
34+
@Test
35+
fun testClearApplyOp() {
36+
Prefs.remove(Const.PREF_SAMPLE_FILE_2).key(Const.SAMPLE_STRING_KEY_APPLY).apply()
37+
38+
val data = Prefs.read(Const.PREF_SAMPLE_FILE_2).content(Const.SAMPLE_STRING_KEY_APPLY, "")
39+
assertEquals("", data)
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.sample.easyprefs.kotlin.remove
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import com.sample.easyprefs.kotlin.Const
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 PrefsRemoveTest {
20+
21+
@Before
22+
fun initApp() {
23+
Prefs.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
24+
}
25+
26+
@Test
27+
fun testClearCommitOp() {
28+
assertTrue(Prefs.remove().key(Const.SAMPLE_STRING_KEY).commit())
29+
30+
val data = Prefs.read().content(Const.SAMPLE_STRING_KEY, "")
31+
assertEquals("", data)
32+
}
33+
34+
@Test
35+
fun testClearApplyOp() {
36+
Prefs.remove().key(Const.SAMPLE_STRING_KEY_APPLY).apply()
37+
38+
val data = Prefs.read().content(Const.SAMPLE_STRING_KEY_APPLY, "")
39+
assertEquals("", data)
40+
}
41+
}

app/src/androidTest/java/com/sample/easyprefs/kotlin/secure/Const.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ object Const {
55
const val PREF_SAMPLE_FILE_2 = "secure_sample_file_name_two"
66

77
const val SAMPLE_STRING_KEY = "secure_sample_string_key"
8-
const val SAMPLE_STRING_KEY_ASYNC = "secure_sample_string_key_async"
8+
const val SAMPLE_STRING_KEY_APPLY = "secure_sample_string_key_apply"
99

1010
const val SAMPLE_STRING_SET_KEY = "secure_sample_string_set_key"
11-
const val SAMPLE_STRING_SET_KEY_ASYNC = "secure_sample_string_set_key_async"
11+
const val SAMPLE_STRING_SET_KEY_APPLY = "secure_sample_string_set_key_apply"
1212

1313
const val SAMPLE_INT_KEY = "secure_sample_int_key"
14-
const val SAMPLE_INT_KEY_ASYNC = "secure_sample_int_key_async"
14+
const val SAMPLE_INT_KEY_APPLY = "secure_sample_int_key_apply"
1515

1616
const val SAMPLE_LONG_KEY = "secure_sample_long_key"
17-
const val SAMPLE_LONG_KEY_ASYNC = "secure_sample_long_key_async"
17+
const val SAMPLE_LONG_KEY_APPLY = "secure_sample_long_key_apply"
1818

1919
const val SAMPLE_FLOAT_KEY = "secure_sample_float_key"
20-
const val SAMPLE_FLOAT_KEY_ASYNC = "secure_sample_float_key_async"
20+
const val SAMPLE_FLOAT_KEY_APPLY = "secure_sample_float_key_apply"
2121

2222
const val SAMPLE_DOUBLE_KEY = "secure_sample_double_key"
23-
const val SAMPLE_DOUBLE_KEY_ASYNC = "secure_sample_double_key_async"
23+
const val SAMPLE_DOUBLE_KEY_APPLY = "secure_sample_double_key_apply"
2424

2525
const val SAMPLE_BOOLEAN_KEY = "secure_sample_boolean_key"
26-
const val SAMPLE_BOOLEAN_KEY_ASYNC = "secure_sample_boolean_key_async"
26+
const val SAMPLE_BOOLEAN_KEY_APPLY = "secure_sample_boolean_key_apply"
2727
}

0 commit comments

Comments
 (0)