Skip to content

Commit

Permalink
Merge pull request #8 from aminekarimii/test-core-analytiks-module
Browse files Browse the repository at this point in the history
Test core analytiks module
  • Loading branch information
aminekarimii committed Apr 12, 2023
2 parents 37a1f05 + b773991 commit 66f9112
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ class MixpanelAnalyticsClient(
override fun pushAll() {
mixpanelClient.flush()
}
}
}
4 changes: 4 additions & 0 deletions analytiks-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20201115'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test:runner:1.5.2'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.analytiks.core.formatters

import com.analytiks.core.model.Param
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class BundleFormatterTest {
private val bundleStrategy = BundleFormatStrategy()

@Test
fun testFormatProperties() {
val properties = arrayOf(
Param("property1", "value1"),
Param("property2", "value2")
)

val result = bundleStrategy(*properties)

assertEquals("value1", result.getString("property1"))
assertEquals("value2", result.getString("property2"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class JSONFormatStrategy : FormatEventPropertiesStrategy<JSONObject>() {
class MapFormatStrategy : FormatEventPropertiesStrategy<Map<String, String>>() {
override fun formatProperties(vararg eventProperties: Param): Map<String, String> {
return eventProperties.associate { property ->
property.propertyName to property.propertyName
property.propertyName to property.propertyValue
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.analytiks.core.formatters

import com.analytiks.core.model.Param
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Test

class Formatters {

private val eventProps = arrayOf(
Param("key1", "value1"),
Param("key2", "value2"),
Param("key3", "value3")
)

private val jsonStrategy = JSONFormatStrategy()
private val mapStrategy = MapFormatStrategy()

@Test
fun `formatProperties should return JSONObject with correct properties`() {
val expectedJson = JSONObject(
mapOf(
"key1" to "value1",
"key2" to "value2",
"key3" to "value3"
)
)

val actualJson = jsonStrategy(*eventProps)

assertEquals(expectedJson.toString(), actualJson.toString())
}

@Test
fun `mapStrategy should return Map with correct properties`() {
val expectedMap = mapOf(
"key1" to "value1",
"key2" to "value2",
"key3" to "value3"
)

val actualMapProperties = mapStrategy(*eventProps)

assertEquals(expectedMap.toString(), actualMapProperties.toString())
}

}

0 comments on commit 66f9112

Please sign in to comment.