1
1
package fr.free.nrw.commons.delete
2
2
3
3
import android.content.Context
4
+ import com.nhaarman.mockitokotlin2.eq
5
+ import com.nhaarman.mockitokotlin2.verify
4
6
import fr.free.nrw.commons.Media
5
7
import fr.free.nrw.commons.actions.PageEditClient
6
8
import fr.free.nrw.commons.notification.NotificationHelper
@@ -14,7 +16,6 @@ import org.mockito.InjectMocks
14
16
import org.mockito.Mock
15
17
import org.mockito.Mockito.`when`
16
18
import org.mockito.MockitoAnnotations
17
- import org.wikipedia.AppAdapter
18
19
import javax.inject.Inject
19
20
import javax.inject.Named
20
21
@@ -65,9 +66,13 @@ class DeleteHelperTest {
65
66
`when `(media?.displayTitle).thenReturn(" Test file" )
66
67
media?.filename= " Test file.jpg"
67
68
69
+ val creatorName = " Creator"
70
+ `when `(media?.getCreator()).thenReturn(" $creatorName (page does not exist)" )
71
+
68
72
val makeDeletion = deleteHelper?.makeDeletion(context, media, " Test reason" )?.blockingGet()
69
73
assertNotNull(makeDeletion)
70
74
assertTrue(makeDeletion!! )
75
+ verify(pageEditClient)?.appendEdit(eq(" User_Talk:$creatorName " ), ArgumentMatchers .anyString(), ArgumentMatchers .anyString())
71
76
}
72
77
73
78
/* *
@@ -83,6 +88,7 @@ class DeleteHelperTest {
83
88
.thenReturn(Observable .just(true ))
84
89
`when `(media?.displayTitle).thenReturn(" Test file" )
85
90
`when `(media?.filename).thenReturn(" Test file.jpg" )
91
+ `when `(media?.creator).thenReturn(" Creator (page does not exist)" )
86
92
87
93
deleteHelper?.makeDeletion(context, media, " Test reason" )?.blockingGet()
88
94
}
@@ -97,6 +103,7 @@ class DeleteHelperTest {
97
103
.thenReturn(Observable .just(false ))
98
104
`when `(media?.displayTitle).thenReturn(" Test file" )
99
105
`when `(media?.filename).thenReturn(" Test file.jpg" )
106
+ `when `(media?.creator).thenReturn(" Creator (page does not exist)" )
100
107
101
108
deleteHelper?.makeDeletion(context, media, " Test reason" )?.blockingGet()
102
109
}
@@ -111,6 +118,24 @@ class DeleteHelperTest {
111
118
.thenReturn(Observable .just(true ))
112
119
`when `(media?.displayTitle).thenReturn(" Test file" )
113
120
`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 )
114
139
115
140
deleteHelper?.makeDeletion(context, media, " Test reason" )?.blockingGet()
116
141
}
0 commit comments