blob: 25e10d0740da804d21ed23fb674febf2390ec266 [file] [log] [blame]
Julia Reynolds7bcb57b2018-01-22 10:37:58 -05001/**
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 */
16package com.android.server.notification;
17
18import static junit.framework.Assert.assertEquals;
19import static junit.framework.Assert.assertTrue;
20
21import android.os.Parcel;
22import android.service.notification.NotifyingApp;
Julia Reynolds7bcb57b2018-01-22 10:37:58 -050023import android.test.suitebuilder.annotation.SmallTest;
24
Brett Chabot84151d92019-02-27 15:37:59 -080025import androidx.test.runner.AndroidJUnit4;
26
Julia Reynolds7bcb57b2018-01-22 10:37:58 -050027import com.android.server.UiServiceTestCase;
28
29import org.junit.Test;
30import org.junit.runner.RunWith;
31
32@SmallTest
33@RunWith(AndroidJUnit4.class)
34public class NotifyingAppTest extends UiServiceTestCase {
35
36 @Test
37 public void testConstructor() {
38 NotifyingApp na = new NotifyingApp();
39 assertEquals(0, na.getUid());
40 assertEquals(0, na.getLastNotified());
41 assertEquals(null, na.getPackage());
42 }
43
44 @Test
45 public void testPackage() {
46 NotifyingApp na = new NotifyingApp();
47 na.setPackage("test");
48 assertEquals("test", na.getPackage());
49 }
50
51 @Test
52 public void testUid() {
53 NotifyingApp na = new NotifyingApp();
54 na.setUid(90);
55 assertEquals(90, na.getUid());
56 }
57
58 @Test
59 public void testLastNotified() {
60 NotifyingApp na = new NotifyingApp();
61 na.setLastNotified((long) 8000);
62 assertEquals((long) 8000, na.getLastNotified());
63 }
64
65 @Test
66 public void testWriteToParcel() {
67 NotifyingApp na = new NotifyingApp();
68 na.setPackage("package");
69 na.setUid(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.getUid(), na1.getUid());
79 }
80
81 @Test
82 public void testCompareTo() {
83 NotifyingApp na1 = new NotifyingApp();
84 na1.setPackage("pkg1");
85 na1.setUid(1000);
86 na1.setLastNotified(6);
87
88 NotifyingApp na2 = new NotifyingApp();
89 na2.setPackage("a");
90 na2.setUid(999);
91 na2.setLastNotified(1);
92
93 assertTrue(na1.compareTo(na2) < 0);
94 }
95}