Skip to content

Commit 9f0a4c0

Browse files
committed
Refactor: make test fail because of exception
1 parent ae858f6 commit 9f0a4c0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterTest.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ class UploadStarterTest : BaseUnitTest() {
234234
}
235235

236236
@Test
237-
fun `given an unexpected mutex unlock, when uploading, then all other sites are uploaded`() = test {
237+
fun `given an unexpected mutex unlock, when uploading, then all other uploads succeed`() = test {
238238
val (first, last) = createLocallyChangedPostModel() to createLocallyChangedPostModel()
239239
val (firstSite, lastSite) = createSiteModel() to createSiteModel()
240+
val page = createLocallyChangedPostModel(page = true)
240241
whenever(uploadServiceFacade.uploadPost(any(), eq(first), any())).thenAnswer {
241242
mutex.unlock()
242243
}
@@ -246,7 +247,10 @@ class UploadStarterTest : BaseUnitTest() {
246247
on { getPostsWithLocalChanges(firstSite) } doReturn listOf(first)
247248
on { getPostsWithLocalChanges(lastSite) } doReturn listOf(last)
248249
},
249-
pageStore = mock { onBlocking { getPagesWithLocalChanges(any()) } doReturn emptyList() },
250+
pageStore = mock {
251+
onBlocking { getPagesWithLocalChanges(firstSite) }.thenReturn(listOf())
252+
onBlocking { getPagesWithLocalChanges(lastSite) }.thenReturn(listOf(page))
253+
},
250254
siteStore = mock { on { sites } doReturn sites.toList() },
251255
).run {
252256
launch {
@@ -262,8 +266,9 @@ class UploadStarterTest : BaseUnitTest() {
262266
}
263267
}
264268

265-
val expectedInvocations = 1 // 1 blog * 2 sites - 1 failed upload
266-
verify(uploadServiceFacade, times(expectedInvocations)).uploadPost(any(), any<PostModel>(), any())
269+
verify(uploadServiceFacade).uploadPost(any(), eq(first), any())
270+
verify(uploadServiceFacade, never()).uploadPost(any(), eq(last), any())
271+
verify(uploadServiceFacade, never()).uploadPost(any(), eq(page), any()) // this should work without never()
267272
}
268273

269274
@Test

0 commit comments

Comments
 (0)