1/*
2 * Copyright (C) 2016 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.settings.notification;
17
18import android.content.ComponentName;
19import android.content.Context;
20import android.content.pm.PackageManager;
21import android.content.pm.ServiceInfo;
22import org.junit.Before;
23import org.junit.Test;
24import org.mockito.Mock;
25import org.mockito.MockitoAnnotations;
26
27import static com.google.common.truth.Truth.assertThat;
28import static org.mockito.Mockito.when;
29
30public class SuppressorHelperTest {
31    private static final String SUPPRESSOR_NAME = "wear";
32
33    private ComponentName mSuppressor;
34    @Mock
35    private Context mContext;
36    @Mock
37    private PackageManager mPackageManager;
38    @Mock
39    private ServiceInfo mServiceInfo;
40
41    @Before
42    public void setUp() {
43        MockitoAnnotations.initMocks(this);
44        mSuppressor = new ComponentName("", "");
45
46        try {
47            when(mContext.getPackageManager()).thenReturn(mPackageManager);
48            when(mPackageManager.getServiceInfo(mSuppressor, 0)).thenReturn(mServiceInfo);
49            when(mServiceInfo.loadLabel(mPackageManager)).thenReturn(new String(SUPPRESSOR_NAME));
50        } catch (PackageManager.NameNotFoundException e) {
51            // Do nothing. This exception will never happen in mock
52        }
53    }
54
55    @Test
56    public void testGetSuppressionText_SuppressorNull_ReturnNull() {
57        String text = SuppressorHelper.getSuppressionText(mContext, null);
58        assertThat(text).isNull();
59    }
60
61    @Test
62    public void testGetSuppressorCaption_SuppressorNotNull_ReturnSuppressorName() {
63        String text = SuppressorHelper.getSuppressorCaption(mContext, mSuppressor);
64        assertThat(text).isEqualTo(SUPPRESSOR_NAME);
65    }
66}
67