-
Notifications
You must be signed in to change notification settings - Fork 63
/
MessageNotificationTest.java
55 lines (48 loc) · 2.96 KB
/
MessageNotificationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.snowplowanalytics.snowplow.event;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@RunWith(AndroidJUnit4.class)
public class MessageNotificationTest {
@Test
public void testExpectedForm() {
MessageNotification event = new MessageNotification("title", "body", MessageNotificationTrigger.push)
.notificationTimestamp("2020-12-31T15:59:60-08:00")
.action("action")
.bodyLocKey("loc key")
.bodyLocArgs(Arrays.asList("loc arg1", "loc arg2"))
.sound("chime.mp3")
.notificationCount(9)
.category("category1")
.attachments(Arrays.asList(new MessageNotificationAttachment("id", "type", "url")));
Map<String, Object> payload = event.getDataPayload();
assertNotNull(payload);
assertEquals("title", payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_TITLE));
assertEquals("body", payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_BODY));
assertEquals("push", payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_TRIGGER));
assertEquals("2020-12-31T15:59:60-08:00", payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_NOTIFICATIONTIMESTAMP));
assertEquals("action", payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_ACTION));
assertEquals("loc key", payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_BODYLOCKEY));
List<String> locArgs = (List<String>)payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_BODYLOCARGS);
assertNotNull(locArgs);
assertEquals(2, locArgs.size());
assertEquals("loc arg1", locArgs.get(0));
assertEquals("loc arg2", locArgs.get(1));
assertEquals("chime.mp3", payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_SOUND));
assertEquals(9, payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_NOTIFICATIONCOUNT));
assertEquals("category1", payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_CATEGORY));
List<MessageNotificationAttachment> attachments = (List<MessageNotificationAttachment>)payload.get(MessageNotification.PARAM_MESSAGENOTIFICATION_MESSAGENOTIFICATIONATTACHMENTS);
assertNotNull(attachments);
assertEquals(1, attachments.size());
MessageNotificationAttachment attachment = attachments.get(0);
assertEquals("id", attachment.get(MessageNotificationAttachment.PARAM_MESSAGENOTIFICATIONATTACHMENT_IDENTIFIER));
assertEquals("type", attachment.get(MessageNotificationAttachment.PARAM_MESSAGENOTIFICATIONATTACHMENT_TYPE));
assertEquals("url", attachment.get(MessageNotificationAttachment.PARAM_MESSAGENOTIFICATIONATTACHMENT_URL));
}
}