Skip to content

Commit b6ab438

Browse files
refactor: Migrate Internal CoreCallback class to kotlin (#517)
1 parent a8efd13 commit b6ab438

3 files changed

Lines changed: 74 additions & 90 deletions

File tree

android-core/src/main/java/com/mparticle/internal/CoreCallbacks.java

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.mparticle.internal
2+
3+
import android.app.Activity
4+
import android.net.Uri
5+
import androidx.annotation.WorkerThread
6+
import com.mparticle.MParticleOptions.DataplanOptions
7+
import org.json.JSONArray
8+
import java.lang.ref.WeakReference
9+
10+
interface CoreCallbacks {
11+
fun isBackgrounded(): Boolean
12+
13+
fun getUserBucket(): Int
14+
15+
fun isEnabled(): Boolean
16+
17+
fun setIntegrationAttributes(kitId: Int, integrationAttributes: Map<String, String>)
18+
19+
fun getIntegrationAttributes(kitId: Int): Map<String, String>?
20+
21+
fun getCurrentActivity(): WeakReference<Activity>?
22+
23+
@WorkerThread
24+
fun getLatestKitConfiguration(): JSONArray?
25+
26+
fun getDataplanOptions(): DataplanOptions?
27+
28+
fun isPushEnabled(): Boolean
29+
30+
fun getPushSenderId(): String?
31+
32+
fun getPushInstanceId(): String?
33+
34+
fun getLaunchUri(): Uri?
35+
36+
fun getLaunchAction(): String?
37+
38+
fun getKitListener(): KitListener?
39+
40+
interface KitListener {
41+
fun kitFound(kitId: Int)
42+
43+
fun kitConfigReceived(kitId: Int, configuration: String?)
44+
45+
fun kitExcluded(kitId: Int, reason: String?)
46+
47+
fun kitStarted(kitId: Int)
48+
fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?)
49+
fun onKitApiCalled(methodName: String?, kitId: Int, used: Boolean?, vararg objects: Any?)
50+
51+
companion object {
52+
@JvmField
53+
val EMPTY: KitListener = object : KitListener {
54+
override fun kitFound(kitId: Int) {}
55+
override fun kitConfigReceived(kitId: Int, configuration: String?) {}
56+
override fun kitExcluded(kitId: Int, reason: String?) {}
57+
override fun kitStarted(kitId: Int) {}
58+
override fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?) {}
59+
override fun onKitApiCalled(methodName: String?, kitId: Int, used: Boolean?, vararg objects: Any?) {}
60+
}
61+
}
62+
}
63+
}

android-core/src/test/kotlin/com/mparticle/internal/KitFrameworkWrapperTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ class KitFrameworkWrapperTest {
8989
true,
9090
Mockito.mock(MParticleOptions::class.java)
9191
)
92-
Mockito.`when`(wrapper.mCoreCallbacks.pushInstanceId).thenReturn("instanceId")
93-
Mockito.`when`(wrapper.mCoreCallbacks.pushSenderId).thenReturn("1234545")
92+
Mockito.`when`(wrapper.mCoreCallbacks.getPushInstanceId()).thenReturn("instanceId")
93+
Mockito.`when`(wrapper.mCoreCallbacks.getPushSenderId()).thenReturn("1234545")
9494
MParticle.setInstance(MockMParticle())
9595
wrapper.replayEvents()
9696
val mockKitManager = Mockito.mock(KitManager::class.java)
@@ -594,15 +594,15 @@ class KitFrameworkWrapperTest {
594594
mockConfigManager,
595595
mockAppStateManager
596596
)
597-
Assert.assertEquals(mockActivity, coreCallbacks.currentActivity.get())
598-
Assert.assertEquals(mockKitConfiguration, coreCallbacks.latestKitConfiguration)
599-
Assert.assertEquals(mockLaunchUri, coreCallbacks.launchUri)
600-
Assert.assertEquals(mockPushInstanceId, coreCallbacks.pushInstanceId)
601-
Assert.assertEquals(mockPushSenderId, coreCallbacks.pushSenderId)
602-
Assert.assertEquals(mockUserBucket.toLong(), coreCallbacks.userBucket.toLong())
603-
Assert.assertEquals(isBackground, coreCallbacks.isBackgrounded)
604-
Assert.assertEquals(isEnabled, coreCallbacks.isEnabled)
605-
Assert.assertEquals(isPushEnabled, coreCallbacks.isPushEnabled)
597+
Assert.assertEquals(mockActivity, coreCallbacks.getCurrentActivity()?.get())
598+
Assert.assertEquals(mockKitConfiguration, coreCallbacks.getLatestKitConfiguration())
599+
Assert.assertEquals(mockLaunchUri, coreCallbacks.getLaunchUri())
600+
Assert.assertEquals(mockPushInstanceId, coreCallbacks.getPushInstanceId())
601+
Assert.assertEquals(mockPushSenderId, coreCallbacks.getPushSenderId())
602+
Assert.assertEquals(mockUserBucket.toLong(), coreCallbacks.getUserBucket().toLong())
603+
Assert.assertEquals(isBackground, coreCallbacks.isBackgrounded())
604+
Assert.assertEquals(isEnabled, coreCallbacks.isEnabled())
605+
Assert.assertEquals(isPushEnabled, coreCallbacks.isPushEnabled())
606606
Assert.assertEquals(mockIntegrationAttributes1, coreCallbacks.getIntegrationAttributes(1))
607607
Assert.assertEquals(mockIntegrationAttributes2, coreCallbacks.getIntegrationAttributes(2))
608608
}

0 commit comments

Comments
 (0)