Skip to content

Commit c0a28e9

Browse files
authored
Merge pull request #4 from segment-integrations/unit_test_cases
unit_test_cases to main
2 parents 2db3946 + c4dccee commit c0a28e9

File tree

2 files changed

+369
-32
lines changed

2 files changed

+369
-32
lines changed

lib/src/main/java/com/segment/analytics/kotlin/destinations/nielsendtvr/NielsenDTVRDestination.kt

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import java.util.*
1515

1616
class NielsenDTVRDestination : DestinationPlugin() {
1717
companion object {
18-
private const val NIELSEN_DCR_FULL_KEY = "Nielsen DTVR"
18+
private const val NIELSEN_DTVR_FULL_KEY = "Nielsen DTVR"
1919
}
2020

2121
private var previousID3: String = ""
@@ -24,7 +24,7 @@ class NielsenDTVRDestination : DestinationPlugin() {
2424
internal var id3EventNames: ArrayList<String> = arrayListOf()
2525
private var id3PropertyName: String = ""
2626

27-
override val key: String = NIELSEN_DCR_FULL_KEY
27+
override val key: String = NIELSEN_DTVR_FULL_KEY
2828

2929
override fun update(settings: Settings, type: Plugin.UpdateType) {
3030
super.update(settings, type)
@@ -40,36 +40,35 @@ class NielsenDTVRDestination : DestinationPlugin() {
4040
}
4141

4242
override fun track(payload: TrackEvent): BaseEvent {
43-
if(!EventVideoEnum.isVideoEvent(payload.event)) {
44-
analytics.log("Event is not Video")
45-
return payload
46-
}
43+
val trackEnum: EventVideoEnum? = EventVideoEnum[payload.event]
4744
val nielsenProperties: Map<String, String> = payload.properties.asStringMap()
48-
when (EventVideoEnum[payload.event]) {
49-
EventVideoEnum.ContentStarted -> {
50-
play(nielsenProperties)
51-
loadMetadata(nielsenProperties)
52-
}
53-
EventVideoEnum.PlaybackResumed,
54-
EventVideoEnum.PlaybackSeekCompleted,
55-
EventVideoEnum.PlaybackBufferCompleted -> {
56-
play(nielsenProperties)
57-
}
58-
EventVideoEnum.PlaybackPaused,
59-
EventVideoEnum.PlaybackInterrupted,
60-
EventVideoEnum.ContentCompleted,
61-
EventVideoEnum.PlaybackBufferStarted,
62-
EventVideoEnum.PlaybackSeekStarted,
45+
if(trackEnum!=null) {
46+
when (trackEnum) {
47+
EventVideoEnum.ContentStarted -> {
48+
play(nielsenProperties)
49+
loadMetadata(nielsenProperties)
50+
}
51+
EventVideoEnum.PlaybackResumed,
52+
EventVideoEnum.PlaybackSeekCompleted,
53+
EventVideoEnum.PlaybackBufferCompleted -> {
54+
play(nielsenProperties)
55+
}
56+
EventVideoEnum.PlaybackPaused,
57+
EventVideoEnum.PlaybackInterrupted,
58+
EventVideoEnum.ContentCompleted,
59+
EventVideoEnum.PlaybackBufferStarted,
60+
EventVideoEnum.PlaybackSeekStarted,
6361
// Nielsen requested Video Playback Completed and new Video Playback Exited event map to stop as end is not used for DTVR
64-
EventVideoEnum.PlaybackExited,
65-
EventVideoEnum.PlaybackCompleted -> {
66-
stop()
67-
}
68-
EventVideoEnum.ApplicationBackgrounded -> {
69-
stop()
70-
}
71-
else -> {
72-
analytics.log("Video Event not found")
62+
EventVideoEnum.PlaybackExited,
63+
EventVideoEnum.PlaybackCompleted -> {
64+
stop()
65+
}
66+
EventVideoEnum.ApplicationBackgrounded -> {
67+
stop()
68+
}
69+
else -> {
70+
analytics.log("Video Event not found")
71+
}
7372
}
7473
}
7574
if (id3EventNames.contains(payload.event.lowercase(Locale.getDefault()))) {
@@ -176,7 +175,7 @@ class NielsenDTVRDestination : DestinationPlugin() {
176175

177176
internal enum class EventVideoEnum(
178177
/**
179-
* Retrieves the Neilsen DCR video event name. This is different from `enum.name()`
178+
* Retrieves the Neilsen DTVR video event name. This is different from `enum.name()`
180179
*
181180
* @return Event name.
182181
*/
@@ -209,7 +208,7 @@ internal enum class EventVideoEnum(
209208
if (names!!.containsKey(name)) {
210209
return names!![name]
211210
}
212-
throw IllegalArgumentException("$name is not a valid video event")
211+
return null
213212
}
214213
/**
215214
* Identifies if the event is a video event.

0 commit comments

Comments
 (0)