Add ContactFixture for test setup

This commit is contained in:
Wolf Montwé 2023-03-07 14:04:58 +01:00
parent 8b049982a9
commit 3974688b63
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
2 changed files with 20 additions and 17 deletions

View file

@ -0,0 +1,19 @@
package app.k9mail.core.android.common.contact
import android.net.Uri
import app.k9mail.core.common.mail.EmailAddress
const val CONTACT_ID = 123L
const val CONTACT_NAME = "user name"
const val CONTACT_LOOKUP_KEY = "0r1-4F314D4F2F294F29"
val CONTACT_EMAIL_ADDRESS = EmailAddress("user@example.com")
val CONTACT_URI: Uri = Uri.parse("content://com.android.contacts/contacts/lookup/$CONTACT_LOOKUP_KEY/$CONTACT_ID")
val CONTACT_PHOTO_URI: Uri = Uri.parse("content://com.android.contacts/display_photo/$CONTACT_ID")
val CONTACT = Contact(
id = CONTACT_ID,
name = CONTACT_NAME,
emailAddress = CONTACT_EMAIL_ADDRESS,
uri = CONTACT_URI,
photoUri = CONTACT_PHOTO_URI,
)

View file

@ -6,7 +6,6 @@ import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import android.provider.ContactsContract
import app.k9mail.core.common.mail.EmailAddress
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isFalse
@ -112,26 +111,11 @@ internal class ContentResolverContactDataSourceTest {
private fun setupContactCursor(): Cursor {
return MatrixCursor(PROJECTION).apply {
addRow(arrayOf(CONTACT_ID, CONTACT_NAME, CONTACT_PHOTO_URI, LOOKUP_KEY))
addRow(arrayOf(CONTACT_ID, CONTACT_NAME, CONTACT_PHOTO_URI, CONTACT_LOOKUP_KEY))
}
}
private companion object {
const val CONTACT_ID = 123L
const val CONTACT_NAME = "name"
const val LOOKUP_KEY = "0r1-4F314D4F2F294F29"
val CONTACT_EMAIL_ADDRESS = EmailAddress("user@example.com")
val CONTACT_URI: Uri = Uri.parse("content://com.android.contacts/contacts/lookup/$LOOKUP_KEY/$CONTACT_ID")
val CONTACT_PHOTO_URI: Uri = Uri.parse("content://com.android.contacts/display_photo/$CONTACT_ID")
val CONTACT = Contact(
id = CONTACT_ID,
name = CONTACT_NAME,
emailAddress = CONTACT_EMAIL_ADDRESS,
uri = CONTACT_URI,
photoUri = CONTACT_PHOTO_URI,
)
val PROJECTION = arrayOf(
ContactsContract.CommonDataKinds.Email._ID,
ContactsContract.CommonDataKinds.Identity.DISPLAY_NAME,