7
7
package mozilla.lockbox.store
8
8
9
9
import android.content.Context
10
+ import android.content.res.Resources
10
11
import android.content.SharedPreferences
12
+ import android.content.res.Configuration
11
13
import android.os.Build
14
+ import android.os.LocaleList
12
15
import android.preference.PreferenceManager
13
16
import android.view.autofill.AutofillManager
14
17
import com.f2prateek.rx.preferences2.Preference
@@ -41,6 +44,7 @@ import org.powermock.api.mockito.PowerMockito
41
44
import org.powermock.core.classloader.annotations.PrepareForTest
42
45
import org.powermock.modules.junit4.PowerMockRunner
43
46
import org.robolectric.util.ReflectionHelpers
47
+ import java.util.Locale
44
48
import org.mockito.Mockito.`when` as whenCalled
45
49
46
50
@RunWith(PowerMockRunner ::class )
@@ -49,6 +53,18 @@ class SettingStoreTest : DisposingTest() {
49
53
@Mock
50
54
val context: Context = Mockito .mock(Context ::class .java)
51
55
56
+ @Mock
57
+ val resources: Resources = Mockito .mock(Resources ::class .java)
58
+
59
+ @Mock
60
+ val configuration: Configuration = Mockito .mock(Configuration ::class .java)
61
+
62
+ @Mock
63
+ val locales: LocaleList = Mockito .mock(LocaleList ::class .java)
64
+
65
+ @Mock
66
+ val locale: Locale = Mockito .mock(Locale ::class .java)
67
+
52
68
@Mock
53
69
val sharedPreferences: SharedPreferences = Mockito .mock(SharedPreferences ::class .java)
54
70
@@ -139,6 +155,21 @@ class SettingStoreTest : DisposingTest() {
139
155
override fun delete () { TODO (" not implemented" ) }
140
156
}
141
157
158
+ private val useLocalServiceSetting = PublishSubject .create<Boolean >()
159
+ private val useLocalserviceStub = object : Preference <Boolean > {
160
+ override fun asObservable (): Observable <Boolean > {
161
+ return useLocalServiceSetting
162
+ }
163
+
164
+ override fun isSet (): Boolean { TODO (" not implemented" ) }
165
+ override fun key (): String { TODO (" not implemented" ) }
166
+ override fun asConsumer (): Consumer <in Boolean > { TODO (" not implemented" ) }
167
+ override fun defaultValue (): Boolean { TODO (" not implemented" ) }
168
+ override fun get (): Boolean { TODO (" not implemented" ) }
169
+ override fun set (value : Boolean ) { TODO (" not implemented" ) }
170
+ override fun delete () { TODO (" not implemented" ) }
171
+ }
172
+
142
173
private val itemListSortSetting = PublishSubject .create<String >()
143
174
private val itemListSortStub = object : Preference <String > {
144
175
override fun asObservable (): Observable <String > {
@@ -157,6 +188,7 @@ class SettingStoreTest : DisposingTest() {
157
188
private val dispatcher = Dispatcher ()
158
189
var subject = SettingStore (dispatcher, fingerprintStore)
159
190
private val sendUsageDataObserver = TestObserver <Boolean >()
191
+ private val useLocalServiceObserver = TestObserver <Boolean >()
160
192
private val itemListSortOrder = TestObserver <Setting .ItemListSort >()
161
193
private val unlockWithFingerprint = TestObserver <Boolean >()
162
194
private val autoLockTime = TestObserver <Setting .AutoLockTime >()
@@ -168,6 +200,11 @@ class SettingStoreTest : DisposingTest() {
168
200
fun setUp () {
169
201
ReflectionHelpers .setStaticField(Build .VERSION ::class .java, " SDK_INT" , 28 )
170
202
203
+ whenCalled(context.resources).thenReturn(resources)
204
+ whenCalled(resources.configuration).thenReturn(configuration)
205
+ whenCalled(configuration.locales).thenReturn(locales)
206
+ whenCalled(locales.get(0 )).thenReturn(locale)
207
+
171
208
whenCalled(editor.putBoolean(Mockito .anyString(), Mockito .anyBoolean())).thenReturn(editor)
172
209
whenCalled(editor.putString(Mockito .anyString(), Mockito .anyString())).thenReturn(editor)
173
210
whenCalled(sharedPreferences.edit()).thenReturn(editor)
@@ -178,6 +215,7 @@ class SettingStoreTest : DisposingTest() {
178
215
whenCalled(rxSharedPreferences.getString(eq(SettingStore .Keys .AUTO_LOCK_TIME ), anyString())).thenReturn(autoLockStub)
179
216
whenCalled(rxSharedPreferences.getBoolean(eq(SettingStore .Keys .DEVICE_SECURITY_PRESENT ), anyBoolean())).thenReturn(deviceSecureStub)
180
217
whenCalled(rxSharedPreferences.getBoolean(eq(SettingStore .Keys .SEND_USAGE_DATA ), anyBoolean())).thenReturn(sendUsageDataStub)
218
+ whenCalled(rxSharedPreferences.getBoolean(eq(SettingStore .Keys .USE_LOCAL_SERVICE ), anyBoolean())).thenReturn(useLocalserviceStub)
181
219
whenCalled(rxSharedPreferences.getBoolean(eq(SettingStore .Keys .UNLOCK_WITH_FINGERPRINT ), anyBoolean())).thenReturn(unlockWithFingerprintStub)
182
220
whenCalled(rxSharedPreferences.getString(eq(SettingStore .Keys .ITEM_LIST_SORT_ORDER ), anyString())).thenReturn(itemListSortStub)
183
221
whenCalled(rxSharedPreferences.getBoolean(SettingStore .Keys .UNLOCK_WITH_FINGERPRINT_PENDING_AUTH )).thenReturn(unlockWithFingerprintPendingAuthStub)
@@ -193,6 +231,7 @@ class SettingStoreTest : DisposingTest() {
193
231
subject.sendUsageData.subscribe(sendUsageDataObserver)
194
232
subject.unlockWithFingerprint.subscribe(unlockWithFingerprint)
195
233
subject.itemListSortOrder.subscribe(itemListSortOrder)
234
+ subject.useLocalService.subscribe(useLocalServiceObserver)
196
235
197
236
clearInvocations(editor)
198
237
}
@@ -384,6 +423,7 @@ class SettingStoreTest : DisposingTest() {
384
423
385
424
verify(editor).putString(SettingStore .Keys .ITEM_LIST_SORT_ORDER , Constant .SettingDefault .itemListSort.name)
386
425
verify(editor).putBoolean(SettingStore .Keys .SEND_USAGE_DATA , Constant .SettingDefault .sendUsageData)
426
+ verify(editor).putBoolean(SettingStore .Keys .USE_LOCAL_SERVICE , Constant .SettingDefault .useLocalServiceFalse)
387
427
verify(editor).putString(SettingStore .Keys .AUTO_LOCK_TIME , Constant .SettingDefault .autoLockTime.name)
388
428
verify(editor).apply ()
389
429
verify(autofillManager).disableAutofillServices()
@@ -396,6 +436,7 @@ class SettingStoreTest : DisposingTest() {
396
436
397
437
verify(editor).putString(SettingStore .Keys .ITEM_LIST_SORT_ORDER , Constant .SettingDefault .itemListSort.name)
398
438
verify(editor).putBoolean(SettingStore .Keys .SEND_USAGE_DATA , Constant .SettingDefault .sendUsageData)
439
+ verify(editor).putBoolean(SettingStore .Keys .USE_LOCAL_SERVICE , Constant .SettingDefault .useLocalServiceFalse)
399
440
verify(editor).putString(SettingStore .Keys .AUTO_LOCK_TIME , Constant .SettingDefault .autoLockTime.name)
400
441
verify(editor).apply ()
401
442
verify(autofillManager).disableAutofillServices()
@@ -408,6 +449,7 @@ class SettingStoreTest : DisposingTest() {
408
449
409
450
verify(editor).putString(SettingStore .Keys .ITEM_LIST_SORT_ORDER , Constant .SettingDefault .itemListSort.name)
410
451
verify(editor).putBoolean(SettingStore .Keys .SEND_USAGE_DATA , Constant .SettingDefault .sendUsageData)
452
+ verify(editor).putBoolean(SettingStore .Keys .USE_LOCAL_SERVICE , Constant .SettingDefault .useLocalServiceFalse)
411
453
verify(editor).putString(SettingStore .Keys .AUTO_LOCK_TIME , Constant .SettingDefault .autoLockTime.name)
412
454
verify(editor).apply ()
413
455
verify(autofillManager, never()).disableAutofillServices()
@@ -420,6 +462,7 @@ class SettingStoreTest : DisposingTest() {
420
462
421
463
verify(editor).putString(SettingStore .Keys .ITEM_LIST_SORT_ORDER , Constant .SettingDefault .itemListSort.name)
422
464
verify(editor).putBoolean(SettingStore .Keys .SEND_USAGE_DATA , Constant .SettingDefault .sendUsageData)
465
+ verify(editor).putBoolean(SettingStore .Keys .USE_LOCAL_SERVICE , Constant .SettingDefault .useLocalServiceFalse)
423
466
verify(editor).putString(SettingStore .Keys .AUTO_LOCK_TIME , Constant .SettingDefault .autoLockTime.name)
424
467
verify(editor).apply ()
425
468
verify(autofillManager, never()).disableAutofillServices()
0 commit comments