mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Fixes #3464, App posts deletion request notifications ({{subst:idw}}) on the wrong user's talk page (#3495)
* Fixed #3464: App posts deletion request notifications ({{subst:idw}}) on the wrong user's talk page * Fixed DeleteHelperTest.kt * Fixed DeleteHelper tests and null-pointer exception * Modified DeleteHelper makeDeletion() test * Reverted unintentionally modified Project.xml * Raising exception when nominating for deletion with empty creator name * Fixed code style * Fixed code style
This commit is contained in:
parent
cd2d530175
commit
e55b5495a1
2 changed files with 33 additions and 2 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package fr.free.nrw.commons.delete
|
||||
|
||||
import android.content.Context
|
||||
import com.nhaarman.mockitokotlin2.eq
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.actions.PageEditClient
|
||||
import fr.free.nrw.commons.notification.NotificationHelper
|
||||
|
|
@ -14,7 +16,6 @@ import org.mockito.InjectMocks
|
|||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.wikipedia.AppAdapter
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
|
|
@ -65,9 +66,13 @@ class DeleteHelperTest {
|
|||
`when`(media?.displayTitle).thenReturn("Test file")
|
||||
media?.filename="Test file.jpg"
|
||||
|
||||
val creatorName = "Creator"
|
||||
`when`(media?.getCreator()).thenReturn("$creatorName (page does not exist)")
|
||||
|
||||
val makeDeletion = deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||
assertNotNull(makeDeletion)
|
||||
assertTrue(makeDeletion!!)
|
||||
verify(pageEditClient)?.appendEdit(eq("User_Talk:$creatorName"), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,6 +88,7 @@ class DeleteHelperTest {
|
|||
.thenReturn(Observable.just(true))
|
||||
`when`(media?.displayTitle).thenReturn("Test file")
|
||||
`when`(media?.filename).thenReturn("Test file.jpg")
|
||||
`when`(media?.creator).thenReturn("Creator (page does not exist)")
|
||||
|
||||
deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||
}
|
||||
|
|
@ -97,6 +103,7 @@ class DeleteHelperTest {
|
|||
.thenReturn(Observable.just(false))
|
||||
`when`(media?.displayTitle).thenReturn("Test file")
|
||||
`when`(media?.filename).thenReturn("Test file.jpg")
|
||||
`when`(media?.creator).thenReturn("Creator (page does not exist)")
|
||||
|
||||
deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||
}
|
||||
|
|
@ -111,6 +118,24 @@ class DeleteHelperTest {
|
|||
.thenReturn(Observable.just(true))
|
||||
`when`(media?.displayTitle).thenReturn("Test file")
|
||||
`when`(media?.filename).thenReturn("Test file.jpg")
|
||||
`when`(media?.creator).thenReturn("Creator (page does not exist)")
|
||||
|
||||
deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException::class)
|
||||
fun makeDeletionForEmptyCreatorName() {
|
||||
`when`(pageEditClient?.prependEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
`when`(pageEditClient?.appendEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
`when`(pageEditClient?.edit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
|
||||
`when`(media?.displayTitle).thenReturn("Test file")
|
||||
media?.filename="Test file.jpg"
|
||||
|
||||
`when`(media?.getCreator()).thenReturn(null)
|
||||
|
||||
deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue