Skip to content

Commit c9c8cfb

Browse files
refactor: Migrate Internal CoreCallback class to kotlin (#543)
1 parent 08401bc commit c9c8cfb

File tree

4 files changed

+78
-94
lines changed

4 files changed

+78
-94
lines changed

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
}

android-kit-base/src/test/kotlin/com/mparticle/kits/KitManagerImplTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class KitManagerImplTest {
331331
manager.updateKits(kitConfiguration)
332332
Assert.assertEquals(0, manager.providers.size)
333333
Mockito.`when`(mockUser.isLoggedIn).thenReturn(true)
334-
Mockito.`when`(manager.mCoreCallbacks.latestKitConfiguration).thenReturn(kitConfiguration)
334+
Mockito.`when`(manager.mCoreCallbacks.getLatestKitConfiguration()).thenReturn(kitConfiguration)
335335
manager.onUserIdentified(mockUser, null)
336336
TestCase.assertEquals(3, manager.providers.size)
337337
}
@@ -377,7 +377,7 @@ class KitManagerImplTest {
377377
manager.updateKits(kitConfiguration)
378378
Assert.assertEquals(3, manager.providers.size)
379379
Mockito.`when`(mockUser.isLoggedIn).thenReturn(false)
380-
Mockito.`when`(mockCoreCallbacks.latestKitConfiguration).thenReturn(kitConfiguration)
380+
Mockito.`when`(mockCoreCallbacks.getLatestKitConfiguration()).thenReturn(kitConfiguration)
381381
manager.onUserIdentified(mockUser, null)
382382
TestCase.assertEquals(0, manager.providers.size)
383383
}
@@ -573,7 +573,7 @@ class KitManagerImplTest {
573573
put(JSONObject().apply { put("id", idOne) })
574574
put(JSONObject().apply { put("id", idTwo) })
575575
}
576-
Mockito.`when`(manager.mCoreCallbacks.latestKitConfiguration).thenReturn(kitConfiguration)
576+
Mockito.`when`(manager.mCoreCallbacks.getLatestKitConfiguration()).thenReturn(kitConfiguration)
577577
val factory = Mockito.mock(
578578
KitIntegrationFactory::class.java
579579
)
@@ -613,7 +613,7 @@ class KitManagerImplTest {
613613
val kitConfiguration = JSONArray()
614614
kitConfiguration.put(JSONObject("{\"id\":1}"))
615615
kitConfiguration.put(JSONObject("{\"id\":2}"))
616-
Mockito.`when`(manager.mCoreCallbacks.latestKitConfiguration).thenReturn(kitConfiguration)
616+
Mockito.`when`(manager.mCoreCallbacks.getLatestKitConfiguration()).thenReturn(kitConfiguration)
617617
val factory = Mockito.mock(
618618
KitIntegrationFactory::class.java
619619
)

0 commit comments

Comments
 (0)