Skip to content

Added more unit tests to UploadMediaPresenterTest #3251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void handleImageResult(Integer imageResult) {
*
* @param errorCode
*/
private void handleBadImage(Integer errorCode) {
public void handleBadImage(Integer errorCode) {
Timber.d("Handle bad picture with error code %d", errorCode);
if (errorCode
>= 8) { // If location of image and nearby does not match, then set shared preferences to disable wikidata edits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.reactivex.schedulers.TestScheduler
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.verify
Expand All @@ -38,6 +39,12 @@ class UploadMediaPresenterTest {
@Mock
private var uploadItem: UploadModel.UploadItem? = null

@Mock
private var title: Title? = null

@Mock
private var descriptions: List<Description>? = null

private var testObservableUploadItem: Observable<UploadModel.UploadItem>? = null
private var testSingleImageResult: Single<Int>? = null

Expand Down Expand Up @@ -107,4 +114,75 @@ class UploadMediaPresenterTest {

}

/**
* Test fetch previous image title when there was one
*/
@Test
fun fetchPreviousImageAndTitleTestPositive(){
Mockito.`when`(repository?.getPreviousUploadItem(ArgumentMatchers.anyInt())).thenReturn(uploadItem)
Mockito.`when`(uploadItem?.descriptions).thenReturn(descriptions)
Mockito.`when`(uploadItem?.title).thenReturn(title)
Mockito.`when`(title?.titleText).thenReturn(ArgumentMatchers.anyString())

uploadMediaPresenter?.fetchPreviousTitleAndDescription(0)
verify(view)?.setTitleAndDescription(ArgumentMatchers.anyString(),ArgumentMatchers.any())
}

/**
* Test fetch previous image title when there was none
*/
@Test
fun fetchPreviousImageAndTitleTestNegative(){
Mockito.`when`(repository?.getPreviousUploadItem(ArgumentMatchers.anyInt())).thenReturn(null)
uploadMediaPresenter?.fetchPreviousTitleAndDescription(0)
verify(view)?.showMessage(ArgumentMatchers.anyInt(),ArgumentMatchers.anyInt())
}

/**
* Test bad image invalid location
*/
@Test
fun handleBadImageBaseTestInvalidLocation(){
uploadMediaPresenter?.handleBadImage(8)
verify(repository)?.saveValue(ArgumentMatchers.anyString(),eq(false))
verify(view)?.showBadImagePopup(8)
}

/**
* Test bad image empty title
*/
@Test
fun handleBadImageBaseTestEmptyTitle(){
uploadMediaPresenter?.handleBadImage(-3)
verify(view)?.showMessage(ArgumentMatchers.anyInt(),ArgumentMatchers.anyInt())
}

/**
* Teste show file already exists
*/
@Test
fun handleBadImageBaseTestFileNameExists(){
uploadMediaPresenter?.handleBadImage(-4)
verify(view)?.showDuplicatePicturePopup()
}


/**
* Test show SimilarImageFragment
*/
@Test
fun showSimilarImageFragmentTest(){
uploadMediaPresenter?.showSimilarImageFragment(ArgumentMatchers.anyString(),ArgumentMatchers.anyString())
verify(view)?.showSimilarImageFragment(ArgumentMatchers.anyString(),ArgumentMatchers.anyString())
}

/**
* Test set upload item
*/
@Test
fun setUploadItemTest(){
uploadMediaPresenter?.setUploadItem(0,uploadItem)
verify(repository)?.updateUploadItem(0,uploadItem)
}

}