Skip to content

Commit

Permalink
refactor: Migrate Internal CoreCallback class to kotlin (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mansi-mParticle authored Oct 30, 2024
1 parent a8efd13 commit b6ab438
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 90 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

0 comments on commit b6ab438

Please sign in to comment.