Skip to content

Commit

Permalink
US2012874: fix test broken by adding support to Android 15
Browse files Browse the repository at this point in the history
- mockito has been upgraded to a more recent version and that has fixed the issue
- mockito cannot be upgraded to the latest version though given that it requires kotlin 1.9
  • Loading branch information
ochalet-wp committed Aug 20, 2024
1 parent ef41f80 commit 80511e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion demo-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ dependencies {

testImplementation 'junit:junit:4.13'
testImplementation 'com.github.java-json-tools:json-schema-validator:2.2.10'
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0"
testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test:rules:1.5.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package com.worldpay.access.checkout.sample.images
import android.app.Activity
import android.content.res.Resources
import android.widget.ImageView
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.argumentCaptor
import com.nhaarman.mockitokotlin2.given
import com.worldpay.access.checkout.client.validation.model.CardBrand
import com.worldpay.access.checkout.client.validation.model.CardBrandImage
import com.worldpay.access.checkout.sample.R
Expand All @@ -21,14 +18,22 @@ import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyZeroInteractions
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.given
import org.mockito.kotlin.verifyNoInteractions

class SVGImageLoaderTest {

private val cardBrand =
CardBrand(
name = "visa",
images = listOf(CardBrandImage(type = "image/svg+xml", url = "https://localhost:8443/test.svg"))
images = listOf(
CardBrandImage(
type = "image/svg+xml",
url = "https://localhost:8443/test.svg"
)
)
)

private lateinit var activity: Activity
Expand Down Expand Up @@ -83,7 +88,7 @@ class SVGImageLoaderTest {

svgImageLoader.fetchAndApplyCardLogo(null, targetImageView)

verifyZeroInteractions(client)
verifyNoInteractions(client)

verify(targetImageView).setImageResource(R.drawable.card_unknown_logo)
verify(targetImageView).setTag(R.integer.card_tag, "card_unknown_logo")
Expand All @@ -94,7 +99,12 @@ class SVGImageLoaderTest {
val cardBrandWithNoSVG =
CardBrand(
name = "visa",
images = listOf(CardBrandImage(type = "image/png", url = "https://localhost:8443/test.png"))
images = listOf(
CardBrandImage(
type = "image/png",
url = "https://localhost:8443/test.png"
)
)
)

val mockHttpCall = mock(Call::class.java)
Expand All @@ -112,7 +122,7 @@ class SVGImageLoaderTest {

svgImageLoader.fetchAndApplyCardLogo(cardBrandWithNoSVG, targetImageView)

verifyZeroInteractions(client)
verifyNoInteractions(client)
verify(targetImageView).setImageResource(R.drawable.card_unknown_logo)
verify(targetImageView).setTag(R.integer.card_tag, "card_unknown_logo")
}
Expand All @@ -136,7 +146,7 @@ class SVGImageLoaderTest {

// Trigger onFailure callback function
captor.firstValue.onFailure(mockHttpCall, IOException("some message"))
verifyZeroInteractions(svgImageRenderer)
verifyZeroInteractions(targetImageView)
verifyNoInteractions(svgImageRenderer)
verifyNoInteractions(targetImageView)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import android.graphics.drawable.PictureDrawable
import android.view.View
import android.widget.ImageView
import com.caverock.androidsvg.SVG
import com.nhaarman.mockitokotlin2.argumentCaptor
import com.nhaarman.mockitokotlin2.verifyZeroInteractions
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.verifyNoInteractions
import com.worldpay.access.checkout.sample.R
import java.io.InputStream
import org.junit.Before
Expand Down Expand Up @@ -64,6 +64,6 @@ class SVGImageRendererImplTest {

svgImageRenderer.renderImage(mockInputStream, target, "someName")

verifyZeroInteractions(target)
verifyNoInteractions(target)
}
}

0 comments on commit 80511e9

Please sign in to comment.