1/** 2 * Copyright (c) 2017, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package com.android.server.notification; 17 18import static android.service.notification.NotificationStats.DISMISSAL_PEEK; 19 20import static junit.framework.Assert.assertEquals; 21import static junit.framework.Assert.assertFalse; 22import static junit.framework.Assert.assertTrue; 23 24import android.os.Parcel; 25import android.service.notification.NotificationStats; 26import android.support.test.runner.AndroidJUnit4; 27import android.test.suitebuilder.annotation.SmallTest; 28 29import com.android.server.UiServiceTestCase; 30 31import org.junit.Test; 32import org.junit.runner.RunWith; 33 34@SmallTest 35@RunWith(AndroidJUnit4.class) 36public class NotificationStatsTest extends UiServiceTestCase { 37 38 @Test 39 public void testConstructor() { 40 NotificationStats stats = new NotificationStats(); 41 42 assertFalse(stats.hasSeen()); 43 assertFalse(stats.hasDirectReplied()); 44 assertFalse(stats.hasExpanded()); 45 assertFalse(stats.hasInteracted()); 46 assertFalse(stats.hasViewedSettings()); 47 assertFalse(stats.hasSnoozed()); 48 assertEquals(NotificationStats.DISMISSAL_NOT_DISMISSED, stats.getDismissalSurface()); 49 } 50 51 @Test 52 public void testSeen() { 53 NotificationStats stats = new NotificationStats(); 54 stats.setSeen(); 55 assertTrue(stats.hasSeen()); 56 assertFalse(stats.hasInteracted()); 57 } 58 59 @Test 60 public void testDirectReplied() { 61 NotificationStats stats = new NotificationStats(); 62 stats.setDirectReplied(); 63 assertTrue(stats.hasDirectReplied()); 64 assertTrue(stats.hasInteracted()); 65 } 66 67 @Test 68 public void testExpanded() { 69 NotificationStats stats = new NotificationStats(); 70 stats.setExpanded(); 71 assertTrue(stats.hasExpanded()); 72 assertTrue(stats.hasInteracted()); 73 } 74 75 @Test 76 public void testSnoozed() { 77 NotificationStats stats = new NotificationStats(); 78 stats.setSnoozed(); 79 assertTrue(stats.hasSnoozed()); 80 assertTrue(stats.hasInteracted()); 81 } 82 83 @Test 84 public void testViewedSettings() { 85 NotificationStats stats = new NotificationStats(); 86 stats.setViewedSettings(); 87 assertTrue(stats.hasViewedSettings()); 88 assertTrue(stats.hasInteracted()); 89 } 90 91 @Test 92 public void testDismissalSurface() { 93 NotificationStats stats = new NotificationStats(); 94 stats.setDismissalSurface(DISMISSAL_PEEK); 95 assertEquals(DISMISSAL_PEEK, stats.getDismissalSurface()); 96 assertFalse(stats.hasInteracted()); 97 } 98 99 @Test 100 public void testWriteToParcel() { 101 NotificationStats stats = new NotificationStats(); 102 stats.setViewedSettings(); 103 stats.setDismissalSurface(NotificationStats.DISMISSAL_AOD); 104 Parcel parcel = Parcel.obtain(); 105 stats.writeToParcel(parcel, 0); 106 parcel.setDataPosition(0); 107 NotificationStats stats1 = NotificationStats.CREATOR.createFromParcel(parcel); 108 assertEquals(stats, stats1); 109 } 110} 111