Skip to content

Commit

Permalink
Merge pull request #3 from segment-integrations/wenxi/resolve-package…
Browse files Browse the repository at this point in the history
…-collison

resolve package collison
  • Loading branch information
wenxi-zeng authored Mar 8, 2022
2 parents 09a6ebd + ee58fb9 commit b70219c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ implementation("com.segment.analytics.kotlin.destinations:mixpanel:1.4.4")
Open the file where you setup and configure the Analytics-Kotlin library. Add this plugin to the list of imports.

```
import com.segment.analytics.kotlin.destinations.plugins.MixpanelDestination
import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelDestination
```

Just under your Analytics-Kotlin library setup, call `analytics.add(plugin = ...)` to add an instance of the plugin to the Analytics timeline.
Expand Down
6 changes: 5 additions & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ plugins {
id("mvn-publish")
}

val VERSION_NAME: String by project

android {
compileSdk = 31
buildToolsVersion = "31.0.0"
Expand All @@ -17,6 +19,8 @@ android {

testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles("proguard-consumer-rules.pro")

buildConfigField("String", "VERSION_NAME", "\"$VERSION_NAME\"")
}

buildTypes {
Expand All @@ -38,7 +42,7 @@ android {
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")

implementation("com.segment.analytics.kotlin:android:1.4.3")
implementation("com.segment.analytics.kotlin:android:1.5.0")
implementation("androidx.multidex:multidex:2.0.1")

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

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry

import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand All @@ -19,6 +17,9 @@ class ExampleInstrumentedTest {
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.segment.analytics.kotlin.destinations.plugins.test", appContext.packageName)
Assert.assertEquals(
"com.segment.analytics.kotlin.destinations.mixpanel.test",
appContext.packageName
)
}
}
2 changes: 1 addition & 1 deletion lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.segment.analytics.kotlin.destinations.plugins">
package="com.segment.analytics.kotlin.destinations.mixpanel">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.segment.analytics.kotlin.destinations.plugins
package com.segment.analytics.kotlin.destinations.mixpanel

import android.app.Activity
import android.content.Context
Expand All @@ -9,6 +9,7 @@ import com.segment.analytics.kotlin.android.utilities.toJSONObject
import com.segment.analytics.kotlin.core.*
import com.segment.analytics.kotlin.core.platform.DestinationPlugin
import com.segment.analytics.kotlin.core.platform.Plugin
import com.segment.analytics.kotlin.core.platform.VersionedPlugin
import com.segment.analytics.kotlin.core.platform.plugins.logger.*
import com.segment.analytics.kotlin.core.utilities.*
import kotlinx.serialization.*
Expand Down Expand Up @@ -67,7 +68,7 @@ data class MixpanelSettings(

class MixpanelDestination(
private val context: Context
) : DestinationPlugin(), AndroidLifecycle {
) : DestinationPlugin(), AndroidLifecycle, VersionedPlugin {

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

override fun version(): String {
return BuildConfig.VERSION_NAME
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.segment.analytics.kotlin.destinations.plugins
package com.segment.analytics.kotlin.destinations.mixpanel

import android.content.Context
import com.mixpanel.android.mpmetrics.MixpanelAPI
import com.segment.analytics.kotlin.core.*
import com.segment.analytics.kotlin.core.platform.Plugin
import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelDestination
import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelSettings
import io.mockk.*
import io.mockk.impl.annotations.MockK
import kotlinx.serialization.decodeFromString
Expand All @@ -12,12 +14,11 @@ import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import org.json.JSONException
import org.json.JSONObject
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.skyscreamer.jsonassert.JSONAssert
import org.skyscreamer.jsonassert.JSONCompareMode


class MixpanelDestinationTests {

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

/* assertions about config */
assertNotNull(mixpanelDestination.settings)
Assertions.assertNotNull(mixpanelDestination.settings)
with(mixpanelDestination.settings!!) {
assertFalse(consolidatedPageCalls)
assertTrue(isPeopleEnabled)
assertFalse(trackAllPages)
assertTrue(trackCategorizedPages)
assertFalse(trackNamedPages)
assertFalse(setAllTraitsByDefault)
Assertions.assertFalse(consolidatedPageCalls)
Assertions.assertTrue(isPeopleEnabled)
Assertions.assertFalse(trackAllPages)
Assertions.assertTrue(trackCategorizedPages)
Assertions.assertFalse(trackNamedPages)
Assertions.assertFalse(setAllTraitsByDefault)

assertEquals("token1234", token)
Assertions.assertEquals("token1234", token)

assertEquals(emptySet<String>(), superPropertiesFilter)
assertEquals(setOf("email", "username", "phone_number"), peoplePropertiesFilter)
assertEquals(setOf("Product Clicked", "Product Viewed"), increments)
Assertions.assertEquals(emptySet<String>(), superPropertiesFilter)
Assertions.assertEquals(
setOf("email", "username", "phone_number"),
peoplePropertiesFilter
)
Assertions.assertEquals(setOf("Product Clicked", "Product Viewed"), increments)
}
}

Expand Down Expand Up @@ -125,7 +129,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)

assertNotNull(screenEvent)
Assertions.assertNotNull(screenEvent)
verify { mockMixpanel wasNot Called }
}

Expand Down Expand Up @@ -154,7 +158,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)

assertNotNull(screenEvent)
Assertions.assertNotNull(screenEvent)
verify {
mockMixpanel.track(
"Viewed LoginFragment Screen",
Expand Down Expand Up @@ -192,7 +196,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)

assertNotNull(screenEvent)
Assertions.assertNotNull(screenEvent)
verify {
mockMixpanel.track(
"Loaded a Screen",
Expand Down Expand Up @@ -232,7 +236,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)

assertNotNull(screenEvent)
Assertions.assertNotNull(screenEvent)
verify {
mockMixpanel.track(
"Viewed LoginFragment Screen",
Expand Down Expand Up @@ -271,7 +275,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)

assertNotNull(screenEvent)
Assertions.assertNotNull(screenEvent)
verify { mockMixpanel wasNot Called }
}

Expand Down Expand Up @@ -301,7 +305,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)

assertNotNull(screenEvent)
Assertions.assertNotNull(screenEvent)
verify {
mockMixpanel.track(
"Viewed signup_flow Screen",
Expand Down Expand Up @@ -340,7 +344,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)

assertNotNull(screenEvent)
Assertions.assertNotNull(screenEvent)
verify { mockMixpanel wasNot Called }
}

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


assertNotNull(trackEvent)
Assertions.assertNotNull(trackEvent)

verify {
mockMixpanel.track(
Expand Down Expand Up @@ -399,7 +403,7 @@ class MixpanelDestinationTests {
val trackEvent = mixpanelDestination.track(sampleEvent)


assertNotNull(trackEvent)
Assertions.assertNotNull(trackEvent)

verify {
mockMixpanel.track(
Expand Down Expand Up @@ -442,7 +446,7 @@ class MixpanelDestinationTests {
val trackEvent = mixpanelDestination.track(sampleEvent)


assertNotNull(trackEvent)
Assertions.assertNotNull(trackEvent)

verify {
mockMixpanel.track(
Expand Down Expand Up @@ -479,7 +483,7 @@ class MixpanelDestinationTests {
val trackEvent = mixpanelDestination.alias(sampleEvent)


assertNotNull(trackEvent)
Assertions.assertNotNull(trackEvent)

verify {
mockMixpanel.alias(
Expand Down Expand Up @@ -511,7 +515,7 @@ class MixpanelDestinationTests {
val trackEvent = mixpanelDestination.alias(sampleEvent)


assertNotNull(trackEvent)
Assertions.assertNotNull(trackEvent)

verify {
mockMixpanel.alias(
Expand Down Expand Up @@ -540,7 +544,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)

assertNotNull(identifyEvent)
Assertions.assertNotNull(identifyEvent)

verify { mockMixpanel.identify("abc-123") }
verify {
Expand Down Expand Up @@ -571,7 +575,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)

assertNotNull(identifyEvent)
Assertions.assertNotNull(identifyEvent)

verify(exactly = 0) { mockMixpanel.identify("abc-123") }
verify {
Expand Down Expand Up @@ -603,7 +607,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)

assertNotNull(identifyEvent)
Assertions.assertNotNull(identifyEvent)

verify { mockMixpanel.identify("abc-123") }
verify {
Expand Down Expand Up @@ -650,7 +654,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)

assertNotNull(identifyEvent)
Assertions.assertNotNull(identifyEvent)

val expectedTraits = JSONObject()
.put("\$email", "123@abc.com")
Expand Down Expand Up @@ -701,7 +705,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)

assertNotNull(identifyEvent)
Assertions.assertNotNull(identifyEvent)

val expectedTraits = JSONObject()
.put("\$phone", "987-654-3210")
Expand Down Expand Up @@ -747,7 +751,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)

assertNotNull(identifyEvent)
Assertions.assertNotNull(identifyEvent)

val expectedTraits = JSONObject()
.put("\$phone", "987-654-3210")
Expand Down Expand Up @@ -787,7 +791,7 @@ class MixpanelDestinationTests {
)
val groupEvent = mixpanelDestination.group(sampleEvent)

assertNotNull(groupEvent)
Assertions.assertNotNull(groupEvent)

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

assertNotNull(groupEvent)
Assertions.assertNotNull(groupEvent)

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

0 comments on commit b70219c

Please sign in to comment.