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
17package com.android.server.notification;
18
19import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
20
21import static junit.framework.Assert.assertEquals;
22
23import android.app.NotificationChannel;
24import android.os.Parcel;
25import android.support.test.runner.AndroidJUnit4;
26import android.test.suitebuilder.annotation.SmallTest;
27
28import com.android.internal.util.FastXmlSerializer;
29
30import org.junit.Test;
31import org.junit.runner.RunWith;
32import org.xmlpull.v1.XmlSerializer;
33
34import java.io.BufferedOutputStream;
35import java.io.ByteArrayOutputStream;
36
37@SmallTest
38@RunWith(AndroidJUnit4.class)
39public 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    }
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    }
70}
71