diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 249cdd184..4f8d566f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,10 +81,6 @@ jobs: fail-fast: false matrix: include: - - api: '29' - abi: 'x86' - tag: 'google_apis' - - api: '30' abi: 'x86' tag: 'playstore' # Explicitly need the PlayStore to fetch GAID @@ -98,6 +94,10 @@ jobs: - api: '33' abi: 'x86_64' tag: 'google_apis' + + - api: '34' + abi: 'x86_64' + tag: 'google_apis' steps: - name: Checkout (latest) uses: actions/checkout@v3 @@ -167,7 +167,7 @@ jobs: - name: Upload XML reports for quality-tests uses: actions/upload-artifact@v3 - if: matrix.api == '33' # Only report latest supported version + if: matrix.api == '34' # Only report latest supported version with: name: android-quality-reports path: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d922a4b1..c8b582b84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Next Version +- Add support of Android 14 (API level 34) # Version 5.0.2 - Send SDK MRAID capability diff --git a/build.gradle.kts b/build.gradle.kts index f844b7371..c92443085 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -28,6 +28,7 @@ buildscript { plugins { id("org.sonarqube") version "3.0" id("io.github.gradle-nexus.publish-plugin") + id("com.github.ben-manes.versions") version "0.50.0" } allprojects { diff --git a/buildSrc/src/main/java/AndroidModule.kt b/buildSrc/src/main/java/AndroidModule.kt index 048295427..15488dc6e 100644 --- a/buildSrc/src/main/java/AndroidModule.kt +++ b/buildSrc/src/main/java/AndroidModule.kt @@ -94,11 +94,11 @@ fun Project.androidLibModule(configure: AndroidModule.() -> Unit = {}) { private fun Project.defaultAndroidModule() { androidBase { - compileSdkVersion(33) + compileSdkVersion(34) defaultConfig { minSdkVersion(19) - targetSdkVersion(33) + targetSdkVersion(34) versionCode = 1 versionName = sdkVersion() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/buildSrc/src/main/java/Deps.kt b/buildSrc/src/main/java/Deps.kt index 9cee06f33..4fb5cdd6f 100644 --- a/buildSrc/src/main/java/Deps.kt +++ b/buildSrc/src/main/java/Deps.kt @@ -117,11 +117,11 @@ object Deps { } object Mockito { - private const val version = "3.9.0" + private const val version = "5.8.0" const val Android = "org.mockito:mockito-android:$version" const val Core = "org.mockito:mockito-core:$version" - const val Kotlin = "org.mockito.kotlin:mockito-kotlin:3.2.0" + const val Kotlin = "org.mockito.kotlin:mockito-kotlin:4.0.0" } object Square { diff --git a/publisher-sdk/src/androidTest/java/com/criteo/publisher/util/ExternalVideoPlayerTest.kt b/publisher-sdk/src/androidTest/java/com/criteo/publisher/util/ExternalVideoPlayerTest.kt index 99ca85d35..d9a46e1ae 100644 --- a/publisher-sdk/src/androidTest/java/com/criteo/publisher/util/ExternalVideoPlayerTest.kt +++ b/publisher-sdk/src/androidTest/java/com/criteo/publisher/util/ExternalVideoPlayerTest.kt @@ -33,7 +33,7 @@ import org.mockito.kotlin.argumentCaptor import org.mockito.kotlin.mock import org.mockito.kotlin.never import org.mockito.kotlin.verify -import org.mockito.kotlin.verifyZeroInteractions +import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever class ExternalVideoPlayerTest { @@ -86,7 +86,7 @@ class ExternalVideoPlayerTest { externalVideoPlayer.play("https://criteo.com/cat_video.mp4", onErrorListener) - verifyZeroInteractions(onErrorListener) + verifyNoInteractions(onErrorListener) val argumentCaptor = argumentCaptor() verify(context).startActivity(argumentCaptor.capture()) val intent = argumentCaptor.lastValue diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/CriteoBannerAdWebViewTest.java b/publisher-sdk/src/test/java/com/criteo/publisher/CriteoBannerAdWebViewTest.java index 3e1fa8f53..f69a717c6 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/CriteoBannerAdWebViewTest.java +++ b/publisher-sdk/src/test/java/com/criteo/publisher/CriteoBannerAdWebViewTest.java @@ -116,8 +116,6 @@ public void setUp() throws Exception { @Test public void loadAdStandalone_GivenNoContext_UseEmptyContext() throws Exception { - bannerView = spy(bannerView); - bannerView.loadAd(); verify(bannerView).loadAd(eq(new ContextData())); diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/CriteoInterstitialTest.java b/publisher-sdk/src/test/java/com/criteo/publisher/CriteoInterstitialTest.java index d2300ca6a..40939f25f 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/CriteoInterstitialTest.java +++ b/publisher-sdk/src/test/java/com/criteo/publisher/CriteoInterstitialTest.java @@ -70,8 +70,6 @@ public void setUp() throws Exception { @Test public void loadAdStandalone_GivenNoContext_LoadAdWithEmptyContext() throws Exception { - interstitial = spy(interstitial); - interstitial.loadAd(); verify(interstitial).loadAd(eq(new ContextData())); diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/AdChoiceOverlayNativeRendererTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/AdChoiceOverlayNativeRendererTest.kt index 4debf9ff3..45892b9b0 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/AdChoiceOverlayNativeRendererTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/AdChoiceOverlayNativeRendererTest.kt @@ -34,7 +34,7 @@ import org.mockito.junit.MockitoJUnit import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.verify -import org.mockito.kotlin.verifyZeroInteractions +import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever class AdChoiceOverlayNativeRendererTest { @@ -118,6 +118,6 @@ class AdChoiceOverlayNativeRendererTest { renderer.renderNativeView(helper, nativeView, nativeAd) - verifyZeroInteractions(delegate) + verifyNoInteractions(delegate) } } diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/ClickHelperTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/ClickHelperTest.kt index 0b2293e53..1803d604e 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/ClickHelperTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/ClickHelperTest.kt @@ -32,7 +32,7 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.spy import org.mockito.kotlin.stub import org.mockito.kotlin.verify -import org.mockito.kotlin.verifyZeroInteractions +import org.mockito.kotlin.verifyNoInteractions import java.net.URI class ClickHelperTest { @@ -61,7 +61,7 @@ class ClickHelperTest { fun notifyUserClick_GivenNull_DoNothing() { clickHelper.notifyUserClickAsync(null) - verifyZeroInteractions(runOnUiThreadExecutor) + verifyNoInteractions(runOnUiThreadExecutor) } @Test @@ -78,7 +78,7 @@ class ClickHelperTest { fun notifyUserIsLeavingApplication_GivenNull_DoNothing() { clickHelper.notifyUserIsLeavingApplicationAsync(null) - verifyZeroInteractions(runOnUiThreadExecutor) + verifyNoInteractions(runOnUiThreadExecutor) } @Test @@ -95,7 +95,7 @@ class ClickHelperTest { fun notifyUserIsBackToApplication_GivenNull_DoNothing() { clickHelper.notifyUserIsBackToApplicationAsync(null) - verifyZeroInteractions(runOnUiThreadExecutor) + verifyNoInteractions(runOnUiThreadExecutor) } @Test diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/CriteoImageLoaderTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/CriteoImageLoaderTest.kt index 65dff53d7..a9f9dc8c2 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/CriteoImageLoaderTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/CriteoImageLoaderTest.kt @@ -23,6 +23,7 @@ import com.squareup.picasso.Picasso import com.squareup.picasso.RequestCreator import org.junit.Rule import org.junit.Test +import org.mockito.Answers import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.Mockito.verify @@ -41,7 +42,7 @@ class CriteoImageLoaderTest { @Mock private lateinit var picasso: Picasso - @Mock + @Mock(answer = Answers.CALLS_REAL_METHODS) @Suppress("UnusedPrivateMember") private lateinit var asyncResources: AsyncResources diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/ImpressionTaskTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/ImpressionTaskTest.kt index 56b244889..f633e10a8 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/ImpressionTaskTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/ImpressionTaskTest.kt @@ -17,7 +17,6 @@ package com.criteo.publisher.advancednative import org.assertj.core.api.Assertions.assertThatCode -import org.junit.Before import org.junit.Rule import org.junit.Test import org.mockito.Mock @@ -28,8 +27,7 @@ import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.mock import org.mockito.kotlin.times import org.mockito.kotlin.verify -import org.mockito.kotlin.whenever -import java.lang.ref.Reference +import java.lang.ref.WeakReference import java.net.URL class ImpressionTaskTest { @@ -41,21 +39,15 @@ class ImpressionTaskTest { @Mock private lateinit var impressionPixels: Iterable - @Mock - private lateinit var listenerRef: Reference - @Mock private lateinit var helper: ImpressionHelper private lateinit var task: ImpressionTask - @Before - fun setUp() { - task = ImpressionTask(impressionPixels, listenerRef, helper) - } - @Test fun onVisible_GivenPixels_DelegateToHelper() { + createImpressionTaskWithListener() + task.onVisible() verify(helper).firePixels(impressionPixels) @@ -63,7 +55,7 @@ class ImpressionTaskTest { @Test fun onVisible_GivenEmptyListenerRef_DoesNotThrowAndDoNotDelegateToHelper() { - whenever(listenerRef.get()).thenReturn(null) + createImpressionTaskWithListener() assertThatCode { task.onVisible() @@ -75,7 +67,7 @@ class ImpressionTaskTest { @Test fun onVisible_GivenNotEmptyListenerRef_DelegateToHelper() { val listener = mock() - whenever(listenerRef.get()).thenReturn(listener) + createImpressionTaskWithListener(listener) task.onVisible() @@ -84,7 +76,8 @@ class ImpressionTaskTest { @Test fun onVisible_CalledTwice_WorkOnlyOnce() { - whenever(listenerRef.get()).thenReturn(mock()) + val listener = mock() + createImpressionTaskWithListener(listener) task.onVisible() task.onVisible() @@ -92,4 +85,8 @@ class ImpressionTaskTest { verify(helper, times(1)).firePixels(any()) verify(helper, times(1)).notifyImpression(any()) } + + private fun createImpressionTaskWithListener(listener: CriteoNativeAdListener? = null) { + task = ImpressionTask(impressionPixels, WeakReference(listener), helper) + } } diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/VisibilityTrackingTaskTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/VisibilityTrackingTaskTest.kt index 11938977a..ad7cb83ee 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/VisibilityTrackingTaskTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/advancednative/VisibilityTrackingTaskTest.kt @@ -37,7 +37,7 @@ import org.mockito.kotlin.doReturn import org.mockito.kotlin.eq import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -import java.lang.ref.Reference +import java.lang.ref.WeakReference class VisibilityTrackingTaskTest { @@ -45,26 +45,23 @@ class VisibilityTrackingTaskTest { @JvmField val mockitoRule = MockitoJUnit.rule() - @Mock - private lateinit var viewRef: Reference - @Mock private lateinit var visibilityChecker: VisibilityChecker + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private lateinit var view: View + private lateinit var runOnUiThreadExecutor: RunOnUiThreadExecutor @Before fun setUp() { - whenever(viewRef.get()).thenReturn(mock(defaultAnswer = Answers.RETURNS_DEEP_STUBS)) runOnUiThreadExecutor = spy(DirectMockRunOnUiThreadExecutor()) } @Test fun new_GivenEmptyReference_DoNotThrow() { - whenever(viewRef.get()).thenReturn(null) - assertThatCode { - createTask() + createTask(null) }.doesNotThrowAnyException() } @@ -90,8 +87,7 @@ class VisibilityTrackingTaskTest { fun onPreDraw_GivenListenerAndEmptyReference_DoesNothing() { val listener = mock(VisibilityListener::class.java) - val task = createTask() - whenever(viewRef.get()).thenReturn(null) + val task = createTask(null) task.onPreDraw() @@ -101,7 +97,7 @@ class VisibilityTrackingTaskTest { @Test fun onPreDraw_GivenListenerAndReferenceAndIsVisible_NotifyListener() { val listener = mock() - whenever(visibilityChecker.isVisible(viewRef.get()!!)).thenReturn(true) + whenever(visibilityChecker.isVisible(view)).thenReturn(true) val task = createTask() task.setListener(listener) @@ -113,7 +109,7 @@ class VisibilityTrackingTaskTest { @Test fun onGlobalLayout_GivenListenerAndReferenceAndIsGone_NotifyListener() { val listener = mock() - whenever(visibilityChecker.isVisible(viewRef.get()!!)).thenReturn(false) + whenever(visibilityChecker.isVisible(view)).thenReturn(false) val task = createTask() task.setListener(listener) @@ -125,7 +121,7 @@ class VisibilityTrackingTaskTest { @Test fun onPreDraw_GivenListenerAndReferenceAndIsGone_CancelAndAndExecuteAndExecuteAsyncWithDelay() { val listener = mock() - whenever(visibilityChecker.isVisible(viewRef.get()!!)).thenReturn(false) + whenever(visibilityChecker.isVisible(view)).thenReturn(false) givenViewTreeObserver(true) val task = createTask() @@ -155,11 +151,11 @@ class VisibilityTrackingTaskTest { on { isAlive() } doReturn isAlive } - whenever(viewRef.get()!!.viewTreeObserver).thenReturn(viewTreeObserver) + whenever(view.viewTreeObserver).thenReturn(viewTreeObserver) return viewTreeObserver } - private fun createTask(): VisibilityTrackingTask { - return VisibilityTrackingTask(viewRef, visibilityChecker, runOnUiThreadExecutor) + private fun createTask(view: View? = this.view): VisibilityTrackingTask { + return VisibilityTrackingTask(WeakReference(view), visibilityChecker, runOnUiThreadExecutor) } } diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/adview/CriteoMraidControllerTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/adview/CriteoMraidControllerTest.kt index e6dd6c01a..bec12636b 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/adview/CriteoMraidControllerTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/adview/CriteoMraidControllerTest.kt @@ -44,7 +44,7 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.never import org.mockito.kotlin.times import org.mockito.kotlin.verify -import org.mockito.kotlin.verifyZeroInteractions +import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever import java.io.IOException import javax.inject.Inject @@ -348,8 +348,8 @@ class CriteoMraidControllerTest { fun onPageFinishedGivenNonMraidAd_ShouldNotInitializeDefaultValues() { givenNonMraidAdAndPageIsFinished() - verifyZeroInteractions(visibilityTracker) - verifyZeroInteractions(mraidInteractor) + verifyNoInteractions(visibilityTracker) + verifyNoInteractions(mraidInteractor) } @Test @@ -367,7 +367,7 @@ class CriteoMraidControllerTest { criteoMraidController.onOpenFailed() - verifyZeroInteractions(mraidInteractor) + verifyNoInteractions(mraidInteractor) } @Test @@ -437,7 +437,7 @@ class CriteoMraidControllerTest { criteoMraidController.onConfigurationChange(configuration) }.doesNotThrowAnyException() - verifyZeroInteractions(mraidInteractor) + verifyNoInteractions(mraidInteractor) } @Test @@ -464,7 +464,7 @@ class CriteoMraidControllerTest { criteoMraidController.onConfigurationChange(null) }.doesNotThrowAnyException() - verifyZeroInteractions(mraidInteractor) + verifyNoInteractions(mraidInteractor) } @Test @@ -508,7 +508,7 @@ class CriteoMraidControllerTest { criteoMraidController.onClosed() }.doesNotThrowAnyException() - verifyZeroInteractions(mraidInteractor) + verifyNoInteractions(mraidInteractor) assertThat(criteoMraidController.currentState).isEqualTo(MraidState.LOADING) } @@ -524,7 +524,7 @@ class CriteoMraidControllerTest { criteoMraidController.onPlayVideo("https://criteo.com/cat_video.mp4") verify(externalVideoPlayer).play(eq("https://criteo.com/cat_video.mp4"), any()) - verifyZeroInteractions(mraidInteractor) + verifyNoInteractions(mraidInteractor) } @Test diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/adview/MraidExpandBannerMediatorTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/adview/MraidExpandBannerMediatorTest.kt index 655934a53..0ea9da6e0 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/adview/MraidExpandBannerMediatorTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/adview/MraidExpandBannerMediatorTest.kt @@ -26,7 +26,7 @@ import org.mockito.Mock import org.mockito.junit.MockitoJUnit import org.mockito.kotlin.mock import org.mockito.kotlin.verify -import org.mockito.kotlin.verifyZeroInteractions +import org.mockito.kotlin.verifyNoInteractions class MraidExpandBannerMediatorTest { @@ -129,7 +129,7 @@ class MraidExpandBannerMediatorTest { mediator.requestClose() mediator.requestOrientationChange(true, MraidOrientation.PORTRAIT) - verifyZeroInteractions(bannerListener) + verifyNoInteractions(bannerListener) } @Test @@ -155,6 +155,6 @@ class MraidExpandBannerMediatorTest { mediator.removeExpandedActivityListener() mediator.notifyOnBackClicked() - verifyZeroInteractions(expandedActivityListener) + verifyNoInteractions(expandedActivityListener) } } diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/csm/CsmBidLifecycleListenerTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/csm/CsmBidLifecycleListenerTest.kt index 4c8e275be..96b4e91e5 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/csm/CsmBidLifecycleListenerTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/csm/CsmBidLifecycleListenerTest.kt @@ -42,8 +42,8 @@ import org.mockito.kotlin.never import org.mockito.kotlin.stub import org.mockito.kotlin.times import org.mockito.kotlin.verify +import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.verifyNoMoreInteractions -import org.mockito.kotlin.verifyZeroInteractions import org.mockito.kotlin.whenever import java.io.IOException import java.io.InterruptedIOException @@ -385,7 +385,7 @@ class CsmBidLifecycleListenerTest { listener.onBidConsumed(adUnit, slot) - verifyZeroInteractions(repository) + verifyNoInteractions(repository) } @Test @@ -523,8 +523,8 @@ class CsmBidLifecycleListenerTest { } private fun verifyFeatureIsDeactivated() { - verifyZeroInteractions(repository) - verifyZeroInteractions(clock) - verifyZeroInteractions(sendingQueueProducer) + verifyNoInteractions(repository) + verifyNoInteractions(clock) + verifyNoInteractions(sendingQueueProducer) } } diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/csm/MetricSendingQueueConsumerTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/csm/MetricSendingQueueConsumerTest.kt index 7cd7014d6..0b9e69671 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/csm/MetricSendingQueueConsumerTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/csm/MetricSendingQueueConsumerTest.kt @@ -37,8 +37,8 @@ import org.mockito.kotlin.doThrow import org.mockito.kotlin.never import org.mockito.kotlin.stub import org.mockito.kotlin.verify +import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.verifyNoMoreInteractions -import org.mockito.kotlin.verifyZeroInteractions import org.mockito.kotlin.whenever import java.io.IOException @@ -91,8 +91,8 @@ class MetricSendingQueueConsumerTest { consumer.sendMetricBatch() - verifyZeroInteractions(queue) - verifyZeroInteractions(api) + verifyNoInteractions(queue) + verifyNoInteractions(api) } @Test @@ -106,8 +106,8 @@ class MetricSendingQueueConsumerTest { consumer.sendMetricBatch() - verifyZeroInteractions(queue) - verifyZeroInteractions(api) + verifyNoInteractions(queue) + verifyNoInteractions(api) } @Test diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/csm/TapeSendingQueueTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/csm/TapeSendingQueueTest.kt index 516a5e05f..607948743 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/csm/TapeSendingQueueTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/csm/TapeSendingQueueTest.kt @@ -47,7 +47,7 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.spy import org.mockito.kotlin.stub import org.mockito.kotlin.verify -import org.mockito.kotlin.verifyZeroInteractions +import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever import org.mockito.stubbing.Answer import java.io.File @@ -194,7 +194,7 @@ class TapeSendingQueueTest(private val tapeImplementation: TapeImplementation) { val metrics = queue.poll(0) assertThat(metrics).isEmpty() - verifyZeroInteractions(tapeQueue) + verifyNoInteractions(tapeQueue) } @Test diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/DfpHeaderBiddingNoDfpTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/DfpHeaderBiddingNoDfpTest.kt index 38375cf92..15a742c49 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/DfpHeaderBiddingNoDfpTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/DfpHeaderBiddingNoDfpTest.kt @@ -22,7 +22,7 @@ import org.assertj.core.api.Assertions.assertThatCode import org.junit.Before import org.junit.Test import org.mockito.kotlin.mock -import org.mockito.kotlin.verifyZeroInteractions +import org.mockito.kotlin.verifyNoInteractions class DfpHeaderBiddingNoDfpTest { @@ -60,6 +60,6 @@ via IntelliJ delegating test run to Gradle. headerBidding.enrichBid(builder, AdUnitType.CRITEO_BANNER, mock()) - verifyZeroInteractions(builder) + verifyNoInteractions(builder) } } diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/HeaderBiddingTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/HeaderBiddingTest.kt index 8701e9b27..9872b83f4 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/HeaderBiddingTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/HeaderBiddingTest.kt @@ -31,8 +31,8 @@ import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.never import org.mockito.kotlin.verify +import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.verifyNoMoreInteractions -import org.mockito.kotlin.verifyZeroInteractions class HeaderBiddingTest { @@ -51,9 +51,9 @@ class HeaderBiddingTest { headerBidding.enrichBid(null, bid) - verifyZeroInteractions(bid) - verifyZeroInteractions(handler) - verifyZeroInteractions(integrationRegistry) + verifyNoInteractions(bid) + verifyNoInteractions(handler) + verifyNoInteractions(integrationRegistry) } @Test diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/OtherAdServersHeaderBiddingTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/OtherAdServersHeaderBiddingTest.kt index 13767e85b..8eaf1f611 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/OtherAdServersHeaderBiddingTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/headerbidding/OtherAdServersHeaderBiddingTest.kt @@ -24,7 +24,7 @@ import org.assertj.core.api.Assertions.assertThat import org.junit.Test import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -import org.mockito.kotlin.verifyZeroInteractions +import org.mockito.kotlin.verifyNoInteractions class OtherAdServersHeaderBiddingTest { @@ -65,7 +65,7 @@ class OtherAdServersHeaderBiddingTest { headerBidding.cleanPreviousBid(builder) - verifyZeroInteractions(builder) + verifyNoInteractions(builder) } @Test @@ -96,7 +96,7 @@ class OtherAdServersHeaderBiddingTest { headerBidding.enrichBid(builder, CRITEO_BANNER, mock()) - verifyZeroInteractions(builder) + verifyNoInteractions(builder) } @Test diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/logging/RemoteHandlerTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/logging/RemoteHandlerTest.kt index 68dae554b..b2fa601f3 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/logging/RemoteHandlerTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/logging/RemoteHandlerTest.kt @@ -35,8 +35,8 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.spy import org.mockito.kotlin.times import org.mockito.kotlin.verify +import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.verifyNoMoreInteractions -import org.mockito.kotlin.verifyZeroInteractions import org.mockito.kotlin.whenever import javax.inject.Inject @@ -98,7 +98,7 @@ class RemoteHandlerTest { remoteHandler.log("tag", logMessage) mockedDependenciesRule.waitForIdleState() - verifyZeroInteractions(sendingQueue) + verifyNoInteractions(sendingQueue) } @Test @@ -122,8 +122,8 @@ class RemoteHandlerTest { remoteHandler.log("tag", logMessage) mockedDependenciesRule.waitForIdleState() - verifyZeroInteractions(remoteLogRecordsFactory) - verifyZeroInteractions(sendingQueue) + verifyNoInteractions(remoteLogRecordsFactory) + verifyNoInteractions(sendingQueue) } @Test diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/network/BidRequestSenderTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/network/BidRequestSenderTest.kt index 63efd8e75..229296fe4 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/network/BidRequestSenderTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/network/BidRequestSenderTest.kt @@ -50,7 +50,7 @@ import org.mockito.kotlin.spy import org.mockito.kotlin.stub import org.mockito.kotlin.times import org.mockito.kotlin.verify -import org.mockito.kotlin.verifyZeroInteractions +import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever import java.io.IOException import java.util.concurrent.CountDownLatch @@ -273,7 +273,7 @@ class BidRequestSenderTest { fun sendBidRequest_GivenNoAdUnits_DoesNothing() { sender.sendBidRequest(emptyList(), mock(), mock()) - verifyZeroInteractions(api) + verifyNoInteractions(api) } @Test diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/tasks/InterstitialListenerNotifierTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/tasks/InterstitialListenerNotifierTest.kt index c10489ae3..3131baede 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/tasks/InterstitialListenerNotifierTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/tasks/InterstitialListenerNotifierTest.kt @@ -27,6 +27,9 @@ import com.criteo.publisher.CriteoListenerCode.INVALID_CREATIVE import com.criteo.publisher.CriteoListenerCode.OPEN import com.criteo.publisher.CriteoListenerCode.VALID import com.criteo.publisher.concurrent.DirectMockRunOnUiThreadExecutor +import com.criteo.publisher.mock.MockedDependenciesRule +import com.criteo.publisher.mock.SpyBean +import com.criteo.publisher.util.BuildConfigWrapper import org.assertj.core.api.Assertions.assertThatCode import org.junit.After import org.junit.Before @@ -41,6 +44,7 @@ import org.mockito.kotlin.doThrow import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import java.lang.ref.Reference +import java.lang.ref.WeakReference class InterstitialListenerNotifierTest { @@ -48,15 +52,21 @@ class InterstitialListenerNotifierTest { @JvmField val mockitoRule = MockitoJUnit.rule() - @Mock - private lateinit var interstitial: CriteoInterstitial + @Rule + @JvmField + var mockedDependenciesRule = MockedDependenciesRule() @Mock - private lateinit var listenerRef: Reference + private lateinit var interstitial: CriteoInterstitial @Mock private lateinit var listener: CriteoInterstitialAdListener + @SpyBean + private lateinit var buildConfigWrapper: BuildConfigWrapper + + private lateinit var listenerRef: Reference + private val runOnUiThreadExecutor = DirectMockRunOnUiThreadExecutor() private lateinit var listenerNotifier: InterstitialListenerNotifier @@ -64,12 +74,6 @@ class InterstitialListenerNotifierTest { @Before fun setUp() { setUpExpectingListenerToBeInvokedInExecutor() - - listenerNotifier = InterstitialListenerNotifier( - interstitial, - listenerRef, - runOnUiThreadExecutor - ) } @After @@ -146,6 +150,9 @@ class InterstitialListenerNotifierTest { @Test fun notifyFor_GivenThrowingListener_DoNothing() { givenThrowingListener() + // by default exception is thrown in debug mode but we want to test + // if it is working fine when debug throw disabled + doReturn(false).whenever(buildConfigWrapper).preconditionThrowsOnException() CriteoListenerCode.values().forEach { assertThatCode { @@ -155,14 +162,26 @@ class InterstitialListenerNotifierTest { } private fun givenReachableListenerReference() { - whenever(listenerRef.get()).doReturn(listener) + listenerRef = WeakReference(listener) + createInterstitialListenerNotifier() } private fun givenUnreachableListenerReference() { - whenever(listenerRef.get()).doReturn(null) + listenerRef = WeakReference(null) + createInterstitialListenerNotifier() + } + + private fun createInterstitialListenerNotifier() { + listenerNotifier = InterstitialListenerNotifier( + interstitial, + listenerRef, + runOnUiThreadExecutor + ) } private fun givenThrowingListener() { + givenReachableListenerReference() + doThrow(RuntimeException::class).whenever(listener).onAdReceived(any()) doThrow(RuntimeException::class).whenever(listener).onAdFailedToReceive(any()) doThrow(RuntimeException::class).whenever(listener).onAdClicked()