Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 1 | package com.android.server.notification; |
| 2 | |
| 3 | import static android.service.notification.NotificationStats.DISMISSAL_PEEK; |
| 4 | |
| 5 | import static junit.framework.Assert.assertEquals; |
| 6 | import static junit.framework.Assert.assertFalse; |
| 7 | import static junit.framework.Assert.assertTrue; |
| 8 | |
| 9 | import android.os.Parcel; |
| 10 | import android.service.notification.NotificationStats; |
| 11 | import android.support.test.runner.AndroidJUnit4; |
| 12 | import android.test.suitebuilder.annotation.SmallTest; |
| 13 | |
Jason Monk | 74f5e36 | 2017-12-06 08:56:33 -0500 | [diff] [blame] | 14 | import com.android.server.UiServiceTestCase; |
| 15 | |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 16 | import org.junit.Test; |
| 17 | import org.junit.runner.RunWith; |
| 18 | |
| 19 | @SmallTest |
| 20 | @RunWith(AndroidJUnit4.class) |
Jason Monk | 74f5e36 | 2017-12-06 08:56:33 -0500 | [diff] [blame] | 21 | public class NotificationStatsTest extends UiServiceTestCase { |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 22 | |
| 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 | } |