Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: parneet-guraya <[email protected]>
  • Loading branch information
parneet-guraya committed Oct 23, 2024
1 parent e328efa commit b22ffe4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/fr/free/nrw/commons/actions/ThanksClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class ThanksClient
* @param revisionId The revision ID the user would like to thank someone for
* @return if thanks was successfully sent to intended recipient
*/
fun thank(revisionId: Long): Observable<Boolean> =
fun thank(revisionId: Long, application: CommonsApplication): Observable<Boolean> =
try {
service
.thank(
revisionId.toString(), // Rev
null, // Log
csrfTokenClient.getTokenBlocking(), // Token
CommonsApplication.instance!!.userAgent, // Source
application.userAgent, // Source
).map { mwThankPostResponse ->
mwThankPostResponse.result?.success == 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ void sendThanks(Context context, MwQueryPage.Revision firstRevision) {
}

Observable.defer((Callable<ObservableSource<Boolean>>) () -> thanksClient.thank(
firstRevision.getRevisionId()))
firstRevision.getRevisionId(), CommonsApplication.getInstance()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ void sendThanks(@NonNull Activity activity) {
return;
}

Observable.defer((Callable<ObservableSource<Boolean>>) () -> thanksClient.thank(firstRevision.getRevisionId()))
Observable.defer((Callable<ObservableSource<Boolean>>) () ->
thanksClient.thank(firstRevision.getRevisionId(), CommonsApplication.getInstance()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ThanksClientTest {
private lateinit var commonsApplication: CommonsApplication

private lateinit var thanksClient: ThanksClient
private lateinit var mockedApplication: MockedStatic<CommonsApplication>

/**
* initial setup, test environment
Expand All @@ -38,8 +37,6 @@ class ThanksClientTest {
@Throws(Exception::class)
fun setUp() {
MockitoAnnotations.openMocks(this)
mockedApplication = Mockito.mockStatic(CommonsApplication::class.java)
`when`(CommonsApplication.instance).thenReturn(commonsApplication)
thanksClient = ThanksClient(csrfTokenClient, service)
}

Expand All @@ -50,7 +47,7 @@ class ThanksClientTest {
fun testThanks() {
`when`(csrfTokenClient.getTokenBlocking()).thenReturn("test")
`when`(commonsApplication.userAgent).thenReturn("test")
thanksClient.thank(1L)
thanksClient.thank(1L, commonsApplication)
verify(service).thank(ArgumentMatchers.anyString(), ArgumentMatchers.any(), eq("test"), eq("test"))
}
}

0 comments on commit b22ffe4

Please sign in to comment.