|
1 | 1 | package app.k9mail.core.android.common.contact |
2 | 2 |
|
| 3 | +import android.net.Uri |
3 | 4 | import assertk.assertThat |
4 | 5 | import assertk.assertions.isEqualTo |
5 | 6 | import assertk.assertions.isFalse |
@@ -140,4 +141,53 @@ internal class CachingContactRepositoryTest { |
140 | 141 |
|
141 | 142 | assertThat(cache[CONTACT_EMAIL_ADDRESS]).isNull() |
142 | 143 | } |
| 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 | + } |
143 | 193 | } |
0 commit comments