RankingHelperTest.java revision 4a24fd3c7bab53e4e9c127214e7168db0af8800a
1/* 2 * Copyright (C) 2014 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 android.app.Notification; 19import android.os.UserHandle; 20import android.service.notification.StatusBarNotification; 21import android.test.AndroidTestCase; 22import android.test.suitebuilder.annotation.SmallTest; 23 24import java.util.ArrayList; 25 26public class RankingHelperTest extends AndroidTestCase { 27 28 private Notification mNotiGroupGSortA; 29 private Notification mNotiGroupGSortB; 30 private Notification mNotiNoGroup; 31 private Notification mNotiNoGroup2; 32 private Notification mNotiNoGroupSortA; 33 private NotificationRecord mRecordGroupGSortA; 34 private NotificationRecord mRecordGroupGSortB; 35 private NotificationRecord mRecordNoGroup; 36 private NotificationRecord mRecordNoGroup2; 37 private NotificationRecord mRecordNoGroupSortA; 38 private RankingHelper mHelper; 39 40 @Override 41 public void setUp() { 42 UserHandle user = UserHandle.ALL; 43 44 mHelper = new RankingHelper(getContext(), null, new String[0]); 45 46 mNotiGroupGSortA = new Notification.Builder(getContext()) 47 .setContentTitle("A") 48 .setGroup("G") 49 .setSortKey("A") 50 .setWhen(1205) 51 .build(); 52 mRecordGroupGSortA = new NotificationRecord(new StatusBarNotification( 53 "package", "package", 1, null, 0, 0, 0, mNotiGroupGSortA, user), 0); 54 55 mNotiGroupGSortB = new Notification.Builder(getContext()) 56 .setContentTitle("B") 57 .setGroup("G") 58 .setSortKey("B") 59 .setWhen(1200) 60 .build(); 61 mRecordGroupGSortB = new NotificationRecord(new StatusBarNotification( 62 "package", "package", 1, null, 0, 0, 0, mNotiGroupGSortB, user), 0); 63 64 mNotiNoGroup = new Notification.Builder(getContext()) 65 .setContentTitle("C") 66 .setWhen(1201) 67 .build(); 68 mRecordNoGroup = new NotificationRecord(new StatusBarNotification( 69 "package", "package", 1, null, 0, 0, 0, mNotiNoGroup, user), 0); 70 71 mNotiNoGroup2 = new Notification.Builder(getContext()) 72 .setContentTitle("D") 73 .setWhen(1202) 74 .build(); 75 mRecordNoGroup2 = new NotificationRecord(new StatusBarNotification( 76 "package", "package", 1, null, 0, 0, 0, mNotiNoGroup2, user), 0); 77 78 mNotiNoGroupSortA = new Notification.Builder(getContext()) 79 .setContentTitle("E") 80 .setWhen(1201) 81 .setSortKey("A") 82 .build(); 83 mRecordNoGroupSortA = new NotificationRecord(new StatusBarNotification( 84 "package", "package", 1, null, 0, 0, 0, mNotiNoGroupSortA, user), 0); 85 } 86 87 @SmallTest 88 public void testFindAfterRankingWithASplitGroup() throws Exception { 89 ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(3); 90 notificationList.add(mRecordGroupGSortA); 91 notificationList.add(mRecordGroupGSortB); 92 notificationList.add(mRecordNoGroup); 93 notificationList.add(mRecordNoGroupSortA); 94 mHelper.sort(notificationList); 95 assertTrue(mHelper.indexOf(notificationList, mRecordGroupGSortA) >= 0); 96 assertTrue(mHelper.indexOf(notificationList, mRecordGroupGSortB) >= 0); 97 assertTrue(mHelper.indexOf(notificationList, mRecordNoGroup) >= 0); 98 assertTrue(mHelper.indexOf(notificationList, mRecordNoGroupSortA) >= 0); 99 } 100 101 @SmallTest 102 public void testSortShouldNotThrowWithPlainNotifications() throws Exception { 103 ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(2); 104 notificationList.add(mRecordNoGroup); 105 notificationList.add(mRecordNoGroup2); 106 mHelper.sort(notificationList); 107 } 108 109 @SmallTest 110 public void testSortShouldNotThrowOneSorted() throws Exception { 111 ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(2); 112 notificationList.add(mRecordNoGroup); 113 notificationList.add(mRecordNoGroupSortA); 114 mHelper.sort(notificationList); 115 } 116 117 @SmallTest 118 public void testSortShouldNotThrowOneNotification() throws Exception { 119 ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(1); 120 notificationList.add(mRecordNoGroup); 121 mHelper.sort(notificationList); 122 } 123 124 @SmallTest 125 public void testSortShouldNotThrowOneSortKey() throws Exception { 126 ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(1); 127 notificationList.add(mRecordGroupGSortB); 128 mHelper.sort(notificationList); 129 } 130 131 @SmallTest 132 public void testSortShouldNotThrowOnEmptyList() throws Exception { 133 ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(); 134 mHelper.sort(notificationList); 135 } 136} 137