1 /** 2 * Copyright (c) 2018, 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 */ 16 package com.android.server.notification; 17 18 import static junit.framework.Assert.assertEquals; 19 import static junit.framework.Assert.assertTrue; 20 21 import android.os.Parcel; 22 import android.service.notification.NotifyingApp; 23 import android.test.suitebuilder.annotation.SmallTest; 24 25 import androidx.test.runner.AndroidJUnit4; 26 27 import com.android.server.UiServiceTestCase; 28 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 32 @SmallTest 33 @RunWith(AndroidJUnit4.class) 34 public class NotifyingAppTest extends UiServiceTestCase { 35 36 @Test testConstructor()37 public void testConstructor() { 38 NotifyingApp na = new NotifyingApp(); 39 assertEquals(0, na.getUserId()); 40 assertEquals(0, na.getLastNotified()); 41 assertEquals(null, na.getPackage()); 42 } 43 44 @Test testPackage()45 public void testPackage() { 46 NotifyingApp na = new NotifyingApp(); 47 na.setPackage("test"); 48 assertEquals("test", na.getPackage()); 49 } 50 51 @Test testUserId()52 public void testUserId() { 53 NotifyingApp na = new NotifyingApp(); 54 na.setUserId(90); 55 assertEquals(90, na.getUserId()); 56 } 57 58 @Test testLastNotified()59 public void testLastNotified() { 60 NotifyingApp na = new NotifyingApp(); 61 na.setLastNotified((long) 8000); 62 assertEquals((long) 8000, na.getLastNotified()); 63 } 64 65 @Test testWriteToParcel()66 public void testWriteToParcel() { 67 NotifyingApp na = new NotifyingApp(); 68 na.setPackage("package"); 69 na.setUserId(200); 70 na.setLastNotified(4000); 71 72 Parcel parcel = Parcel.obtain(); 73 na.writeToParcel(parcel, 0); 74 parcel.setDataPosition(0); 75 NotifyingApp na1 = NotifyingApp.CREATOR.createFromParcel(parcel); 76 assertEquals(na.getLastNotified(), na1.getLastNotified()); 77 assertEquals(na.getPackage(), na1.getPackage()); 78 assertEquals(na.getUserId(), na1.getUserId()); 79 } 80 81 @Test testCompareTo()82 public void testCompareTo() { 83 NotifyingApp na1 = new NotifyingApp(); 84 na1.setPackage("pkg1"); 85 na1.setUserId(1000); 86 na1.setLastNotified(6); 87 88 NotifyingApp na2 = new NotifyingApp(); 89 na2.setPackage("a"); 90 na2.setUserId(999); 91 na2.setLastNotified(1); 92 93 assertTrue(na1.compareTo(na2) < 0); 94 } 95 } 96