Skip to content

Commit

Permalink
Added more unit tests to UploadPresenter (commons-app#3250)
Browse files Browse the repository at this point in the history
* Added more unit tests to UploadPresenter

* added method comments
  • Loading branch information
ashishkumar468 authored and maskaravivek committed Nov 30, 2019
1 parent 3206747 commit 88bb1d8
Showing 1 changed file with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class UploadPresenterTest {
@Mock
private lateinit var uploadableFile: UploadableFile

@Mock
private lateinit var anotherUploadableFile: UploadableFile

@InjectMocks
var uploadPresenter: UploadPresenter? = null

Expand All @@ -44,7 +47,6 @@ class UploadPresenterTest {
MockitoAnnotations.initMocks(this)
uploadPresenter?.onAttachView(view)
`when`(repository?.buildContributions()).thenReturn(Observable.just(contribution))
`when`(view?.isLoggedIn).thenReturn(true)
uploadableFiles.add(uploadableFile)
`when`(view?.uploadableFiles).thenReturn(uploadableFiles)
`when`(uploadableFile?.filePath).thenReturn("data://test")
Expand All @@ -54,7 +56,8 @@ class UploadPresenterTest {
* unit test case for method UploadPresenter.handleSubmit
*/
@Test
fun handleSubmitTest() {
fun handleSubmitTestUserLoggedIn() {
`when`(view?.isLoggedIn).thenReturn(true)
uploadPresenter?.handleSubmit()
verify(view)?.isLoggedIn
verify(view)?.showProgress(true)
Expand All @@ -63,13 +66,57 @@ class UploadPresenterTest {
}

/**
* unit test for UploadMediaPresenter.deletePictureAtIndex
* unit test case for method UploadPresenter.handleSubmit
*/
@Test
fun handleSubmitTestUserNotLoggedIn() {
`when`(view?.isLoggedIn).thenReturn(false)
uploadPresenter?.handleSubmit()
verify(view)?.isLoggedIn
verify(view)?.askUserToLogIn()

}

private fun deletePictureBaseTest(){
uploadableFiles.clear()
}

/**
* Test which asserts If the next fragment to be shown is not one of the MediaDetailsFragment, lets hide the top card
*/
@Test
fun deletePictureAtIndexTest() {
fun hideTopCardWhenReachedTheLastFile(){
deletePictureBaseTest()
uploadableFiles.add(uploadableFile)
uploadPresenter?.deletePictureAtIndex(0)
verify(view)?.showHideTopCard(false)
verify(repository)?.deletePicture(ArgumentMatchers.anyString())
}

/**
* Test media deletion during single upload
*/
@Test
fun testDeleteWhenSingleUpload(){
deletePictureBaseTest()
uploadableFiles.add(uploadableFile)
uploadPresenter?.deletePictureAtIndex(0)
verify(view)?.showHideTopCard(false)
verify(repository)?.deletePicture(ArgumentMatchers.anyString())
verify(view)?.showMessage(ArgumentMatchers.anyInt())//As there is only one while which we are asking for deletion, upload should be cancelled and this flow should be triggered
verify(view)?.finish()
}

/**
* Test media deletion during multiple upload
*/
@Test
fun testDeleteWhenMultipleFilesUpload(){
deletePictureBaseTest()
uploadableFiles.add(uploadableFile)
uploadableFiles.add(anotherUploadableFile)
uploadPresenter?.deletePictureAtIndex(0)
verify(view)?.onUploadMediaDeleted(0)
verify(view)?.updateTopCardTitle()
}
}

0 comments on commit 88bb1d8

Please sign in to comment.