-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
153 additions
and
128 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
app/src/androidTest/kotlin/at/bitfire/davdroid/repository/AccountRepositoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details. | ||
*/ | ||
|
||
package at.bitfire.davdroid.repository | ||
|
||
import android.content.Context | ||
import at.bitfire.davdroid.R | ||
import at.bitfire.davdroid.db.AppDatabase | ||
import at.bitfire.davdroid.sync.account.TestAccountAuthenticator | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.android.testing.HiltAndroidRule | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import javax.inject.Inject | ||
import at.bitfire.davdroid.db.Account as DbAccount | ||
|
||
@HiltAndroidTest | ||
class AccountRepositoryTest { | ||
|
||
@Inject | ||
lateinit var accountRepository: AccountRepository | ||
|
||
@Inject @ApplicationContext | ||
lateinit var context: Context | ||
|
||
@Inject | ||
lateinit var db: AppDatabase | ||
|
||
@get:Rule | ||
val hiltRule = HiltAndroidRule(this) | ||
|
||
@Before | ||
fun setUp() { | ||
hiltRule.inject() | ||
} | ||
|
||
|
||
@Test | ||
fun testRemoveOrphanedInDb() { | ||
TestAccountAuthenticator.provide(accountType = context.getString(R.string.account_type)) { systemAccount -> | ||
val dao = db.accountDao() | ||
dao.insertOrIgnore(DbAccount(id = 1, name = systemAccount.name)) | ||
dao.insertOrIgnore(DbAccount(id = 2, name = "no-corresponding-system-account")) | ||
|
||
accountRepository.removeOrphanedInDb() | ||
|
||
// now the account without a corresponding system account should be removed | ||
assertEquals(listOf(DbAccount(id = 1, name = systemAccount.name)), db.accountDao().getAll()) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.