mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Added more unit tests to UploadMediaPresenterTest (#3251)
This commit is contained in:
parent
88bb1d87ca
commit
36e0f766c9
2 changed files with 79 additions and 1 deletions
|
|
@ -160,7 +160,7 @@ public class UploadMediaPresenter implements UserActionListener, SimilarImageInt
|
|||
*
|
||||
* @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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue