Skip to content

Commit d665188

Browse files
fix test
Signed-off-by: parneet-guraya <[email protected]>
1 parent acf540e commit d665188

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

app/src/main/java/fr/free/nrw/commons/actions/ThanksClient.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class ThanksClient
2525
* @param revisionId The revision ID the user would like to thank someone for
2626
* @return if thanks was successfully sent to intended recipient
2727
*/
28-
fun thank(revisionId: Long): Observable<Boolean> =
28+
fun thank(revisionId: Long, application: CommonsApplication): Observable<Boolean> =
2929
try {
3030
service
3131
.thank(
3232
revisionId.toString(), // Rev
3333
null, // Log
3434
csrfTokenClient.getTokenBlocking(), // Token
35-
CommonsApplication.instance!!.userAgent, // Source
35+
application.userAgent, // Source
3636
).map { mwThankPostResponse ->
3737
mwThankPostResponse.result?.success == 1
3838
}

app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ void sendThanks(Context context, MwQueryPage.Revision firstRevision) {
785785
}
786786

787787
Observable.defer((Callable<ObservableSource<Boolean>>) () -> thanksClient.thank(
788-
firstRevision.getRevisionId()))
788+
firstRevision.getRevisionId(), CommonsApplication.getInstance()))
789789
.subscribeOn(Schedulers.io())
790790
.observeOn(AndroidSchedulers.mainThread())
791791
.subscribe(result -> {

app/src/main/java/fr/free/nrw/commons/review/ReviewController.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ void sendThanks(@NonNull Activity activity) {
157157
return;
158158
}
159159

160-
Observable.defer((Callable<ObservableSource<Boolean>>) () -> thanksClient.thank(firstRevision.getRevisionId()))
160+
Observable.defer((Callable<ObservableSource<Boolean>>) () ->
161+
thanksClient.thank(firstRevision.getRevisionId(), CommonsApplication.getInstance()))
161162
.subscribeOn(Schedulers.io())
162163
.observeOn(AndroidSchedulers.mainThread())
163164
.subscribe(result -> {

app/src/test/kotlin/fr/free/nrw/commons/actions/ThanksClientTest.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class ThanksClientTest {
2929
private lateinit var commonsApplication: CommonsApplication
3030

3131
private lateinit var thanksClient: ThanksClient
32-
private lateinit var mockedApplication: MockedStatic<CommonsApplication>
3332

3433
/**
3534
* initial setup, test environment
@@ -38,8 +37,6 @@ class ThanksClientTest {
3837
@Throws(Exception::class)
3938
fun setUp() {
4039
MockitoAnnotations.openMocks(this)
41-
mockedApplication = Mockito.mockStatic(CommonsApplication::class.java)
42-
`when`(CommonsApplication.instance).thenReturn(commonsApplication)
4340
thanksClient = ThanksClient(csrfTokenClient, service)
4441
}
4542

@@ -50,7 +47,7 @@ class ThanksClientTest {
5047
fun testThanks() {
5148
`when`(csrfTokenClient.getTokenBlocking()).thenReturn("test")
5249
`when`(commonsApplication.userAgent).thenReturn("test")
53-
thanksClient.thank(1L)
50+
thanksClient.thank(1L, commonsApplication)
5451
verify(service).thank(ArgumentMatchers.anyString(), ArgumentMatchers.any(), eq("test"), eq("test"))
5552
}
5653
}

0 commit comments

Comments
 (0)