Skip to content

Commit

Permalink
test(junit4): revert to junit4 using kotest everywhere possible
Browse files Browse the repository at this point in the history
SUITEDEV-35237

Co-authored-by: davidSchuppa <[email protected]>
  • Loading branch information
megamegax and davidSchuppa committed Feb 27, 2024
1 parent eaa591e commit 3e4087f
Show file tree
Hide file tree
Showing 239 changed files with 1,592 additions and 1,466 deletions.
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,18 @@ test-android-firebase-emulator: check-env ## run Android Instrumented tests on e
--device model=Pixel2.arm,version=28,locale=en,orientation=portrait \
--device model=MediumPhone.arm,version=30,locale=en,orientation=portrait \
--device model=SmallPhone.arm,version=33,locale=en,orientation=portrait \
--environment-variables runnerBuilder=de.mannodermaus.junit5.AndroidJUnit5Builder \
--environment-variables clearPackageData=true \
--client-details matrixLabel="Android Emarsys SDK - virtual devices"

test-android-firebase: check-env ## run Android Instrumented tests on real devices on Firebase Test Lab
@gcloud firebase test android run \
--type instrumentation \
--app ./sample/build/outputs/apk/androidTest/debug/sample-debug-androidTest.apk \
--test ./$(MODULE_NAME)/build/outputs/apk/androidTest/debug/$(MODULE_NAME)-debug-androidTest.apk \
--device model=f2q,version=30,locale=en,orientation=portrait \
--device model=a51,version=31,locale=en,orientation=portrait \
--device model=bluejay,version=32,locale=en,orientation=portrait \
--device model=b4q,version=33,locale=en,orientation=portrait \
--environment-variables runnerBuilder=de.mannodermaus.junit5.AndroidJUnit5Builder \
--environment-variables clearPackageData=true \
--client-details matrixLabel="Unified SDK - physical devices"
--device model=redfin,version=30,locale=en,orientation=portrait \
--device model=q2q,version=31,locale=en,orientation=portrait \
--device model=oriole,version=32,locale=en,orientation=portrait \
--device model=felix,version=33,locale=en,orientation=portrait \
--client-details matrixLabel="Android Emarsys SDK - physical devices"

