Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 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 | */ |
| 16 | |
| 17 | package com.android.server.notification; |
| 18 | |
| 19 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
| 20 | |
| 21 | import static junit.framework.Assert.assertEquals; |
| 22 | |
| 23 | import android.app.NotificationChannel; |
| 24 | import android.os.Parcel; |
| 25 | import android.support.test.runner.AndroidJUnit4; |
| 26 | import android.test.suitebuilder.annotation.SmallTest; |
| 27 | |
Julia Reynolds | 0f17000 | 2017-07-10 10:51:01 -0400 | [diff] [blame] | 28 | import com.android.internal.util.FastXmlSerializer; |
| 29 | |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 30 | import org.junit.Test; |
| 31 | import org.junit.runner.RunWith; |
Julia Reynolds | 0f17000 | 2017-07-10 10:51:01 -0400 | [diff] [blame] | 32 | import org.xmlpull.v1.XmlSerializer; |
| 33 | |
| 34 | import java.io.BufferedOutputStream; |
| 35 | import java.io.ByteArrayOutputStream; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 36 | |
| 37 | @SmallTest |
| 38 | @RunWith(AndroidJUnit4.class) |
| 39 | public class NotificationChannelTest extends NotificationTestCase { |
| 40 | |
| 41 | @Test |
| 42 | public void testWriteToParcel() { |
| 43 | NotificationChannel channel = |
| 44 | new NotificationChannel("1", "one", IMPORTANCE_DEFAULT); |
| 45 | Parcel parcel = Parcel.obtain(); |
| 46 | channel.writeToParcel(parcel, 0); |
| 47 | parcel.setDataPosition(0); |
| 48 | NotificationChannel channel1 = NotificationChannel.CREATOR.createFromParcel(parcel); |
| 49 | assertEquals(channel, channel1); |
| 50 | } |
| 51 | |
| 52 | @Test |
| 53 | public void testSystemBlockable() { |
| 54 | NotificationChannel channel = new NotificationChannel("a", "ab", IMPORTANCE_DEFAULT); |
| 55 | assertEquals(false, channel.isBlockableSystem()); |
| 56 | channel.setBlockableSystem(true); |
| 57 | assertEquals(true, channel.isBlockableSystem()); |
| 58 | } |
Julia Reynolds | 0f17000 | 2017-07-10 10:51:01 -0400 | [diff] [blame] | 59 | |
| 60 | @Test |
| 61 | public void testEmptyVibration_noException() throws Exception { |
| 62 | NotificationChannel channel = new NotificationChannel("a", "ab", IMPORTANCE_DEFAULT); |
| 63 | channel.setVibrationPattern(new long[0]); |
| 64 | |
| 65 | XmlSerializer serializer = new FastXmlSerializer(); |
| 66 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 67 | serializer.setOutput(new BufferedOutputStream(baos), "utf-8"); |
| 68 | channel.writeXml(serializer); |
| 69 | } |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 70 | } |