Skip to content

Commit

Permalink
refactor: Migrate Internal CoreCallback class to kotlin (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mansi-mParticle authored Feb 12, 2025
1 parent 08401bc commit c9c8cfb
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 94 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.mparticle.internal

import android.app.Activity
import android.net.Uri
import androidx.annotation.WorkerThread
import com.mparticle.MParticleOptions.DataplanOptions
import org.json.JSONArray
import java.lang.ref.WeakReference

interface CoreCallbacks {
fun isBackgrounded(): Boolean

fun getUserBucket(): Int

fun isEnabled(): Boolean

fun setIntegrationAttributes(kitId: Int, integrationAttributes: Map<String, String>)

fun getIntegrationAttributes(kitId: Int): Map<String, String>?

fun getCurrentActivity(): WeakReference<Activity>?

@WorkerThread
fun getLatestKitConfiguration(): JSONArray?

fun getDataplanOptions(): DataplanOptions?

fun isPushEnabled(): Boolean

fun getPushSenderId(): String?

fun getPushInstanceId(): String?

fun getLaunchUri(): Uri?

fun getLaunchAction(): String?

fun getKitListener(): KitListener?

interface KitListener {
fun kitFound(kitId: Int)

fun kitConfigReceived(kitId: Int, configuration: String?)

fun kitExcluded(kitId: Int, reason: String?)

fun kitStarted(kitId: Int)
fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?)
fun onKitApiCalled(methodName: String?, kitId: Int, used: Boolean?, vararg objects: Any?)

companion object {
@JvmField
val EMPTY: KitListener = object : KitListener {
override fun kitFound(kitId: Int) {}
override fun kitConfigReceived(kitId: Int, configuration: String?) {}
override fun kitExcluded(kitId: Int, reason: String?) {}
override fun kitStarted(kitId: Int) {}
override fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?) {}
override fun onKitApiCalled(methodName: String?, kitId: Int, used: Boolean?, vararg objects: Any?) {}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class KitFrameworkWrapperTest {
true,
Mockito.mock(MParticleOptions::class.java)
)
Mockito.`when`(wrapper.mCoreCallbacks.pushInstanceId).thenReturn("instanceId")
Mockito.`when`(wrapper.mCoreCallbacks.pushSenderId).thenReturn("1234545")
Mockito.`when`(wrapper.mCoreCallbacks.getPushInstanceId()).thenReturn("instanceId")
Mockito.`when`(wrapper.mCoreCallbacks.getPushSenderId()).thenReturn("1234545")
MParticle.setInstance(MockMParticle())
wrapper.replayEvents()
val mockKitManager = Mockito.mock(KitManager::class.java)
Expand Down Expand Up @@ -594,15 +594,15 @@ class KitFrameworkWrapperTest {
mockConfigManager,
mockAppStateManager
)
Assert.assertEquals(mockActivity, coreCallbacks.currentActivity.get())
Assert.assertEquals(mockKitConfiguration, coreCallbacks.latestKitConfiguration)
Assert.assertEquals(mockLaunchUri, coreCallbacks.launchUri)
Assert.assertEquals(mockPushInstanceId, coreCallbacks.pushInstanceId)
Assert.assertEquals(mockPushSenderId, coreCallbacks.pushSenderId)
Assert.assertEquals(mockUserBucket.toLong(), coreCallbacks.userBucket.toLong())
Assert.assertEquals(isBackground, coreCallbacks.isBackgrounded)
Assert.assertEquals(isEnabled, coreCallbacks.isEnabled)
Assert.assertEquals(isPushEnabled, coreCallbacks.isPushEnabled)
Assert.assertEquals(mockActivity, coreCallbacks.getCurrentActivity()?.get())
Assert.assertEquals(mockKitConfiguration, coreCallbacks.getLatestKitConfiguration())
Assert.assertEquals(mockLaunchUri, coreCallbacks.getLaunchUri())
Assert.assertEquals(mockPushInstanceId, coreCallbacks.getPushInstanceId())
Assert.assertEquals(mockPushSenderId, coreCallbacks.getPushSenderId())
Assert.assertEquals(mockUserBucket.toLong(), coreCallbacks.getUserBucket().toLong())
Assert.assertEquals(isBackground, coreCallbacks.isBackgrounded())
Assert.assertEquals(isEnabled, coreCallbacks.isEnabled())
Assert.assertEquals(isPushEnabled, coreCallbacks.isPushEnabled())
Assert.assertEquals(mockIntegrationAttributes1, coreCallbacks.getIntegrationAttributes(1))
Assert.assertEquals(mockIntegrationAttributes2, coreCallbacks.getIntegrationAttributes(2))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class KitManagerImplTest {
manager.updateKits(kitConfiguration)
Assert.assertEquals(0, manager.providers.size)
Mockito.`when`(mockUser.isLoggedIn).thenReturn(true)
Mockito.`when`(manager.mCoreCallbacks.latestKitConfiguration).thenReturn(kitConfiguration)
Mockito.`when`(manager.mCoreCallbacks.getLatestKitConfiguration()).thenReturn(kitConfiguration)
manager.onUserIdentified(mockUser, null)
TestCase.assertEquals(3, manager.providers.size)
}
Expand Down Expand Up @@ -377,7 +377,7 @@ class KitManagerImplTest {
manager.updateKits(kitConfiguration)
Assert.assertEquals(3, manager.providers.size)
Mockito.`when`(mockUser.isLoggedIn).thenReturn(false)
Mockito.`when`(mockCoreCallbacks.latestKitConfiguration).thenReturn(kitConfiguration)
Mockito.`when`(mockCoreCallbacks.getLatestKitConfiguration()).thenReturn(kitConfiguration)
manager.onUserIdentified(mockUser, null)
TestCase.assertEquals(0, manager.providers.size)
}
Expand Down Expand Up @@ -573,7 +573,7 @@ class KitManagerImplTest {
put(JSONObject().apply { put("id", idOne) })
put(JSONObject().apply { put("id", idTwo) })
}
Mockito.`when`(manager.mCoreCallbacks.latestKitConfiguration).thenReturn(kitConfiguration)
Mockito.`when`(manager.mCoreCallbacks.getLatestKitConfiguration()).thenReturn(kitConfiguration)
val factory = Mockito.mock(
KitIntegrationFactory::class.java
)
Expand Down Expand Up @@ -613,7 +613,7 @@ class KitManagerImplTest {
val kitConfiguration = JSONArray()
kitConfiguration.put(JSONObject("{\"id\":1}"))
kitConfiguration.put(JSONObject("{\"id\":2}"))
Mockito.`when`(manager.mCoreCallbacks.latestKitConfiguration).thenReturn(kitConfiguration)
Mockito.`when`(manager.mCoreCallbacks.getLatestKitConfiguration()).thenReturn(kitConfiguration)
val factory = Mockito.mock(
KitIntegrationFactory::class.java
)
Expand Down

0 comments on commit c9c8cfb

Please sign in to comment.