Skip to content

Commit 0287a2b

Browse files
committed
[WIP] Add migration test
1 parent 87b74a6 commit 0287a2b

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
3+
*/
4+
5+
package at.bitfire.davdroid.settings.migration
6+
7+
import android.accounts.Account
8+
import android.content.ContentResolver
9+
import android.content.SyncRequest
10+
import android.os.Bundle
11+
import android.provider.ContactsContract
12+
import at.bitfire.davdroid.sync.account.TestAccount
13+
import dagger.hilt.android.testing.HiltAndroidTest
14+
import org.junit.Assert.assertFalse
15+
import org.junit.Assert.assertTrue
16+
import org.junit.Before
17+
import org.junit.Test
18+
import javax.inject.Inject
19+
20+
@HiltAndroidTest
21+
class AccountSettingsMigration21Test {
22+
23+
@Inject
24+
lateinit var migration: AccountSettingsMigration21
25+
26+
lateinit var account: Account
27+
28+
@Before
29+
fun setUp() {
30+
account = TestAccount.create()
31+
}
32+
33+
34+
@Test
35+
fun testCancelsSyncs() {
36+
val authority = ContactsContract.AUTHORITY
37+
38+
// Build sync request
39+
val syncRequest = SyncRequest.Builder()
40+
.setSyncAdapter(account, authority)
41+
.setExtras(Bundle(1).apply {
42+
putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, true)
43+
})
44+
.syncOnce()
45+
.build()
46+
47+
// Request sync
48+
ContentResolver.requestSync(syncRequest)
49+
50+
Thread.sleep(1000)
51+
52+
// Verify the sync is now pending
53+
assertTrue(ContentResolver.isSyncPending(account, authority))
54+
55+
// Account is not used in migration; it should cancel for all accounts
56+
val invalidFakeAccount = Account("","")
57+
58+
// Run the migration which should cancel the sync
59+
migration.migrate(invalidFakeAccount)
60+
61+
Thread.sleep(1000)
62+
63+
// Check the sync is not pending anymore
64+
assertFalse(ContentResolver.isSyncPending(account, authority))
65+
66+
}
67+
68+
}

0 commit comments

Comments
 (0)