blob: fec28115b418acd4ca86baa26d3a4c20f16d61e1 [file] [log] [blame]
Julia Reynolds503ed942017-10-04 16:04:56 -04001package com.android.server.notification;
2
3import static android.service.notification.NotificationStats.DISMISSAL_PEEK;
4
5import static junit.framework.Assert.assertEquals;
6import static junit.framework.Assert.assertFalse;
7import static junit.framework.Assert.assertTrue;
8
9import android.os.Parcel;
10import android.service.notification.NotificationStats;
11import android.support.test.runner.AndroidJUnit4;
12import android.test.suitebuilder.annotation.SmallTest;
13
14import org.junit.Test;
15import org.junit.runner.RunWith;
16
17@SmallTest
18@RunWith(AndroidJUnit4.class)
19public class NotificationStatsTest extends NotificationTestCase {
20
21 @Test
22 public void testConstructor() {
23 NotificationStats stats = new NotificationStats();
24
25 assertFalse(stats.hasSeen());
26 assertFalse(stats.hasDirectReplied());
27 assertFalse(stats.hasExpanded());
28 assertFalse(stats.hasInteracted());
29 assertFalse(stats.hasViewedSettings());
30 assertFalse(stats.hasSnoozed());
31 assertEquals(NotificationStats.DISMISSAL_NOT_DISMISSED, stats.getDismissalSurface());
32 }
33
34 @Test
35 public void testSeen() {
36 NotificationStats stats = new NotificationStats();
37 stats.setSeen();
38 assertTrue(stats.hasSeen());
39 assertFalse(stats.hasInteracted());
40 }
41
42 @Test
43 public void testDirectReplied() {
44 NotificationStats stats = new NotificationStats();
45 stats.setDirectReplied();
46 assertTrue(stats.hasDirectReplied());
47 assertTrue(stats.hasInteracted());
48 }
49
50 @Test
51 public void testExpanded() {
52 NotificationStats stats = new NotificationStats();
53 stats.setExpanded();
54 assertTrue(stats.hasExpanded());
55 assertTrue(stats.hasInteracted());
56 }
57
58 @Test
59 public void testSnoozed() {
60 NotificationStats stats = new NotificationStats();
61 stats.setSnoozed();
62 assertTrue(stats.hasSnoozed());
63 assertTrue(stats.hasInteracted());
64 }
65
66 @Test
67 public void testViewedSettings() {
68 NotificationStats stats = new NotificationStats();
69 stats.setViewedSettings();
70 assertTrue(stats.hasViewedSettings());
71 assertTrue(stats.hasInteracted());
72 }
73
74 @Test
75 public void testDismissalSurface() {
76 NotificationStats stats = new NotificationStats();
77 stats.setDismissalSurface(DISMISSAL_PEEK);
78 assertEquals(DISMISSAL_PEEK, stats.getDismissalSurface());
79 assertFalse(stats.hasInteracted());
80 }
81
82 @Test
83 public void testWriteToParcel() {
84 NotificationStats stats = new NotificationStats();
85 stats.setViewedSettings();
86 stats.setDismissalSurface(NotificationStats.DISMISSAL_AOD);
87 Parcel parcel = Parcel.obtain();
88 stats.writeToParcel(parcel, 0);
89 parcel.setDataPosition(0);
90 NotificationStats stats1 = NotificationStats.CREATOR.createFromParcel(parcel);
91 assertEquals(stats, stats1);
92 }
93}