blob: 4f153eed7326c51e4c158a772b0e7ca72a00bae1 [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
Jason Monk74f5e362017-12-06 08:56:33 -050014import com.android.server.UiServiceTestCase;
15
Julia Reynolds503ed942017-10-04 16:04:56 -040016import org.junit.Test;
17import org.junit.runner.RunWith;
18
19@SmallTest
20@RunWith(AndroidJUnit4.class)
Jason Monk74f5e362017-12-06 08:56:33 -050021public class NotificationStatsTest extends UiServiceTestCase {
Julia Reynolds503ed942017-10-04 16:04:56 -040022
23 @Test
24 public void testConstructor() {
25 NotificationStats stats = new NotificationStats();
26
27 assertFalse(stats.hasSeen());
28 assertFalse(stats.hasDirectReplied());
29 assertFalse(stats.hasExpanded());
30 assertFalse(stats.hasInteracted());
31 assertFalse(stats.hasViewedSettings());
32 assertFalse(stats.hasSnoozed());
33 assertEquals(NotificationStats.DISMISSAL_NOT_DISMISSED, stats.getDismissalSurface());
34 }
35
36 @Test
37 public void testSeen() {
38 NotificationStats stats = new NotificationStats();
39 stats.setSeen();
40 assertTrue(stats.hasSeen());
41 assertFalse(stats.hasInteracted());
42 }
43
44 @Test
45 public void testDirectReplied() {
46 NotificationStats stats = new NotificationStats();
47 stats.setDirectReplied();
48 assertTrue(stats.hasDirectReplied());
49 assertTrue(stats.hasInteracted());
50 }
51
52 @Test
53 public void testExpanded() {
54 NotificationStats stats = new NotificationStats();
55 stats.setExpanded();
56 assertTrue(stats.hasExpanded());
57 assertTrue(stats.hasInteracted());
58 }
59
60 @Test
61 public void testSnoozed() {
62 NotificationStats stats = new NotificationStats();
63 stats.setSnoozed();
64 assertTrue(stats.hasSnoozed());
65 assertTrue(stats.hasInteracted());
66 }
67
68 @Test
69 public void testViewedSettings() {
70 NotificationStats stats = new NotificationStats();
71 stats.setViewedSettings();
72 assertTrue(stats.hasViewedSettings());
73 assertTrue(stats.hasInteracted());
74 }
75
76 @Test
77 public void testDismissalSurface() {
78 NotificationStats stats = new NotificationStats();
79 stats.setDismissalSurface(DISMISSAL_PEEK);
80 assertEquals(DISMISSAL_PEEK, stats.getDismissalSurface());
81 assertFalse(stats.hasInteracted());
82 }
83
84 @Test
85 public void testWriteToParcel() {
86 NotificationStats stats = new NotificationStats();
87 stats.setViewedSettings();
88 stats.setDismissalSurface(NotificationStats.DISMISSAL_AOD);
89 Parcel parcel = Parcel.obtain();
90 stats.writeToParcel(parcel, 0);
91 parcel.setDataPosition(0);
92 NotificationStats stats1 = NotificationStats.CREATOR.createFromParcel(parcel);
93 assertEquals(stats, stats1);
94 }
95}