Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tests] Upgrade to Junit5 #2006

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions OneSignalSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ buildscript {
huaweiHMSPushVersion = '6.3.0.304'
huaweiHMSLocationVersion = '4.0.0.300'
kotlinVersion = '1.7.10'
kotestVersion = '5.5.0'
kotestVersion = '5.8.0'
ktlintPluginVersion = '11.6.1'
ktlintVersion = '1.0.1'
junitVersion = '4.13.2'
// DO NOT upgrade for tests, using an old version so it matches AOSP
tdunningJsonForTest = '1.0'
}
Expand Down
9 changes: 6 additions & 3 deletions OneSignalSDK/onesignal/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ android {
unitTests {
includeAndroidResources = true
}
unitTests.all {
it.useJUnitPlatform()
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -79,9 +82,9 @@ dependencies {
}

testImplementation(project(':OneSignal:testhelpers'))
testImplementation("junit:junit:$junitVersion")
testImplementation("io.kotest:kotest-runner-junit4:$kotestVersion")
testImplementation("io.kotest:kotest-runner-junit4-jvm:$kotestVersion")

testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
testImplementation("io.kotest:kotest-runner-junit5-jvm:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
testImplementation("io.kotest:kotest-property:$kotestVersion")
testImplementation("org.robolectric:robolectric:4.8.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ package com.onesignal.common

import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.mockkStatic
import io.mockk.verify
import org.json.JSONArray
import org.json.JSONObject
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class JSONObjectExtensionsTest : DescribeSpec({
describe("toMap") {
// Some org.json JVM libraries define their own toMap. We want to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import com.onesignal.user.internal.subscriptions.SubscriptionModel
import com.onesignal.user.internal.subscriptions.SubscriptionModelStore
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import junit.framework.TestCase
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class ModelingTests : FunSpec({

test("Deadlock related to Model.setOptAnyProperty") {
Expand Down Expand Up @@ -55,7 +51,7 @@ class ModelingTests : FunSpec({
t2.join(1000)

// verify if the thread has been successfully terminated
TestCase.assertEquals(Thread.State.TERMINATED, t2.state)
t2.state shouldBe Thread.State.TERMINATED
}

test("Deadlock related to ModelSstore add() or remove()") {
Expand Down Expand Up @@ -113,7 +109,7 @@ class ModelingTests : FunSpec({
t2.join(1000)

// verify if the thread has been successfully terminated
TestCase.assertEquals(Thread.State.TERMINATED, t2.state)
t2.state shouldBe Thread.State.TERMINATED
}

test("Unsubscribing handler in change event may cause the concurrent modification exception") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import com.onesignal.debug.internal.logging.Logging
import com.onesignal.testhelpers.extensions.RobolectricTest
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.delay
import org.junit.runner.RunWith
import org.robolectric.Robolectric

@RobolectricTest
@RunWith(KotestTestRunner::class)
class ApplicationServiceTests : FunSpec({

beforeAny {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import com.onesignal.session.internal.outcomes.impl.OutcomeTableProvider
import com.onesignal.testhelpers.extensions.RobolectricTest
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.mockk
import org.junit.runner.RunWith

@RobolectricTest
@RunWith(KotestTestRunner::class)
class OSDatabaseTests : FunSpec({

beforeAny {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.types.beInstanceOf
import io.kotest.runner.junit4.KotestTestRunner
import kotlinx.coroutines.TimeoutCancellationException
import org.json.JSONObject
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class HttpClientTests : FunSpec({

beforeAny {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.onesignal.debug.internal.logging.Logging
import com.onesignal.mocks.MockHelper
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.CapturingSlot
import io.mockk.coEvery
import io.mockk.coVerifyOrder
Expand All @@ -17,9 +16,7 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.slot
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class OperationRepoTests : FunSpec({

beforeAny {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ import com.onesignal.testhelpers.extensions.RobolectricTest
import io.kotest.assertions.throwables.shouldThrowUnit
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import kotlinx.coroutines.delay
import org.junit.runner.RunWith

@RobolectricTest
@RunWith(KotestTestRunner::class)
class PreferencesServiceTests : FunSpec({
val mockPrefStoreName = PreferenceStores.ONESIGNAL
val mockBoolPrefStoreKey = "mock-bool"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import com.onesignal.debug.internal.logging.Logging
import io.kotest.assertions.throwables.shouldThrowUnit
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class StartupServiceTests : FunSpec({

beforeAny {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import com.onesignal.debug.internal.logging.Logging
import io.kotest.assertions.throwables.shouldThrowUnit
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class OneSignalImpTests : FunSpec({
beforeAny {
Logging.logLevel = LogLevel.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import com.onesignal.testhelpers.extensions.RobolectricTest
import io.kotest.core.spec.style.FunSpec
import io.kotest.core.spec.style.funSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import org.json.JSONObject
import org.junit.runner.RunWith

/**
* This purpose of this file is to ensure org.json classes being used in
Expand All @@ -29,7 +27,6 @@ val keyAOSPBehavior =
}

@RobolectricTest
@RunWith(KotestTestRunner::class)
class JSONObjectRobolectricEnvTest : FunSpec({
test("ensure our src JSON Kotlin extension methods work with @RobolectricTest") {
val test = JSONObject()
Expand All @@ -41,7 +38,6 @@ class JSONObjectRobolectricEnvTest : FunSpec({
include(keyAOSPBehavior)
})

@RunWith(KotestTestRunner::class)
class JSONObjectJVMEnvTest : FunSpec({
include(keyAOSPBehavior)
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ import com.onesignal.session.internal.session.ISessionService
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.Runs
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class InfluenceManagerTests : FunSpec({

test("default are disabled influences") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import com.onesignal.session.internal.outcomes.impl.OutcomeEventsBackendService
import io.kotest.assertions.throwables.shouldThrowUnit
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class OutcomeEventsBackendServiceTests : FunSpec({
beforeAny {
Logging.logLevel = LogLevel.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.onesignal.user.internal.subscriptions.SubscriptionModel
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.Runs
import io.mockk.coEvery
import io.mockk.coVerify
Expand All @@ -35,9 +34,7 @@ import io.mockk.runs
import io.mockk.spyk
import kotlinx.coroutines.delay
import org.json.JSONArray
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class OutcomeEventsControllerTests : FunSpec({
beforeAny {
Logging.logLevel = LogLevel.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ import com.onesignal.testhelpers.extensions.RobolectricTest
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.verify
import io.mockk.verifyAll
import io.mockk.verifySequence
import org.json.JSONArray
import org.junit.runner.RunWith

@RobolectricTest
@RunWith(KotestTestRunner::class)
class OutcomeEventsRepositoryTests : FunSpec({
beforeAny {
Logging.logLevel = LogLevel.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import com.onesignal.mocks.MockHelper
import com.onesignal.session.internal.session.impl.SessionService
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.spyk
import io.mockk.verify
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class SessionServiceTests : FunSpec({

test("session created on focus when current session invalid") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import com.onesignal.user.internal.subscriptions.SubscriptionList
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.slot
import io.mockk.verify
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class UserManagerTests : FunSpec({

test("language is backed by the language context") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import com.onesignal.debug.internal.logging.Logging
import com.onesignal.user.internal.backend.impl.IdentityBackendService
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class IdentityBackendServiceTests : FunSpec({
beforeAny {
Logging.logLevel = LogLevel.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ import com.onesignal.user.internal.subscriptions.SubscriptionStatus
import io.kotest.assertions.throwables.shouldThrowUnit
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import org.junit.runner.RunWith

// WARNING: Adding @RobolectricTest will cause JSONObject.map() to stop working
// at runtime.
@RunWith(KotestTestRunner::class)
class SubscriptionBackendServiceTests : FunSpec({
beforeAny {
Logging.logLevel = LogLevel.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ import com.onesignal.user.internal.backend.impl.UserBackendService
import io.kotest.assertions.throwables.shouldThrowUnit
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import org.junit.runner.RunWith
import java.math.BigDecimal

@RunWith(KotestTestRunner::class)
class UserBackendServiceTests : FunSpec({
beforeAny {
Logging.logLevel = LogLevel.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ import com.onesignal.user.internal.identity.IdentityModelStore
import com.onesignal.user.internal.operations.impl.executors.IdentityOperationExecutor
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class IdentityOperationExecutorTests : FunSpec({

test("execution of set alias operation") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldBeOneOf
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeInstanceOf
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.mockk
import org.junit.runner.RunWith

@RobolectricTest
@RunWith(KotestTestRunner::class)
class LoginUserOperationExecutorTests : FunSpec({
val appId = "appId"
val localOneSignalId = "local-onesignalId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ import com.onesignal.user.internal.subscriptions.SubscriptionModelStore
import com.onesignal.user.internal.subscriptions.SubscriptionType
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class RefreshUserOperationExecutorTests : FunSpec({
val appId = "appId"
val existingSubscriptionId1 = "existing-subscriptionId1"
Expand Down
Loading
Loading