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.settings.notification; 18 19 import static com.android.settings.notification.ConfigureNotificationSettings.SUMMARY_PROVIDER_FACTORY; 20 21 import static com.google.common.truth.Truth.assertThat; 22 23 import static org.mockito.ArgumentMatchers.any; 24 import static org.mockito.Mockito.mock; 25 import static org.mockito.Mockito.spy; 26 import static org.mockito.Mockito.verify; 27 import static org.mockito.Mockito.when; 28 29 import android.app.Activity; 30 31 import com.android.settings.dashboard.SummaryLoader; 32 import com.android.settings.notification.ConfigureNotificationSettings.SummaryProvider; 33 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.mockito.ArgumentCaptor; 38 import org.robolectric.Robolectric; 39 import org.robolectric.RobolectricTestRunner; 40 41 @RunWith(RobolectricTestRunner.class) 42 public class ConfigureNotificationSettingsTest { 43 44 private Activity mActivity; 45 46 @Before setUp()47 public void setUp() { 48 mActivity = spy(Robolectric.buildActivity(Activity.class).get()); 49 } 50 51 @Test getSummary_noneBlocked()52 public void getSummary_noneBlocked() { 53 SummaryLoader loader = mock(SummaryLoader.class); 54 NotificationBackend backend = mock(NotificationBackend.class); 55 when(backend.getBlockedAppCount()).thenReturn(0); 56 SummaryProvider provider = 57 (SummaryProvider) SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader); 58 provider.setBackend(backend); 59 60 provider.setListening(true); 61 62 ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class); 63 verify(loader).setSummary(any(), captor.capture()); 64 65 assertThat(captor.getValue().toString()).contains("On"); 66 } 67 68 @Test getSummary_someBlocked()69 public void getSummary_someBlocked() { 70 SummaryLoader loader = mock(SummaryLoader.class); 71 NotificationBackend backend = mock(NotificationBackend.class); 72 when(backend.getBlockedAppCount()).thenReturn(5); 73 SummaryProvider provider = 74 (SummaryProvider) SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader); 75 provider.setBackend(backend); 76 77 provider.setListening(true); 78 79 ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class); 80 verify(loader).setSummary(any(), captor.capture()); 81 82 assertThat(captor.getValue().toString()).contains("Off"); 83 assertThat(captor.getValue().toString()).contains("5"); 84 } 85 } 86