Skip to content

Commit 5ad52b6

Browse files
committed
Add tests for setWrapperSdkVersion
1 parent 43bd466 commit 5ad52b6

5 files changed

Lines changed: 105 additions & 12 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ public void execute(@NonNull String viewName,
666666
}
667667

668668
@Override
669-
public void setWrapperSdkVersion(WrapperSdkVersion wrapperSdkVersion) {
669+
public void setWrapperSdkVersion(@NonNull WrapperSdkVersion wrapperSdkVersion) {
670670
if (mKitManager != null) {
671671
mKitManager.setWrapperSdkVersion(wrapperSdkVersion);
672672
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void execute(
131131
@Nullable Map<String, WeakReference<RoktEmbeddedView>> placeHolders,
132132
@Nullable Map<String, WeakReference<Typeface>> fontTypefaces);
133133

134-
void setWrapperSdkVersion(WrapperSdkVersion wrapperSdkVersion);
134+
void setWrapperSdkVersion(@NonNull WrapperSdkVersion wrapperSdkVersion);
135135

136136
enum KitStatus {
137137
NOT_CONFIGURED,

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@ import com.mparticle.MPEvent
88
import com.mparticle.MParticle
99
import com.mparticle.MParticleOptions
1010
import com.mparticle.MockMParticle
11+
import com.mparticle.WrapperSdk
12+
import com.mparticle.WrapperSdkVersion
1113
import com.mparticle.commerce.CommerceEvent
1214
import com.mparticle.internal.PushRegistrationHelper.PushRegistration
1315
import com.mparticle.testutils.RandomUtils
1416
import org.json.JSONArray
1517
import org.junit.Assert
1618
import org.junit.Test
1719
import org.junit.runner.RunWith
20+
import org.mockito.ArgumentMatchers.any
1821
import org.mockito.Mockito
22+
import org.mockito.Mockito.mock
23+
import org.mockito.Mockito.times
24+
import org.mockito.Mockito.verify
1925
import org.powermock.api.mockito.PowerMockito
2026
import org.powermock.core.classloader.annotations.PrepareForTest
2127
import org.powermock.modules.junit4.PowerMockRunner
@@ -605,4 +611,45 @@ class KitFrameworkWrapperTest {
605611
Assert.assertEquals(mockIntegrationAttributes1, coreCallbacks.getIntegrationAttributes(1))
606612
Assert.assertEquals(mockIntegrationAttributes2, coreCallbacks.getIntegrationAttributes(2))
607613
}
614+
615+
@Test
616+
fun testSetWrapperSdkVersion_noCalls() {
617+
val wrapper = KitFrameworkWrapper(
618+
mock(
619+
Context::class.java
620+
),
621+
mock(ReportingManager::class.java),
622+
mock(ConfigManager::class.java),
623+
mock(AppStateManager::class.java),
624+
true,
625+
mock(MParticleOptions::class.java)
626+
)
627+
628+
val mockKitManager = mock(KitManager::class.java)
629+
wrapper.setKitManager(mockKitManager)
630+
631+
verify(mockKitManager, times(0)).setWrapperSdkVersion(any())
632+
}
633+
634+
@Test
635+
fun testSetWrapperSdkVersion_kitManagerSet_setWrapperVersionCalled() {
636+
val wrapper = KitFrameworkWrapper(
637+
mock(
638+
Context::class.java
639+
),
640+
mock(ReportingManager::class.java),
641+
mock(ConfigManager::class.java),
642+
mock(AppStateManager::class.java),
643+
true,
644+
mock(MParticleOptions::class.java)
645+
)
646+
647+
val mockKitManager = mock(KitManager::class.java)
648+
wrapper.setKitManager(mockKitManager)
649+
650+
val expectedSdkVersion = WrapperSdkVersion(WrapperSdk.WrapperFlutter, "1.0.0")
651+
wrapper.setWrapperSdkVersion(expectedSdkVersion)
652+
653+
verify(mockKitManager).setWrapperSdkVersion(expectedSdkVersion)
654+
}
608655
}

android-kit-base/src/main/java/com/mparticle/kits/KitManagerImpl.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,11 +1331,11 @@ public void reset() {
13311331
}
13321332

13331333
@Override
1334-
public void execute(String viewName,
1335-
Map<String, String> attributes,
1336-
MParticle.MpRoktEventCallback mpRoktEventCallback,
1337-
Map<String, WeakReference<RoktEmbeddedView>> placeHolders,
1338-
Map<String, WeakReference<Typeface>> fontTypefaces) {
1334+
public void execute(@NonNull String viewName,
1335+
@NonNull Map<String, String> attributes,
1336+
@Nullable MParticle.MpRoktEventCallback mpRoktEventCallback,
1337+
@Nullable Map<String, WeakReference<RoktEmbeddedView>> placeHolders,
1338+
@Nullable Map<String, WeakReference<Typeface>> fontTypefaces) {
13391339
for (KitIntegration provider : providers.values()) {
13401340
try {
13411341
if (provider instanceof KitIntegration.RoktListener && !provider.isDisabled()) {
@@ -1396,8 +1396,16 @@ public void execute(String viewName,
13961396
}
13971397

13981398
@Override
1399-
public void setWrapperSdkVersion(WrapperSdkVersion wrapperSdkVersion) {
1400-
1399+
public void setWrapperSdkVersion(@NonNull WrapperSdkVersion wrapperSdkVersion) {
1400+
for (KitIntegration provider : providers.values()) {
1401+
try {
1402+
if (provider instanceof KitIntegration.RoktListener && !provider.isDisabled()) {
1403+
((KitIntegration.RoktListener) provider).setWrapperSdkVersion(wrapperSdkVersion);
1404+
}
1405+
} catch (Exception e) {
1406+
Logger.warning("Failed to call execute for kit: " + provider.getName() + ": " + e.getMessage());
1407+
}
1408+
}
14011409
}
14021410

14031411
private void confirmEmail(

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.mparticle.MPEvent
99
import com.mparticle.MParticle
1010
import com.mparticle.MParticleOptions
1111
import com.mparticle.MParticleTask
12+
import com.mparticle.WrapperSdk
1213
import com.mparticle.WrapperSdkVersion
1314
import com.mparticle.commerce.CommerceEvent
1415
import com.mparticle.commerce.Product
@@ -38,8 +39,10 @@ import org.junit.runner.RunWith
3839
import org.mockito.ArgumentMatchers.any
3940
import org.mockito.Mockito
4041
import org.mockito.Mockito.mock
42+
import org.mockito.Mockito.never
4143
import org.mockito.Mockito.verify
4244
import org.mockito.Mockito.`when`
45+
import org.mockito.Mockito.withSettings
4346
import org.powermock.api.mockito.PowerMockito
4447
import org.powermock.core.classloader.annotations.PrepareForTest
4548
import org.powermock.modules.junit4.PowerMockRunner
@@ -1425,6 +1428,40 @@ class KitManagerImplTest {
14251428
Assert.assertEquals("false", attributes["sandbox"])
14261429
}
14271430

1431+
@Test
1432+
fun testSetWrapperSdkVersion() {
1433+
val manager: KitManagerImpl = MockKitManagerImpl()
1434+
1435+
val enabledRoktListener = mock(
1436+
KitIntegration::class.java,
1437+
withSettings().extraInterfaces(KitIntegration.RoktListener::class.java)
1438+
)
1439+
`when`(enabledRoktListener.isDisabled).thenReturn(false)
1440+
1441+
val disabledRoktListener = mock(
1442+
KitIntegration::class.java,
1443+
withSettings().extraInterfaces(KitIntegration.RoktListener::class.java)
1444+
)
1445+
`when`(disabledRoktListener.isDisabled).thenReturn(true)
1446+
1447+
val nonRoktListener = mock(KitIntegration::class.java)
1448+
`when`(nonRoktListener.isDisabled).thenReturn(false)
1449+
1450+
manager.providers = ConcurrentHashMap<Int, KitIntegration>().apply {
1451+
put(1, enabledRoktListener)
1452+
put(2, disabledRoktListener)
1453+
put(3, nonRoktListener)
1454+
}
1455+
1456+
val wrapperSdkVersion = WrapperSdkVersion(WrapperSdk.WrapperFlutter, "1.2.3")
1457+
manager.setWrapperSdkVersion(wrapperSdkVersion)
1458+
1459+
verify(enabledRoktListener as KitIntegration.RoktListener)
1460+
.setWrapperSdkVersion(wrapperSdkVersion)
1461+
verify(disabledRoktListener as KitIntegration.RoktListener, never())
1462+
.setWrapperSdkVersion(wrapperSdkVersion)
1463+
}
1464+
14281465
internal inner class mockProvider(val config: KitConfiguration) : KitIntegration(), KitIntegration.RoktListener {
14291466
override fun isDisabled(): Boolean = false
14301467
override fun getName(): String = "FakeProvider"
@@ -1441,8 +1478,8 @@ class KitManagerImplTest {
14411478
}
14421479

14431480
override fun execute(
1444-
viewName: String?,
1445-
attributes: MutableMap<String, String>?,
1481+
viewName: String,
1482+
attributes: MutableMap<String, String>,
14461483
mpRoktEventCallback: MParticle.MpRoktEventCallback?,
14471484
placeHolders: MutableMap<String, WeakReference<RoktEmbeddedView>>?,
14481485
fontTypefaces: MutableMap<String, WeakReference<Typeface>>?,
@@ -1451,10 +1488,11 @@ class KitManagerImplTest {
14511488
println("Executed with $attributes")
14521489
}
14531490

1454-
override fun setWrapperSdkVersion(wrapperSdkVersion: WrapperSdkVersion?) {
1491+
override fun setWrapperSdkVersion(wrapperSdkVersion: WrapperSdkVersion) {
14551492
println("setWrapperSdkVersion with $wrapperSdkVersion")
14561493
}
14571494
}
1495+
14581496
internal inner class KitManagerEventCounter : MockKitManagerImpl() {
14591497
var logBaseEventCalled = 0
14601498
var logCommerceEventCalled = 0

0 commit comments

Comments
 (0)