Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove test account type #1224

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions app/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,4 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS" android:maxSdkVersion="22"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" android:maxSdkVersion="22"/>

<application>

<!-- test account type (without associated sync adapters) -->
<service
android:name="at.bitfire.davdroid.sync.account.TestAccountAuthenticator"
android:exported="false">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
</intent-filter>

<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/test_account_authenticator"/>
</service>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ package at.bitfire.davdroid.resource

import android.Manifest
import android.accounts.Account
import android.accounts.AccountManager
import android.content.ContentProviderClient
import android.content.ContentUris
import android.content.Context
import android.provider.ContactsContract
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import at.bitfire.vcard4android.Contact
import at.bitfire.vcard4android.GroupMethod
import at.bitfire.vcard4android.LabeledProperty
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.android.testing.HiltAndroidRule
Expand All @@ -24,7 +22,7 @@ import org.junit.After
import org.junit.AfterClass
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.BeforeClass
import org.junit.ClassRule
Expand All @@ -36,16 +34,12 @@ import javax.inject.Inject
@HiltAndroidTest
class LocalAddressBookTest {

@Inject @ApplicationContext
lateinit var context: Context

@get:Rule
val hiltRule = HiltAndroidRule(this)

@Inject
lateinit var addressbookFactory: LocalTestAddressBook.Factory

@Inject
@ApplicationContext
lateinit var context: Context

val account = Account("Test Account", "Test Account Type")
lateinit var addressBook: LocalTestAddressBook

Expand All @@ -54,15 +48,13 @@ class LocalAddressBookTest {
fun setUp() {
hiltRule.inject()

addressBook = addressbookFactory.create(account, provider, GroupMethod.CATEGORIES)
LocalTestAddressBook.createAccount(context)
addressBook = LocalTestAddressBook.create(context, account, provider)
}

@After
fun tearDown() {
// remove address book
val accountManager = AccountManager.get(context)
accountManager.removeAccountExplicitly(addressBook.addressBookAccount)
addressBook.remove()
}


Expand All @@ -87,7 +79,7 @@ class LocalAddressBookTest {
// rename address book
val newName = "New Name"
addressBook.renameAccount(newName)
assertEquals(Account(newName, LocalTestAddressBook.ACCOUNT.type), addressBook.addressBookAccount)
assertEquals(newName, addressBook.addressBookAccount.name)

// check whether contact is still here (including data rows) and not dirty
val result = addressBook.findContactById(id)
Expand Down Expand Up @@ -115,8 +107,8 @@ class LocalAddressBookTest {

// rename address book
val newName = "New Name"
addressBook.renameAccount(newName)
assertEquals(Account(newName, LocalTestAddressBook.ACCOUNT.type), addressBook.addressBookAccount)
assertTrue(addressBook.renameAccount(newName))
assertEquals(newName, addressBook.addressBookAccount.name)

// check whether group is still here and not dirty
val result = addressBook.findGroupById(id)
Expand All @@ -126,6 +118,7 @@ class LocalAddressBookTest {
assertEquals("Test Group", group.displayName)
}


companion object {

@JvmField
Expand All @@ -137,9 +130,8 @@ class LocalAddressBookTest {
@BeforeClass
@JvmStatic
fun connect() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val context = InstrumentationRegistry.getInstrumentation().context
provider = context.contentResolver.acquireContentProviderClient(ContactsContract.AUTHORITY)!!
assertNotNull(provider)
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class LocalCalendarTest {
}

@Test
// Flaky, Needs single or rec init of CalendarProvider (InitCalendarProviderRule)
// Needs InitCalendarProviderRule
fun testDeleteDirtyEventsWithoutInstances_Recurring_Instances() {
val event = Event().apply {
dtStart = DtStart("20220120T010203Z")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import android.os.Build
import android.provider.CalendarContract
import android.provider.CalendarContract.ACCOUNT_TYPE_LOCAL
import android.provider.CalendarContract.Events
import androidx.datastore.dataStore
import androidx.test.platform.app.InstrumentationRegistry
import at.bitfire.davdroid.InitCalendarProviderRule
import at.bitfire.ical4android.AndroidCalendar
Expand Down Expand Up @@ -41,29 +40,6 @@ import java.util.UUID

class LocalEventTest {

companion object {

@JvmField
@ClassRule
val initCalendarProviderRule: TestRule = InitCalendarProviderRule.getInstance()

private lateinit var provider: ContentProviderClient

@BeforeClass
@JvmStatic
fun setUpClass() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
provider = context.contentResolver.acquireContentProviderClient(CalendarContract.AUTHORITY)!!
}

@AfterClass
@JvmStatic
fun tearDownClass() {
provider.closeCompat()
}

}

private val account = Account("LocalCalendarTest", ACCOUNT_TYPE_LOCAL)
private lateinit var calendar: LocalCalendar

Expand Down Expand Up @@ -482,4 +458,28 @@ class LocalEventTest {
}
}

}

companion object {

@JvmField
@ClassRule
val initCalendarProviderRule: TestRule = InitCalendarProviderRule.getInstance()

private lateinit var provider: ContentProviderClient

@BeforeClass
@JvmStatic
fun setUpClass() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
provider = context.contentResolver.acquireContentProviderClient(CalendarContract.AUTHORITY)!!
}

@AfterClass
@JvmStatic
fun tearDownClass() {
provider.closeCompat()
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import at.bitfire.vcard4android.GroupMethod
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.After
import org.junit.AfterClass
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
Expand All @@ -37,39 +38,12 @@ import javax.inject.Inject
@HiltAndroidTest
class LocalGroupTest {

companion object {

@JvmField
@ClassRule
val permissionRule = GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)!!

private lateinit var provider: ContentProviderClient

@BeforeClass
@JvmStatic
fun connect() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
provider = context.contentResolver.acquireContentProviderClient(ContactsContract.AUTHORITY)!!
assertNotNull(provider)
}

@AfterClass
@JvmStatic
fun disconnect() {
provider.close()
}
}
@Inject @ApplicationContext
lateinit var context: Context

@get:Rule
val hiltRule = HiltAndroidRule(this)

@Inject
@ApplicationContext
lateinit var context: Context

@Inject
lateinit var addressbookFactory: LocalTestAddressBook.Factory

val account = Account("Test Account", "Test Account Type")
private lateinit var addressBookGroupsAsCategories: LocalTestAddressBook
private lateinit var addressBookGroupsAsVCards: LocalTestAddressBook
Expand All @@ -78,14 +52,20 @@ class LocalGroupTest {
fun setup() {
hiltRule.inject()

addressBookGroupsAsCategories = addressbookFactory.create(account, provider, GroupMethod.CATEGORIES)
addressBookGroupsAsVCards = addressbookFactory.create(account, provider, GroupMethod.GROUP_VCARDS)
addressBookGroupsAsCategories = LocalTestAddressBook.create(context, account, provider, GroupMethod.CATEGORIES)
addressBookGroupsAsVCards = LocalTestAddressBook.create(context, account, provider, GroupMethod.GROUP_VCARDS)

// clear contacts
addressBookGroupsAsCategories.clear()
addressBookGroupsAsVCards.clear()
}

@After
fun tearDown() {
addressBookGroupsAsCategories.remove()
addressBookGroupsAsVCards.remove()
}


@Test
fun testApplyPendingMemberships_addPendingMembership() {
Expand Down Expand Up @@ -279,4 +259,27 @@ class LocalGroupTest {
add()
}


companion object {

@JvmField
@ClassRule
val permissionRule = GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)!!

private lateinit var provider: ContentProviderClient

@BeforeClass
@JvmStatic
fun connect() {
val context = InstrumentationRegistry.getInstrumentation().context
provider = context.contentResolver.acquireContentProviderClient(ContactsContract.AUTHORITY)!!
}

@AfterClass
@JvmStatic
fun disconnect() {
provider.close()
}
}

}
Loading
Loading