-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catch IllegalArgumentException in ApiOperation (#2441)
Fixes #2440
- Loading branch information
1 parent
fed08a6
commit b9c0e1e
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
stripe/src/test/java/com/stripe/android/ApiOperationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.stripe.android | ||
|
||
import com.nhaarman.mockitokotlin2.argWhere | ||
import com.nhaarman.mockitokotlin2.mock | ||
import com.nhaarman.mockitokotlin2.verify | ||
import com.stripe.android.exception.InvalidRequestException | ||
import kotlin.test.Test | ||
import kotlinx.coroutines.MainScope | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class ApiOperationTest { | ||
|
||
private val callback: ApiResultCallback<String> = mock() | ||
|
||
@Test | ||
fun getResult_whenException_shouldInvokeCallbackOnError() { | ||
FakeApiOperation(callback).execute() | ||
verify(callback).onError( | ||
argWhere { | ||
(it as? InvalidRequestException)?.message == "Illegal argument!" | ||
} | ||
) | ||
} | ||
|
||
internal class FakeApiOperation( | ||
callback: ApiResultCallback<String> | ||
) : ApiOperation<String>( | ||
workScope = MainScope(), | ||
callback = callback | ||
) { | ||
override suspend fun getResult(): String? { | ||
throw IllegalArgumentException("Illegal argument!") | ||
} | ||
} | ||
} |