@@ -20,6 +20,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
20
20
import androidx.test.platform.app.InstrumentationRegistry
21
21
import com.duckduckgo.common.test.CoroutineTestRule
22
22
import kotlinx.coroutines.test.TestScope
23
+ import kotlinx.coroutines.test.runTest
23
24
import org.junit.Assert.assertEquals
24
25
import org.junit.Assert.assertNull
25
26
import org.junit.Assert.assertTrue
@@ -43,78 +44,78 @@ class SyncSharedPrefsStoreTest {
43
44
sharedPrefsProvider,
44
45
TestScope (),
45
46
coroutineRule.testDispatcherProvider,
46
- syncFeature. createAsyncPreferences().isEnabled() ,
47
+ createAsyncPreferences = true ,
47
48
)
48
49
}
49
50
50
51
@Test
51
- fun whenUserIdStoredThenValueUpdatedInPrefsStore () {
52
- assertNull(store.userId )
53
- store.userId = " test_user"
54
- assertEquals(" test_user" , store.userId )
55
- store.userId = null
56
- assertNull(store.userId )
52
+ fun whenUserIdStoredThenValueUpdatedInPrefsStore () = runTest {
53
+ assertNull(store.getUserId() )
54
+ store.setUserId( " test_user" )
55
+ assertEquals(" test_user" , store.getUserId() )
56
+ store.setUserId( null )
57
+ assertNull(store.getUserId() )
57
58
}
58
59
59
60
@Test
60
- fun whenDeviceNameStoredThenValueUpdatedInPrefsStore () {
61
- assertNull(store.deviceName )
62
- store.deviceName = " test_device"
63
- assertEquals(" test_device" , store.deviceName )
64
- store.deviceName = null
65
- assertNull(store.deviceName )
61
+ fun whenDeviceNameStoredThenValueUpdatedInPrefsStore () = runTest {
62
+ assertNull(store.getDeviceName() )
63
+ store.setDeviceName( " test_device" )
64
+ assertEquals(" test_device" , store.getDeviceName() )
65
+ store.setDeviceName( null )
66
+ assertNull(store.getDeviceName() )
66
67
}
67
68
68
69
@Test
69
- fun whenDeviceIdStoredThenValueUpdatedInPrefsStore () {
70
- assertNull(store.deviceId )
71
- store.deviceId = " test_device_id"
72
- assertEquals(" test_device_id" , store.deviceId )
73
- store.deviceId = null
74
- assertNull(store.deviceId )
70
+ fun whenDeviceIdStoredThenValueUpdatedInPrefsStore () = runTest {
71
+ assertNull(store.getDeviceId() )
72
+ store.setDeviceId( " test_device_id" )
73
+ assertEquals(" test_device_id" , store.getDeviceId() )
74
+ store.setDeviceId( null )
75
+ assertNull(store.getDeviceId() )
75
76
}
76
77
77
78
@Test
78
- fun whenStoreCredentialsThenValuesUpdatedInPrefsStore () {
79
- assertNull(store.userId )
80
- assertNull(store.deviceName )
81
- assertNull(store.deviceId )
82
- assertNull(store.primaryKey )
83
- assertNull(store.secretKey )
84
- assertNull(store.token )
79
+ fun whenStoreCredentialsThenValuesUpdatedInPrefsStore () = runTest {
80
+ assertNull(store.getUserId() )
81
+ assertNull(store.getDeviceName() )
82
+ assertNull(store.getDeviceId() )
83
+ assertNull(store.getPrimaryKey() )
84
+ assertNull(store.getSecretKey() )
85
+ assertNull(store.getToken() )
85
86
store.storeCredentials(" userId" , " deviceId" , " deviceName" , " primaryKey" , " secretKey" , " token" )
86
- assertEquals(" userId" , store.userId )
87
- assertEquals(" deviceName" , store.deviceName )
88
- assertEquals(" deviceId" , store.deviceId )
89
- assertEquals(" primaryKey" , store.primaryKey )
90
- assertEquals(" secretKey" , store.secretKey )
91
- assertEquals(" token" , store.token )
87
+ assertEquals(" userId" , store.getUserId() )
88
+ assertEquals(" deviceName" , store.getDeviceName() )
89
+ assertEquals(" deviceId" , store.getDeviceId() )
90
+ assertEquals(" primaryKey" , store.getPrimaryKey() )
91
+ assertEquals(" secretKey" , store.getSecretKey() )
92
+ assertEquals(" token" , store.getToken() )
92
93
}
93
94
94
95
@Test
95
- fun whenIsSignedInThenReturnTrueIfUserHasAuthKeys () {
96
+ fun whenIsSignedInThenReturnTrueIfUserHasAuthKeys () = runTest {
96
97
store.storeCredentials(" userId" , " deviceId" , " deviceName" , " primaryKey" , " secretKey" , " token" )
97
98
98
99
assertTrue(store.isSignedIn())
99
100
}
100
101
101
102
@Test
102
- fun whenClearAllThenReturnRemoveAllKeys () {
103
+ fun whenClearAllThenReturnRemoveAllKeys () = runTest {
103
104
store.storeCredentials(" userId" , " deviceId" , " deviceName" , " primaryKey" , " secretKey" , " token" )
104
- assertEquals(" userId" , store.userId )
105
- assertEquals(" deviceName" , store.deviceName )
106
- assertEquals(" deviceId" , store.deviceId )
107
- assertEquals(" primaryKey" , store.primaryKey )
108
- assertEquals(" secretKey" , store.secretKey )
109
- assertEquals(" token" , store.token )
105
+ assertEquals(" userId" , store.getUserId() )
106
+ assertEquals(" deviceName" , store.getDeviceName() )
107
+ assertEquals(" deviceId" , store.getDeviceId() )
108
+ assertEquals(" primaryKey" , store.getPrimaryKey() )
109
+ assertEquals(" secretKey" , store.getSecretKey() )
110
+ assertEquals(" token" , store.getToken() )
110
111
111
112
store.clearAll()
112
113
113
- assertNull(store.userId )
114
- assertNull(store.deviceName )
115
- assertNull(store.deviceId )
116
- assertNull(store.primaryKey )
117
- assertNull(store.secretKey )
118
- assertNull(store.token )
114
+ assertNull(store.getUserId() )
115
+ assertNull(store.getDeviceName() )
116
+ assertNull(store.getDeviceId() )
117
+ assertNull(store.getPrimaryKey() )
118
+ assertNull(store.getSecretKey() )
119
+ assertNull(store.getToken() )
119
120
}
120
121
}
0 commit comments