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