run-github-workflow-locally: check-env ## needs act to be installed: `brew install act` and docker running. Pass in workflow path to run
@act --secret-file ./workflow.secrets -W $(WORKFLOW_PATH) --container-architecture linux/amd64
12 changes: 9 additions & 3 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ android {

multiDexEnabled = true
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["runnerBuilder"] =
"de.mannodermaus.junit5.AndroidJUnit5Builder"
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
packaging {
resources {
excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md")
excludes += arrayOf(
"README.txt",
"META-INF/LICENSE.md",
"META-INF/LICENSE-notice.md",
"**/attach_hotspot_windows.dll",
"META-INF/AL2.0",
"META-INF/LGPL2.1",
"META-INF/licenses/ASM"
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.emarsys.common.feature

import com.emarsys.testUtil.AnnotationSpec
import io.kotest.data.forAll
import io.kotest.data.row
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test


class InnerFeatureTest {
class InnerFeatureTest : AnnotationSpec() {

@Test
fun testValues_shouldReturnCorrectValues() {
Expand Down
12 changes: 9 additions & 3 deletions core-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ android {

multiDexEnabled = true
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["runnerBuilder"] =
"de.mannodermaus.junit5.AndroidJUnit5Builder"
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
packaging {
resources {
excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md")
excludes += arrayOf(
"README.txt",
"META-INF/LICENSE.md",
"META-INF/LICENSE-notice.md",
"**/attach_hotspot_windows.dll",
"META-INF/AL2.0",
"META-INF/LGPL2.1",
"META-INF/licenses/ASM"
)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core-api/src/androidTest/java/com/emarsys/core/api/ApiTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.emarsys.core.api


import org.junit.jupiter.api.Test
import com.emarsys.testUtil.AnnotationSpec


class ApiTest {
class ApiTest : AnnotationSpec() {


@Test
Expand Down
13 changes: 9 additions & 4 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ android {
multiDexEnabled = true

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["runnerBuilder"] =
"de.mannodermaus.junit5.AndroidJUnit5Builder"


val version: GitVersion by rootProject.extra
buildConfigField("int", "VERSION_CODE", "${version.versionCode}")
Expand All @@ -44,7 +41,15 @@ android {

packaging {
resources {
excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md")
excludes += arrayOf(
"README.txt",
"META-INF/LICENSE.md",
"META-INF/LICENSE-notice.md",
"**/attach_hotspot_windows.dll",
"META-INF/AL2.0",
"META-INF/LGPL2.1",
"META-INF/licenses/ASM"
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import com.emarsys.core.api.ResponseErrorException
import com.emarsys.core.api.result.CompletionListener
import com.emarsys.core.request.model.RequestModel
import com.emarsys.core.response.ResponseModel
import com.emarsys.testUtil.AnnotationSpec
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
Expand All @@ -15,7 +14,7 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyNoInteractions
import org.mockito.kotlin.verifyNoMoreInteractions

class DefaultCoreCompletionHandlerTest {
class DefaultCoreCompletionHandlerTest : AnnotationSpec() {

companion object {
const val STATUS_CODE = 500
Expand All @@ -30,7 +29,7 @@ class DefaultCoreCompletionHandlerTest {
private lateinit var responseErrorException: ResponseErrorException


@BeforeEach
@Before
@Suppress("UNCHECKED_CAST")
fun init() {
mockMap = mock()
Expand Down
10 changes: 4 additions & 6 deletions core/src/androidTest/java/com/emarsys/core/DeviceInfoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.emarsys.core.device.LanguageProvider
import com.emarsys.core.provider.hardwareid.HardwareIdProvider
import com.emarsys.core.provider.version.VersionProvider
import com.emarsys.core.util.AndroidVersionUtils
import com.emarsys.testUtil.AnnotationSpec
import com.emarsys.testUtil.ApplicationTestUtils.applicationDebug
import com.emarsys.testUtil.ApplicationTestUtils.applicationRelease
import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext
Expand All @@ -22,16 +23,13 @@ import io.kotest.matchers.booleans.shouldBeTrue
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import org.json.JSONObject
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import java.util.*

class DeviceInfoTest {
class DeviceInfoTest : AnnotationSpec() {

companion object {
private const val HARDWARE_ID = "hwid"
Expand All @@ -49,7 +47,7 @@ class DeviceInfoTest {
private lateinit var mockNotificationManagerHelper: NotificationSettings


@BeforeEach
@Before
fun setup() {
tz = TimeZone.getTimeZone("Asia/Tokyo")
TimeZone.setDefault(tz)
Expand All @@ -72,7 +70,7 @@ class DeviceInfoTest {
)
}

@AfterEach
@After
fun teardown() {
TimeZone.setDefault(null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import com.emarsys.core.activity.ActivityLifecycleAction.ActivityLifecycle.RESUM
import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory
import com.emarsys.core.handler.ConcurrentHandlerHolder
import com.emarsys.core.provider.activity.CurrentActivityProvider
import com.emarsys.testUtil.AnnotationSpec
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.doReturn
Expand All @@ -19,7 +18,7 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.util.concurrent.CountDownLatch

class ActivityLifecycleActionRegistryTest {
class ActivityLifecycleActionRegistryTest : AnnotationSpec() {

private lateinit var activityLifecycleActionRegistry: ActivityLifecycleActionRegistry
private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder
Expand All @@ -30,7 +29,7 @@ class ActivityLifecycleActionRegistryTest {
private lateinit var mockActions: MutableList<ActivityLifecycleAction>
private lateinit var mockActivity: Activity

@BeforeEach
@Before
fun setup() {
mockActivity = mock()
mockAction1 = mock {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.emarsys.core.activity

import android.app.Activity
import org.junit.jupiter.api.BeforeEach

import org.junit.jupiter.api.Test

import com.emarsys.testUtil.AnnotationSpec
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify

class ActivityLifecycleWatchdogTest {
class ActivityLifecycleWatchdogTest : AnnotationSpec() {
private lateinit var watchdog: ActivityLifecycleWatchdog
private lateinit var mockRegistry: ActivityLifecycleActionRegistry
private lateinit var mockActivity: Activity


@BeforeEach
@Before
fun setUp() {
mockRegistry = mock()
mockActivity = mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ import android.os.Bundle
import com.emarsys.core.provider.Property
import com.emarsys.core.provider.activity.CurrentActivityProvider
import com.emarsys.core.provider.activity.FallbackActivityProvider
import com.emarsys.testUtil.AnnotationSpec
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.kotlin.inOrder
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyNoInteractions

class CurrentActivityWatchdogTest {
class CurrentActivityWatchdogTest : AnnotationSpec() {
private lateinit var watchdog: CurrentActivityWatchdog
private lateinit var activity: Activity
private lateinit var nextActivity: Activity
private lateinit var activityProvider: Property<Activity?>


@BeforeEach
@Before
fun setUp() {
activityProvider = mock()
watchdog = CurrentActivityWatchdog(activityProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ package com.emarsys.core.api

import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory
import com.emarsys.core.handler.ConcurrentHandlerHolder
import com.emarsys.testUtil.AnnotationSpec
import com.emarsys.testUtil.mockito.ThreadSpy
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.BeforeEach

import org.junit.jupiter.api.Test

import java.util.concurrent.Callable
import java.util.concurrent.CountDownLatch

class AsyncProxyTest {
class AsyncProxyTest : AnnotationSpec() {

private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder


@BeforeEach
@Before
fun setUp() {
concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import com.emarsys.core.handler.ConcurrentHandlerHolder
import com.emarsys.core.util.log.LogLevel
import com.emarsys.core.util.log.Logger
import com.emarsys.core.util.log.entry.CrashLog
import com.emarsys.testUtil.AnnotationSpec
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.eq
Expand All @@ -21,11 +19,11 @@ import java.lang.reflect.InvocationTargetException
import java.util.concurrent.CountDownLatch


class LogExceptionProxyTest {
class LogExceptionProxyTest : AnnotationSpec() {
private lateinit var mockLogger: Logger
private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder

@BeforeEach
@Before
fun setUp() {
concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create()
mockLogger = mock()
Expand All @@ -39,7 +37,7 @@ class LogExceptionProxyTest {
setupCoreComponent(dependencyContainer)
}

@AfterEach
@After
fun tearDown() {
tearDownCoreComponent()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@ import androidx.lifecycle.LifecycleRegistry
import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory
import com.emarsys.core.handler.ConcurrentHandlerHolder
import com.emarsys.core.session.Session
import com.emarsys.testUtil.AnnotationSpec
import com.emarsys.testUtil.mockito.whenever
import org.junit.jupiter.api.BeforeEach

import org.junit.jupiter.api.Test

import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import java.util.concurrent.CountDownLatch

class AppLifecycleObserverTest {
class AppLifecycleObserverTest : AnnotationSpec() {
private lateinit var mockSession: Session
private lateinit var appLifecycleObserver: AppLifecycleObserver
private lateinit var coreHandlerHolder: ConcurrentHandlerHolder
private lateinit var mockLifecycleOwner: LifecycleOwner
private lateinit var uiHandler: Handler


@BeforeEach
@Before
fun setUp() {
uiHandler = Handler(Looper.getMainLooper())
mockSession = mock()
Expand Down
Loading

0 comments on commit 3e4087f

Please sign in to comment.