Skip to content

Commit

Permalink
fix CardDetectTest and SSDOcrTest TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Guardiola committed Nov 29, 2023
1 parent 53c989a commit 65bcf3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 50 deletions.
Expand Up @@ -9,26 +9,21 @@ import com.stripe.android.camera.framework.image.size
import com.stripe.android.camera.framework.util.toRect
import com.stripe.android.stripecardscan.framework.ResourceFetcher
import com.stripe.android.stripecardscan.test.R
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

@OptIn(ExperimentalCoroutinesApi::class)
class CardDetectTest {
private val appContext = InstrumentationRegistry.getInstrumentation().targetContext
private val testContext = InstrumentationRegistry.getInstrumentation().context

/**
* TODO: this method should use runBlockingTest instead of runBlocking. However, an issue with
* runBlockingTest currently fails when functions under test use withContext(Dispatchers.IO) or
* withContext(Dispatchers.Default).
*
* See https://github.com/Kotlin/kotlinx.coroutines/issues/1204 for details.
*/
@Test
@MediumTest
fun cardDetect_pan() = runBlocking {
fun cardDetect_pan() = runTest {
val bitmap = testContext.resources.getDrawable(R.drawable.card_pan, null)
.toBitmap()
.scale(Size(224, 224))
Expand All @@ -52,19 +47,13 @@ class CardDetectTest {
Unit
)
assertNotNull(prediction)

assertEquals(CardDetect.Prediction.Side.PAN, prediction.side)
}

/**
* TODO: this method should use runBlockingTest instead of runBlocking. However, an issue with
* runBlockingTest currently fails when functions under test use withContext(Dispatchers.IO) or
* withContext(Dispatchers.Default).
*
* See https://github.com/Kotlin/kotlinx.coroutines/issues/1204 for details.
*/
@Test
@MediumTest
fun cardDetect_noPan() = runBlocking {
fun cardDetect_noPan() = runTest {
val bitmap = testContext.resources.getDrawable(R.drawable.card_no_pan, null)
.toBitmap()
.scale(Size(224, 224))
Expand All @@ -88,19 +77,13 @@ class CardDetectTest {
Unit
)
assertNotNull(prediction)

assertEquals(CardDetect.Prediction.Side.NO_PAN, prediction.side)
}

/**
* TODO: this method should use runBlockingTest instead of runBlocking. However, an issue with
* runBlockingTest currently fails when functions under test use withContext(Dispatchers.IO) or
* withContext(Dispatchers.Default).
*
* See https://github.com/Kotlin/kotlinx.coroutines/issues/1204 for details.
*/
@Test
@MediumTest
fun cardDetect_noCard() = runBlocking {
fun cardDetect_noCard() = runTest {
val bitmap = testContext.resources.getDrawable(R.drawable.card_no_card, null)
.toBitmap()
.scale(Size(224, 224))
Expand All @@ -124,6 +107,7 @@ class CardDetectTest {
Unit
)
assertNotNull(prediction)

assertEquals(CardDetect.Prediction.Side.NO_CARD, prediction.side)
}
}
Expand Up @@ -9,26 +9,21 @@ import com.stripe.android.camera.framework.image.size
import com.stripe.android.camera.framework.util.toRect
import com.stripe.android.stripecardscan.framework.ResourceFetcher
import com.stripe.android.stripecardscan.test.R
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

@OptIn(ExperimentalCoroutinesApi::class)
class SSDOcrTest {
private val appContext = InstrumentationRegistry.getInstrumentation().targetContext
private val testContext = InstrumentationRegistry.getInstrumentation().context

/**
* TODO: this method should use runBlockingTest instead of runBlocking. However, an issue with
* runBlockingTest currently fails when functions under test use withContext(Dispatchers.IO) or
* withContext(Dispatchers.Default).
*
* See https://github.com/Kotlin/kotlinx.coroutines/issues/1204 for details.
*/
@Test
@MediumTest
fun resourceModelExecution_works() = runBlocking {
fun resourceModelExecution_works() = runTest {
val bitmap = testContext.resources.getDrawable(R.drawable.ocr_card_numbers, null)
.toBitmap()
.scale(Size(600, 375))
Expand Down Expand Up @@ -56,16 +51,9 @@ class SSDOcrTest {
assertEquals("4242424242424242", prediction.pan)
}

/**
* TODO: this method should use runBlockingTest instead of runBlocking. However, an issue with
* runBlockingTest currently fails when functions under test use withContext(Dispatchers.IO) or
* withContext(Dispatchers.Default).
*
* See https://github.com/Kotlin/kotlinx.coroutines/issues/1204 for details.
*/
@Test
@MediumTest
fun resourceModelExecution_worksWithQR() = runBlocking {
fun resourceModelExecution_worksWithQR() = runTest {
val bitmap = testContext.resources.getDrawable(R.drawable.ocr_card_numbers_qr, null)
.toBitmap()
.scale(Size(600, 375))
Expand Down Expand Up @@ -93,16 +81,9 @@ class SSDOcrTest {
assertEquals("4242424242424242", prediction.pan)
}

/**
* TODO: this method should use runBlockingTest instead of runBlocking. However, an issue with
* runBlockingTest currently fails when functions under test use withContext(Dispatchers.IO) or
* withContext(Dispatchers.Default).
*
* See https://github.com/Kotlin/kotlinx.coroutines/issues/1204 for details.
*/
@Test
@MediumTest
fun resourceModelExecution_worksRepeatedly() = runBlocking {
fun resourceModelExecution_worksRepeatedly() = runTest {
val bitmap = testContext.resources.getDrawable(R.drawable.ocr_card_numbers, null)
.toBitmap()
.scale(Size(600, 375))
Expand Down

0 comments on commit 65bcf3f

Please sign in to comment.