Julia Reynolds | 7bcb57b | 2018-01-22 10:37:58 -0500 | [diff] [blame] | 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.support.test.runner.AndroidJUnit4; |
| 24 | import android.test.suitebuilder.annotation.SmallTest; |
| 25 | |
| 26 | import com.android.server.UiServiceTestCase; |
| 27 | |
| 28 | import org.junit.Test; |
| 29 | import org.junit.runner.RunWith; |
| 30 | |
| 31 | @SmallTest |
| 32 | @RunWith(AndroidJUnit4.class) |
| 33 | public class NotifyingAppTest extends UiServiceTestCase { |
| 34 | |
| 35 | @Test |
| 36 | public void testConstructor() { |
| 37 | NotifyingApp na = new NotifyingApp(); |
| 38 | assertEquals(0, na.getUid()); |
| 39 | assertEquals(0, na.getLastNotified()); |
| 40 | assertEquals(null, na.getPackage()); |
| 41 | } |
| 42 | |
| 43 | @Test |
| 44 | public void testPackage() { |
| 45 | NotifyingApp na = new NotifyingApp(); |
| 46 | na.setPackage("test"); |
| 47 | assertEquals("test", na.getPackage()); |
| 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public void testUid() { |
| 52 | NotifyingApp na = new NotifyingApp(); |
| 53 | na.setUid(90); |
| 54 | assertEquals(90, na.getUid()); |
| 55 | } |
| 56 | |
| 57 | @Test |
| 58 | public void testLastNotified() { |
| 59 | NotifyingApp na = new NotifyingApp(); |
| 60 | na.setLastNotified((long) 8000); |
| 61 | assertEquals((long) 8000, na.getLastNotified()); |
| 62 | } |
| 63 | |
| 64 | @Test |
| 65 | public void testWriteToParcel() { |
| 66 | NotifyingApp na = new NotifyingApp(); |
| 67 | na.setPackage("package"); |
| 68 | na.setUid(200); |
| 69 | na.setLastNotified(4000); |
| 70 | |
| 71 | Parcel parcel = Parcel.obtain(); |
| 72 | na.writeToParcel(parcel, 0); |
| 73 | parcel.setDataPosition(0); |
| 74 | NotifyingApp na1 = NotifyingApp.CREATOR.createFromParcel(parcel); |
| 75 | assertEquals(na.getLastNotified(), na1.getLastNotified()); |
| 76 | assertEquals(na.getPackage(), na1.getPackage()); |
| 77 | assertEquals(na.getUid(), na1.getUid()); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void testCompareTo() { |
| 82 | NotifyingApp na1 = new NotifyingApp(); |
| 83 | na1.setPackage("pkg1"); |
| 84 | na1.setUid(1000); |
| 85 | na1.setLastNotified(6); |
| 86 | |
| 87 | NotifyingApp na2 = new NotifyingApp(); |
| 88 | na2.setPackage("a"); |
| 89 | na2.setUid(999); |
| 90 | na2.setLastNotified(1); |
| 91 | |
| 92 | assertTrue(na1.compareTo(na2) < 0); |
| 93 | } |
| 94 | } |