Skip to content

Commit 2b0cb2d

Browse files
committed
LIBMOBILE-1187
- code reformatted
1 parent 97676d5 commit 2b0cb2d

File tree

2 files changed

+62
-65
lines changed

2 files changed

+62
-65
lines changed

lib/src/main/java/com/segment/analytics/kotlin/destinations/nielsendcr/NielsenDCRDestination.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class NielsenDCRDestination : DestinationPlugin() {
9696
}
9797

9898
override fun screen(payload: ScreenEvent): BaseEvent {
99-
val propertiesMap = payload.properties.asStringMap() as Map<String, String>
99+
val propertiesMap = payload.properties.asStringMap()
100100
val name: String = fetchSectionProperty(propertiesMap, payload.name)
101101
val contentAssetId: String = fetchContentAssetId(propertiesMap)
102102
val metadata = JSONObject()
@@ -140,7 +140,7 @@ class NielsenDCRDestination : DestinationPlugin() {
140140
return payload
141141
}
142142
val eventEnum = EventVideoEnum[payload.event]
143-
val nielsenProperties: Map<String, String> = payload.properties.asStringMap() as Map<String, String>
143+
val nielsenProperties: Map<String, String> = payload.properties.asStringMap()
144144
val nielsenOptions: Map<String, String> = ((payload.integrations["nielsen-dcr"]
145145
?: JsonObject(emptyMap())) as JsonObject).asStringMap()
146146
when (eventEnum) {

lib/src/test/kotlin/com/segment/analytics/kotlin/destinations/nielsendcr/NielsenDCRDestinationTest.kt

Lines changed: 60 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import io.mockk.impl.annotations.MockK
1414
import kotlinx.serialization.decodeFromString
1515
import kotlinx.serialization.json.buildJsonObject
1616
import kotlinx.serialization.json.put
17-
import org.json.JSONException
1817
import org.json.JSONObject
1918
import org.junit.Assert.assertEquals
2019
import org.junit.Before
@@ -64,9 +63,11 @@ class NielsenDCRDestinationTest {
6463
}
6564
""".trimIndent()
6665
)
66+
6767
init {
6868
MockKAnnotations.init(this)
6969
}
70+
7071
@Before
7172
fun setUp() {
7273
mockedNielsenDcrDestination = NielsenDCRDestination()
@@ -88,6 +89,64 @@ class NielsenDCRDestinationTest {
8889
mockedNielsenDcrDestination.appSdk = mockedAppSdk
8990
}
9091

92+
@Test
93+
fun `screen handled correctly`() {
94+
val sampleEvent = ScreenEvent(
95+
name = "Screen 1",
96+
category = "Category 1",
97+
properties = buildJsonObject {
98+
put("variation", "New Screen")
99+
put("assetId", 123456)
100+
}
101+
).apply {
102+
anonymousId = "anonymous_UserID-123"
103+
context = emptyJsonObject
104+
integrations = emptyJsonObject
105+
}
106+
mockedNielsenDcrDestination.screen(sampleEvent)
107+
val screenExpectedMetadata = JSONObject()
108+
screenExpectedMetadata.put("assetid", "123456")
109+
screenExpectedMetadata.put("section", "Screen 1")
110+
screenExpectedMetadata.put("type", "static")
111+
screenExpectedMetadata.put("segB", "")
112+
screenExpectedMetadata.put("segC", "")
113+
verify { mockedAppSdk.loadMetadata(matchJSONObject(screenExpectedMetadata)) }
114+
}
115+
116+
@Test
117+
fun `screen handled with custom settings correctly`() {
118+
mockedNielsenDcrDestination.nielsenDCRSettings?.customSectionProperty = "customSection"
119+
mockedNielsenDcrDestination.nielsenDCRSettings?.contentAssetIdPropertyName = "customContentAssetId"
120+
val sampleEvent = ScreenEvent(
121+
name = "Screen 1",
122+
category = "Category 1",
123+
properties = buildJsonObject {
124+
put("variation", "New Screen")
125+
put("customSection", "customSection")
126+
put("customContentAssetId", 123456)
127+
}
128+
).apply {
129+
anonymousId = "anonymous_UserID-123"
130+
context = emptyJsonObject
131+
integrations = buildJsonObject {
132+
put("nielsen-dcr", buildJsonObject {
133+
put("segB", "segmentB")
134+
put("segC", "segmentC")
135+
put("crossId1", "Cross Id 1 value")
136+
})
137+
}
138+
}
139+
mockedNielsenDcrDestination.screen(sampleEvent)
140+
val screenExpectedMetadata = JSONObject()
141+
screenExpectedMetadata.put("assetid", "123456")
142+
screenExpectedMetadata.put("section", "customSection")
143+
screenExpectedMetadata.put("type", "static")
144+
screenExpectedMetadata.put("segB", "segmentB")
145+
screenExpectedMetadata.put("segC", "segmentC")
146+
screenExpectedMetadata.put("crossId1", "Cross Id 1 value")
147+
verify { mockedAppSdk.loadMetadata(matchJSONObject(screenExpectedMetadata)) }
148+
}
149+
91150
@Test
92151
fun `settings are updated correctly`() {
93152

@@ -138,7 +197,6 @@ class NielsenDCRDestinationTest {
138197
}
139198

140199
@Test
141-
@Throws(JSONException::class)
142200
fun `track for Video Playback Started with live stream handled correctly`() {
143201
val sampleEvent = TrackEvent(
144202
event = "Video Playback Started",
@@ -698,7 +756,6 @@ class NielsenDCRDestinationTest {
698756
verify { mockedAppSdk.loadMetadata(matchJSONObject(expectedMetaData)) }
699757
}
700758

701-
702759
@Test
703760
fun `track for Video Ad Started with type pre-roll handled correctly`() {
704761
val sampleEvent = TrackEvent(
@@ -827,7 +884,6 @@ class NielsenDCRDestinationTest {
827884
JSONAssert.assertEquals(adExpectedMetadata, adCaptureSlot.captured, JSONCompareMode.LENIENT)
828885
}
829886

830-
831887
@Test
832888
fun `track for Video Ad Completed handled correctly`() {
833889
val sampleEvent = TrackEvent(
@@ -848,63 +904,4 @@ class NielsenDCRDestinationTest {
848904
mockedNielsenDcrDestination.track(sampleEvent)
849905
verify{mockedAppSdk.stop()}
850906
}
851-
852-
853-
@Test
854-
fun `screen handled correctly`() {
855-
val sampleEvent = ScreenEvent(
856-
name = "Screen 1",
857-
category = "Category 1",
858-
properties = buildJsonObject {
859-
put("variation", "New Screen")
860-
put("assetId", 123456)
861-
}
862-
).apply {
863-
anonymousId = "anonymous_UserID-123"
864-
context = emptyJsonObject
865-
integrations = emptyJsonObject
866-
}
867-
mockedNielsenDcrDestination.screen(sampleEvent)
868-
val screenExpectedMetadata = JSONObject()
869-
screenExpectedMetadata.put("assetid", "123456")
870-
screenExpectedMetadata.put("section", "Screen 1")
871-
screenExpectedMetadata.put("type", "static")
872-
screenExpectedMetadata.put("segB", "")
873-
screenExpectedMetadata.put("segC", "")
874-
verify { mockedAppSdk.loadMetadata(matchJSONObject(screenExpectedMetadata)) }
875-
}
876-
877-
@Test
878-
fun `screen handled with custom settings correctly`() {
879-
mockedNielsenDcrDestination.nielsenDCRSettings?.customSectionProperty = "customSection"
880-
mockedNielsenDcrDestination.nielsenDCRSettings?.contentAssetIdPropertyName = "customContentAssetId"
881-
val sampleEvent = ScreenEvent(
882-
name = "Screen 1",
883-
category = "Category 1",
884-
properties = buildJsonObject {
885-
put("variation", "New Screen")
886-
put("customSection", "customSection")
887-
put("customContentAssetId", 123456)
888-
}
889-
).apply {
890-
anonymousId = "anonymous_UserID-123"
891-
context = emptyJsonObject
892-
integrations = buildJsonObject {
893-
put("nielsen-dcr", buildJsonObject {
894-
put("segB", "segmentB")
895-
put("segC", "segmentC")
896-
put("crossId1", "Cross Id 1 value")
897-
})
898-
}
899-
}
900-
mockedNielsenDcrDestination.screen(sampleEvent)
901-
val screenExpectedMetadata = JSONObject()
902-
screenExpectedMetadata.put("assetid", "123456")
903-
screenExpectedMetadata.put("section", "customSection")
904-
screenExpectedMetadata.put("type", "static")
905-
screenExpectedMetadata.put("segB", "segmentB")
906-
screenExpectedMetadata.put("segC", "segmentC")
907-
screenExpectedMetadata.put("crossId1", "Cross Id 1 value")
908-
verify { mockedAppSdk.loadMetadata(matchJSONObject(screenExpectedMetadata)) }
909-
}
910907
}

0 commit comments

Comments
 (0)