Skip to content

Commit eb32b47

Browse files
committed
test(CachingContactRepositoryTest): add test coverage for getPhotoUri()
1 parent 058d244 commit eb32b47

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

core/android/common/src/test/kotlin/app/k9mail/core/android/common/contact/CachingContactRepositoryTest.kt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package app.k9mail.core.android.common.contact
22

3+
import android.net.Uri
34
import assertk.assertThat
45
import assertk.assertions.isEqualTo
56
import assertk.assertions.isFalse
@@ -140,4 +141,53 @@ internal class CachingContactRepositoryTest {
140141

141142
assertThat(cache[CONTACT_EMAIL_ADDRESS]).isNull()
142143
}
144+
145+
@Test
146+
fun `getPhotoUri() returns null when email is invalid`() {
147+
val result = testSubject.getPhotoUri("invalid-email")
148+
149+
assertThat(result).isNull()
150+
}
151+
152+
@Test
153+
fun `getPhotoUri() returns null when no contact found for valid email`() {
154+
dataSource.stub { on { getContactFor(CONTACT_EMAIL_ADDRESS) } doReturn null }
155+
156+
val result = testSubject.getPhotoUri(CONTACT_EMAIL_ADDRESS.address)
157+
158+
assertThat(result).isNull()
159+
}
160+
161+
@Test
162+
fun `getPhotoUri() returns contact photo uri when contact exists`() {
163+
dataSource.stub { on { getContactFor(CONTACT_EMAIL_ADDRESS) } doReturn CONTACT }
164+
165+
val result = testSubject.getPhotoUri(CONTACT_EMAIL_ADDRESS.address)
166+
167+
assertThat(result).isEqualTo(CONTACT.photoUri)
168+
}
169+
170+
@Test
171+
fun `getPhotoUri() returns cached photo uri when contact already cached`() {
172+
cache[CONTACT_EMAIL_ADDRESS] = CONTACT
173+
174+
val result = testSubject.getPhotoUri(CONTACT_EMAIL_ADDRESS.address)
175+
176+
assertThat(result).isEqualTo(CONTACT.photoUri)
177+
}
178+
179+
@Test
180+
fun `getPhotoUri() caches result after first fetch`() {
181+
dataSource.stub {
182+
on { getContactFor(CONTACT_EMAIL_ADDRESS) } doReturnConsecutively listOf(
183+
CONTACT,
184+
CONTACT.copy(photoUri = Uri.parse("content://other/photo")),
185+
)
186+
}
187+
188+
val result1 = testSubject.getPhotoUri(CONTACT_EMAIL_ADDRESS.address)
189+
val result2 = testSubject.getPhotoUri(CONTACT_EMAIL_ADDRESS.address)
190+
191+
assertThat(result1).isEqualTo(result2)
192+
}
143193
}

0 commit comments

Comments
 (0)