11package fr.free.nrw.commons.delete
22
33import android.content.Context
4+ import com.nhaarman.mockitokotlin2.eq
5+ import com.nhaarman.mockitokotlin2.verify
46import fr.free.nrw.commons.Media
57import fr.free.nrw.commons.actions.PageEditClient
68import fr.free.nrw.commons.notification.NotificationHelper
@@ -14,7 +16,6 @@ import org.mockito.InjectMocks
1416import org.mockito.Mock
1517import org.mockito.Mockito.`when`
1618import org.mockito.MockitoAnnotations
17- import org.wikipedia.AppAdapter
1819import javax.inject.Inject
1920import javax.inject.Named
2021
@@ -65,9 +66,13 @@ class DeleteHelperTest {
6566 `when `(media?.displayTitle).thenReturn(" Test file" )
6667 media?.filename= " Test file.jpg"
6768
69+ val creatorName = " Creator"
70+ `when `(media?.getCreator()).thenReturn(" $creatorName (page does not exist)" )
71+
6872 val makeDeletion = deleteHelper?.makeDeletion(context, media, " Test reason" )?.blockingGet()
6973 assertNotNull(makeDeletion)
7074 assertTrue(makeDeletion!! )
75+ verify(pageEditClient)?.appendEdit(eq(" User_Talk:$creatorName " ), ArgumentMatchers .anyString(), ArgumentMatchers .anyString())
7176 }
7277
7378 /* *
@@ -83,6 +88,7 @@ class DeleteHelperTest {
8388 .thenReturn(Observable .just(true ))
8489 `when `(media?.displayTitle).thenReturn(" Test file" )
8590 `when `(media?.filename).thenReturn(" Test file.jpg" )
91+ `when `(media?.creator).thenReturn(" Creator (page does not exist)" )
8692
8793 deleteHelper?.makeDeletion(context, media, " Test reason" )?.blockingGet()
8894 }
@@ -97,6 +103,7 @@ class DeleteHelperTest {
97103 .thenReturn(Observable .just(false ))
98104 `when `(media?.displayTitle).thenReturn(" Test file" )
99105 `when `(media?.filename).thenReturn(" Test file.jpg" )
106+ `when `(media?.creator).thenReturn(" Creator (page does not exist)" )
100107
101108 deleteHelper?.makeDeletion(context, media, " Test reason" )?.blockingGet()
102109 }
@@ -111,6 +118,24 @@ class DeleteHelperTest {
111118 .thenReturn(Observable .just(true ))
112119 `when `(media?.displayTitle).thenReturn(" Test file" )
113120 `when `(media?.filename).thenReturn(" Test file.jpg" )
121+ `when `(media?.creator).thenReturn(" Creator (page does not exist)" )
122+
123+ deleteHelper?.makeDeletion(context, media, " Test reason" )?.blockingGet()
124+ }
125+
126+ @Test(expected = RuntimeException ::class )
127+ fun makeDeletionForEmptyCreatorName () {
128+ `when `(pageEditClient?.prependEdit(ArgumentMatchers .anyString(), ArgumentMatchers .anyString(), ArgumentMatchers .anyString()))
129+ .thenReturn(Observable .just(true ))
130+ `when `(pageEditClient?.appendEdit(ArgumentMatchers .anyString(), ArgumentMatchers .anyString(), ArgumentMatchers .anyString()))
131+ .thenReturn(Observable .just(true ))
132+ `when `(pageEditClient?.edit(ArgumentMatchers .anyString(), ArgumentMatchers .anyString(), ArgumentMatchers .anyString()))
133+ .thenReturn(Observable .just(true ))
134+
135+ `when `(media?.displayTitle).thenReturn(" Test file" )
136+ media?.filename= " Test file.jpg"
137+
138+ `when `(media?.getCreator()).thenReturn(null )
114139
115140 deleteHelper?.makeDeletion(context, media, " Test reason" )?.blockingGet()
116141 }
0 commit comments