Skip to content

Commit b70219c

Browse files
authored
Merge pull request #3 from segment-integrations/wenxi/resolve-package-collison
resolve package collison
2 parents 09a6ebd + ee58fb9 commit b70219c

File tree

6 files changed

+58
-44
lines changed

6 files changed

+58
-44
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ implementation("com.segment.analytics.kotlin.destinations:mixpanel:1.4.4")
2323
Open the file where you setup and configure the Analytics-Kotlin library. Add this plugin to the list of imports.
2424

2525
```
26-
import com.segment.analytics.kotlin.destinations.plugins.MixpanelDestination
26+
import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelDestination
2727
```
2828

2929
Just under your Analytics-Kotlin library setup, call `analytics.add(plugin = ...)` to add an instance of the plugin to the Analytics timeline.

lib/build.gradle.kts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ plugins {
66
id("mvn-publish")
77
}
88

9+
val VERSION_NAME: String by project
10+
911
android {
1012
compileSdk = 31
1113
buildToolsVersion = "31.0.0"
@@ -17,6 +19,8 @@ android {
1719

1820
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
1921
consumerProguardFiles("proguard-consumer-rules.pro")
22+
23+
buildConfigField("String", "VERSION_NAME", "\"$VERSION_NAME\"")
2024
}
2125

2226
buildTypes {
@@ -38,7 +42,7 @@ android {
3842
dependencies {
3943
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
4044

41-
implementation("com.segment.analytics.kotlin:android:1.4.3")
45+
implementation("com.segment.analytics.kotlin:android:1.5.0")
4246
implementation("androidx.multidex:multidex:2.0.1")
4347

4448
implementation("androidx.core:core-ktx:1.7.0")
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
package com.segment.analytics.kotlin.destinations.plugins
1+
package com.segment.analytics.kotlin.destinations.mixpanel
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import androidx.test.platform.app.InstrumentationRegistry
5-
5+
import org.junit.Assert
66
import org.junit.Test
77
import org.junit.runner.RunWith
88

9-
import org.junit.Assert.*
10-
119
/**
1210
* Instrumented test, which will execute on an Android device.
1311
*
@@ -19,6 +17,9 @@ class ExampleInstrumentedTest {
1917
fun useAppContext() {
2018
// Context of the app under test.
2119
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22-
assertEquals("com.segment.analytics.kotlin.destinations.plugins.test", appContext.packageName)
20+
Assert.assertEquals(
21+
"com.segment.analytics.kotlin.destinations.mixpanel.test",
22+
appContext.packageName
23+
)
2324
}
2425
}

lib/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.segment.analytics.kotlin.destinations.plugins">
3+
package="com.segment.analytics.kotlin.destinations.mixpanel">
44

55
</manifest>

lib/src/main/java/com/segment/analytics/kotlin/destinations/plugins/MixpanelDestination.kt lib/src/main/java/com/segment/analytics/kotlin/destinations/mixpanel/MixpanelDestination.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.segment.analytics.kotlin.destinations.plugins
1+
package com.segment.analytics.kotlin.destinations.mixpanel
22

33
import android.app.Activity
44
import android.content.Context
@@ -9,6 +9,7 @@ import com.segment.analytics.kotlin.android.utilities.toJSONObject
99
import com.segment.analytics.kotlin.core.*
1010
import com.segment.analytics.kotlin.core.platform.DestinationPlugin
1111
import com.segment.analytics.kotlin.core.platform.Plugin
12+
import com.segment.analytics.kotlin.core.platform.VersionedPlugin
1213
import com.segment.analytics.kotlin.core.platform.plugins.logger.*
1314
import com.segment.analytics.kotlin.core.utilities.*
1415
import kotlinx.serialization.*
@@ -67,7 +68,7 @@ data class MixpanelSettings(
6768

6869
class MixpanelDestination(
6970
private val context: Context
70-
) : DestinationPlugin(), AndroidLifecycle {
71+
) : DestinationPlugin(), AndroidLifecycle, VersionedPlugin {
7172

7273
internal var settings: MixpanelSettings? = null
7374
internal var mixpanel: MixpanelAPI? = null
@@ -251,4 +252,8 @@ class MixpanelDestination(
251252
keyMapper: Map<String, String>,
252253
): Map<String, JsonElement> = JsonObject(this).mapTransform(keyMapper, null)
253254

255+
override fun version(): String {
256+
return BuildConfig.VERSION_NAME
257+
}
258+
254259
}

lib/src/test/java/com/segment/analytics/kotlin/destinations/plugins/MixpanelDestinationTests.kt lib/src/test/java/com/segment/analytics/kotlin/destinations/mixpanel/MixpanelDestinationTests.kt

+38-34
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
package com.segment.analytics.kotlin.destinations.plugins
1+
package com.segment.analytics.kotlin.destinations.mixpanel
22

33
import android.content.Context
44
import com.mixpanel.android.mpmetrics.MixpanelAPI
55
import com.segment.analytics.kotlin.core.*
66
import com.segment.analytics.kotlin.core.platform.Plugin
7+
import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelDestination
8+
import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelSettings
79
import io.mockk.*
810
import io.mockk.impl.annotations.MockK
911
import kotlinx.serialization.decodeFromString
@@ -12,12 +14,11 @@ import kotlinx.serialization.json.buildJsonObject
1214
import kotlinx.serialization.json.put
1315
import org.json.JSONException
1416
import org.json.JSONObject
15-
import org.junit.jupiter.api.Assertions.*
17+
import org.junit.jupiter.api.Assertions
1618
import org.junit.jupiter.api.Test
1719
import org.skyscreamer.jsonassert.JSONAssert
1820
import org.skyscreamer.jsonassert.JSONCompareMode
1921

20-
2122
class MixpanelDestinationTests {
2223

2324
private val mockContext = mockk<Context>(relaxed = true)
@@ -81,20 +82,23 @@ class MixpanelDestinationTests {
8182
mixpanelDestination.update(settingsBlob, Plugin.UpdateType.Initial)
8283

8384
/* assertions about config */
84-
assertNotNull(mixpanelDestination.settings)
85+
Assertions.assertNotNull(mixpanelDestination.settings)
8586
with(mixpanelDestination.settings!!) {
86-
assertFalse(consolidatedPageCalls)
87-
assertTrue(isPeopleEnabled)
88-
assertFalse(trackAllPages)
89-
assertTrue(trackCategorizedPages)
90-
assertFalse(trackNamedPages)
91-
assertFalse(setAllTraitsByDefault)
87+
Assertions.assertFalse(consolidatedPageCalls)
88+
Assertions.assertTrue(isPeopleEnabled)
89+
Assertions.assertFalse(trackAllPages)
90+
Assertions.assertTrue(trackCategorizedPages)
91+
Assertions.assertFalse(trackNamedPages)
92+
Assertions.assertFalse(setAllTraitsByDefault)
9293

93-
assertEquals("token1234", token)
94+
Assertions.assertEquals("token1234", token)
9495

95-
assertEquals(emptySet<String>(), superPropertiesFilter)
96-
assertEquals(setOf("email", "username", "phone_number"), peoplePropertiesFilter)
97-
assertEquals(setOf("Product Clicked", "Product Viewed"), increments)
96+
Assertions.assertEquals(emptySet<String>(), superPropertiesFilter)
97+
Assertions.assertEquals(
98+
setOf("email", "username", "phone_number"),
99+
peoplePropertiesFilter
100+
)
101+
Assertions.assertEquals(setOf("Product Clicked", "Product Viewed"), increments)
98102
}
99103
}
100104

@@ -125,7 +129,7 @@ class MixpanelDestinationTests {
125129
)
126130
val screenEvent = mixpanelDestination.screen(sampleEvent)
127131

128-
assertNotNull(screenEvent)
132+
Assertions.assertNotNull(screenEvent)
129133
verify { mockMixpanel wasNot Called }
130134
}
131135

@@ -154,7 +158,7 @@ class MixpanelDestinationTests {
154158
)
155159
val screenEvent = mixpanelDestination.screen(sampleEvent)
156160

157-
assertNotNull(screenEvent)
161+
Assertions.assertNotNull(screenEvent)
158162
verify {
159163
mockMixpanel.track(
160164
"Viewed LoginFragment Screen",
@@ -192,7 +196,7 @@ class MixpanelDestinationTests {
192196
)
193197
val screenEvent = mixpanelDestination.screen(sampleEvent)
194198

195-
assertNotNull(screenEvent)
199+
Assertions.assertNotNull(screenEvent)
196200
verify {
197201
mockMixpanel.track(
198202
"Loaded a Screen",
@@ -232,7 +236,7 @@ class MixpanelDestinationTests {
232236
)
233237
val screenEvent = mixpanelDestination.screen(sampleEvent)
234238

235-
assertNotNull(screenEvent)
239+
Assertions.assertNotNull(screenEvent)
236240
verify {
237241
mockMixpanel.track(
238242
"Viewed LoginFragment Screen",
@@ -271,7 +275,7 @@ class MixpanelDestinationTests {
271275
)
272276
val screenEvent = mixpanelDestination.screen(sampleEvent)
273277

274-
assertNotNull(screenEvent)
278+
Assertions.assertNotNull(screenEvent)
275279
verify { mockMixpanel wasNot Called }
276280
}
277281

@@ -301,7 +305,7 @@ class MixpanelDestinationTests {
301305
)
302306
val screenEvent = mixpanelDestination.screen(sampleEvent)
303307

304-
assertNotNull(screenEvent)
308+
Assertions.assertNotNull(screenEvent)
305309
verify {
306310
mockMixpanel.track(
307311
"Viewed signup_flow Screen",
@@ -340,7 +344,7 @@ class MixpanelDestinationTests {
340344
)
341345
val screenEvent = mixpanelDestination.screen(sampleEvent)
342346

343-
assertNotNull(screenEvent)
347+
Assertions.assertNotNull(screenEvent)
344348
verify { mockMixpanel wasNot Called }
345349
}
346350

@@ -364,7 +368,7 @@ class MixpanelDestinationTests {
364368
val trackEvent = mixpanelDestination.track(sampleEvent)
365369

366370

367-
assertNotNull(trackEvent)
371+
Assertions.assertNotNull(trackEvent)
368372

369373
verify {
370374
mockMixpanel.track(
@@ -399,7 +403,7 @@ class MixpanelDestinationTests {
399403
val trackEvent = mixpanelDestination.track(sampleEvent)
400404

401405

402-
assertNotNull(trackEvent)
406+
Assertions.assertNotNull(trackEvent)
403407

404408
verify {
405409
mockMixpanel.track(
@@ -442,7 +446,7 @@ class MixpanelDestinationTests {
442446
val trackEvent = mixpanelDestination.track(sampleEvent)
443447

444448

445-
assertNotNull(trackEvent)
449+
Assertions.assertNotNull(trackEvent)
446450

447451
verify {
448452
mockMixpanel.track(
@@ -479,7 +483,7 @@ class MixpanelDestinationTests {
479483
val trackEvent = mixpanelDestination.alias(sampleEvent)
480484

481485

482-
assertNotNull(trackEvent)
486+
Assertions.assertNotNull(trackEvent)
483487

484488
verify {
485489
mockMixpanel.alias(
@@ -511,7 +515,7 @@ class MixpanelDestinationTests {
511515
val trackEvent = mixpanelDestination.alias(sampleEvent)
512516

513517

514-
assertNotNull(trackEvent)
518+
Assertions.assertNotNull(trackEvent)
515519

516520
verify {
517521
mockMixpanel.alias(
@@ -540,7 +544,7 @@ class MixpanelDestinationTests {
540544
)
541545
val identifyEvent = mixpanelDestination.identify(sampleEvent)
542546

543-
assertNotNull(identifyEvent)
547+
Assertions.assertNotNull(identifyEvent)
544548

545549
verify { mockMixpanel.identify("abc-123") }
546550
verify {
@@ -571,7 +575,7 @@ class MixpanelDestinationTests {
571575
)
572576
val identifyEvent = mixpanelDestination.identify(sampleEvent)
573577

574-
assertNotNull(identifyEvent)
578+
Assertions.assertNotNull(identifyEvent)
575579

576580
verify(exactly = 0) { mockMixpanel.identify("abc-123") }
577581
verify {
@@ -603,7 +607,7 @@ class MixpanelDestinationTests {
603607
)
604608
val identifyEvent = mixpanelDestination.identify(sampleEvent)
605609

606-
assertNotNull(identifyEvent)
610+
Assertions.assertNotNull(identifyEvent)
607611

608612
verify { mockMixpanel.identify("abc-123") }
609613
verify {
@@ -650,7 +654,7 @@ class MixpanelDestinationTests {
650654
)
651655
val identifyEvent = mixpanelDestination.identify(sampleEvent)
652656

653-
assertNotNull(identifyEvent)
657+
Assertions.assertNotNull(identifyEvent)
654658

655659
val expectedTraits = JSONObject()
656660
.put("\$email", "123@abc.com")
@@ -701,7 +705,7 @@ class MixpanelDestinationTests {
701705
)
702706
val identifyEvent = mixpanelDestination.identify(sampleEvent)
703707

704-
assertNotNull(identifyEvent)
708+
Assertions.assertNotNull(identifyEvent)
705709

706710
val expectedTraits = JSONObject()
707711
.put("\$phone", "987-654-3210")
@@ -747,7 +751,7 @@ class MixpanelDestinationTests {
747751
)
748752
val identifyEvent = mixpanelDestination.identify(sampleEvent)
749753

750-
assertNotNull(identifyEvent)
754+
Assertions.assertNotNull(identifyEvent)
751755

752756
val expectedTraits = JSONObject()
753757
.put("\$phone", "987-654-3210")
@@ -787,7 +791,7 @@ class MixpanelDestinationTests {
787791
)
788792
val groupEvent = mixpanelDestination.group(sampleEvent)
789793

790-
assertNotNull(groupEvent)
794+
Assertions.assertNotNull(groupEvent)
791795

792796
// check mixpanel getGroup called with groupKey default "[Segment] Group" and groupID "grp-123"
793797
verify { mockMixpanel.getGroup("[Segment] Group", "grp-123") }
@@ -828,7 +832,7 @@ class MixpanelDestinationTests {
828832
)
829833
val groupEvent = mixpanelDestination.group(sampleEvent)
830834

831-
assertNotNull(groupEvent)
835+
Assertions.assertNotNull(groupEvent)
832836

833837
// check mixpanel getGroup called with groupKey default "ABC network" and groupID "grp-123"
834838
verify { mockMixpanel.getGroup("ABC network", "grp-123") }

0 commit comments

Comments
 (0)