@@ -28,7 +28,6 @@ import com.ichi2.anki.servicelayer.PreferenceUpgradeService.PreferenceUpgrade
28
28
import com.ichi2.anki.servicelayer.RemovedPreferences
29
29
import com.ichi2.anki.web.CustomSyncServer
30
30
import com.ichi2.libanki.Consts
31
- import com.ichi2.testutils.EmptyApplication
32
31
import com.ichi2.utils.HashUtil
33
32
import org.hamcrest.CoreMatchers.equalTo
34
33
import org.hamcrest.MatcherAssert.assertThat
@@ -37,10 +36,8 @@ import org.junit.Assert.assertEquals
37
36
import org.junit.Before
38
37
import org.junit.Test
39
38
import org.junit.runner.RunWith
40
- import org.robolectric.annotation.Config
41
39
42
40
@RunWith(AndroidJUnit4 ::class )
43
- @Config(application = EmptyApplication ::class ) // no point in Application init if we don't use it
44
41
class PreferenceUpgradeServiceTest : RobolectricTest () {
45
42
46
43
private lateinit var mPrefs: SharedPreferences
@@ -184,4 +181,22 @@ class PreferenceUpgradeServiceTest : RobolectricTest() {
184
181
assertThat(mPrefs.contains(RemovedPreferences .PREFERENCE_CUSTOM_SYNC_BASE ), equalTo(false ))
185
182
assertThat(mPrefs.getString(CustomSyncServer .PREFERENCE_CUSTOM_COLLECTION_SYNC_URL , " " ), equalTo(" http://foo/sync/" ))
186
183
}
184
+
185
+ @Test
186
+ fun `Removed Use custom sync server preference is applied to both sync URL preferences after upgrade` () {
187
+ mPrefs.edit {
188
+ putString(CustomSyncServer .PREFERENCE_CUSTOM_COLLECTION_SYNC_URL , " http://foo/sync/" )
189
+ putBoolean(RemovedPreferences .PREFERENCE_ENABLE_CUSTOM_SYNC_SERVER , true )
190
+ }
191
+
192
+ assertThat(CustomSyncServer .getCollectionSyncUrlIfSetAndEnabledOrNull(mPrefs), equalTo(null ))
193
+ assertThat(CustomSyncServer .getMediaSyncUrlIfSetAndEnabledOrNull(mPrefs), equalTo(null ))
194
+
195
+ PreferenceUpgrade .UpgradeCustomSyncServerEnabled ().performUpgrade(mPrefs)
196
+
197
+ assertThat(mPrefs.getBoolean(CustomSyncServer .PREFERENCE_CUSTOM_COLLECTION_SYNC_SERVER_ENABLED , false ), equalTo(true ))
198
+ assertThat(mPrefs.getBoolean(CustomSyncServer .PREFERENCE_CUSTOM_MEDIA_SYNC_SERVER_ENABLED , false ), equalTo(false ))
199
+ assertThat(CustomSyncServer .getCollectionSyncUrlIfSetAndEnabledOrNull(mPrefs), equalTo(" http://foo/sync/" ))
200
+ assertThat(CustomSyncServer .getMediaSyncUrlIfSetAndEnabledOrNull(mPrefs), equalTo(null ))
201
+ }
187
202
}
0 commit comments