Skip to content

Commit

Permalink
⬆️ Add support for Android 14 (API 34)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-rasevych-criteo committed Jan 3, 2024
1 parent 19e9613 commit 698b98a
Show file tree
Hide file tree
Showing 24 changed files with 112 additions and 101 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Next Version
- Add support of Android 14 (API level 34)

# Version 5.0.2
- Send SDK MRAID capability
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/AndroidModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -86,7 +86,7 @@ class ExternalVideoPlayerTest {

externalVideoPlayer.play("https://criteo.com/cat_video.mp4", onErrorListener)

verifyZeroInteractions(onErrorListener)
verifyNoInteractions(onErrorListener)
val argumentCaptor = argumentCaptor<Intent>()
verify(context).startActivity(argumentCaptor.capture())
val intent = argumentCaptor.lastValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -118,6 +118,6 @@ class AdChoiceOverlayNativeRendererTest {

renderer.renderNativeView(helper, nativeView, nativeAd)

verifyZeroInteractions(delegate)
verifyNoInteractions(delegate)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -61,7 +61,7 @@ class ClickHelperTest {
fun notifyUserClick_GivenNull_DoNothing() {
clickHelper.notifyUserClickAsync(null)

verifyZeroInteractions(runOnUiThreadExecutor)
verifyNoInteractions(runOnUiThreadExecutor)
}

@Test
Expand All @@ -78,7 +78,7 @@ class ClickHelperTest {
fun notifyUserIsLeavingApplication_GivenNull_DoNothing() {
clickHelper.notifyUserIsLeavingApplicationAsync(null)

verifyZeroInteractions(runOnUiThreadExecutor)
verifyNoInteractions(runOnUiThreadExecutor)
}

@Test
Expand All @@ -95,7 +95,7 @@ class ClickHelperTest {
fun notifyUserIsBackToApplication_GivenNull_DoNothing() {
clickHelper.notifyUserIsBackToApplicationAsync(null)

verifyZeroInteractions(runOnUiThreadExecutor)
verifyNoInteractions(runOnUiThreadExecutor)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -41,29 +39,23 @@ class ImpressionTaskTest {
@Mock
private lateinit var impressionPixels: Iterable<URL>

@Mock
private lateinit var listenerRef: Reference<CriteoNativeAdListener>

@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)
}

@Test
fun onVisible_GivenEmptyListenerRef_DoesNotThrowAndDoNotDelegateToHelper() {
whenever(listenerRef.get()).thenReturn(null)
createImpressionTaskWithListener()

assertThatCode {
task.onVisible()
Expand All @@ -75,7 +67,7 @@ class ImpressionTaskTest {
@Test
fun onVisible_GivenNotEmptyListenerRef_DelegateToHelper() {
val listener = mock<CriteoNativeAdListener>()
whenever(listenerRef.get()).thenReturn(listener)
createImpressionTaskWithListener(listener)

task.onVisible()

Expand All @@ -84,12 +76,17 @@ class ImpressionTaskTest {

@Test
fun onVisible_CalledTwice_WorkOnlyOnce() {
whenever(listenerRef.get()).thenReturn(mock())
val listener = mock<CriteoNativeAdListener>()
createImpressionTaskWithListener(listener)

task.onVisible()
task.onVisible()

verify(helper, times(1)).firePixels(any())
verify(helper, times(1)).notifyImpression(any())
}

private fun createImpressionTaskWithListener(listener: CriteoNativeAdListener? = null) {
task = ImpressionTask(impressionPixels, WeakReference(listener), helper)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,31 @@ 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 {

@Rule
@JvmField
val mockitoRule = MockitoJUnit.rule()

@Mock
private lateinit var viewRef: Reference<View>

@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()
}

Expand All @@ -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()

Expand All @@ -101,7 +97,7 @@ class VisibilityTrackingTaskTest {
@Test
fun onPreDraw_GivenListenerAndReferenceAndIsVisible_NotifyListener() {
val listener = mock<VisibilityListener>()
whenever(visibilityChecker.isVisible(viewRef.get()!!)).thenReturn(true)
whenever(visibilityChecker.isVisible(view)).thenReturn(true)

val task = createTask()
task.setListener(listener)
Expand All @@ -113,7 +109,7 @@ class VisibilityTrackingTaskTest {
@Test
fun onGlobalLayout_GivenListenerAndReferenceAndIsGone_NotifyListener() {
val listener = mock<VisibilityListener>()
whenever(visibilityChecker.isVisible(viewRef.get()!!)).thenReturn(false)
whenever(visibilityChecker.isVisible(view)).thenReturn(false)

val task = createTask()
task.setListener(listener)
Expand All @@ -125,7 +121,7 @@ class VisibilityTrackingTaskTest {
@Test
fun onPreDraw_GivenListenerAndReferenceAndIsGone_CancelAndAndExecuteAndExecuteAsyncWithDelay() {
val listener = mock<VisibilityListener>()
whenever(visibilityChecker.isVisible(viewRef.get()!!)).thenReturn(false)
whenever(visibilityChecker.isVisible(view)).thenReturn(false)
givenViewTreeObserver(true)

val task = createTask()
Expand Down Expand Up @@ -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)
}
}
Loading

0 comments on commit 698b98a

Please sign in to comment.