1 /* 2 * Copyright (C) 2020 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.keyguard; 18 19 import static org.mockito.ArgumentMatchers.eq; 20 import static org.mockito.Mockito.verify; 21 22 import android.test.suitebuilder.annotation.SmallTest; 23 import android.testing.AndroidTestingRunner; 24 25 import com.android.systemui.SysuiTestCase; 26 import com.android.systemui.statusbar.policy.ConfigurationController; 27 import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.mockito.ArgumentCaptor; 33 import org.mockito.Mock; 34 import org.mockito.MockitoAnnotations; 35 36 @SmallTest 37 @RunWith(AndroidTestingRunner.class) 38 public class KeyguardMessageAreaControllerTest extends SysuiTestCase { 39 @Mock 40 private ConfigurationController mConfigurationController; 41 @Mock 42 private KeyguardUpdateMonitor mKeyguardUpdateMonitor; 43 @Mock 44 private KeyguardMessageArea mKeyguardMessageArea; 45 46 private KeyguardMessageAreaController mMessageAreaController; 47 48 @Before setUp()49 public void setUp() throws Exception { 50 MockitoAnnotations.initMocks(this); 51 mMessageAreaController = new KeyguardMessageAreaController.Factory( 52 mKeyguardUpdateMonitor, mConfigurationController).create(mKeyguardMessageArea); 53 } 54 55 @Test onAttachedToWindow_registersConfigurationCallback()56 public void onAttachedToWindow_registersConfigurationCallback() { 57 ArgumentCaptor<ConfigurationListener> configurationListenerArgumentCaptor = 58 ArgumentCaptor.forClass(ConfigurationListener.class); 59 60 mMessageAreaController.onViewAttached(); 61 verify(mConfigurationController).addCallback(configurationListenerArgumentCaptor.capture()); 62 63 mMessageAreaController.onViewDetached(); 64 verify(mConfigurationController).removeCallback( 65 eq(configurationListenerArgumentCaptor.getValue())); 66 } 67 68 @Test onAttachedToWindow_registersKeyguardUpdateMontiorCallback()69 public void onAttachedToWindow_registersKeyguardUpdateMontiorCallback() { 70 ArgumentCaptor<KeyguardUpdateMonitorCallback> keyguardUpdateMonitorCallbackArgumentCaptor = 71 ArgumentCaptor.forClass(KeyguardUpdateMonitorCallback.class); 72 73 mMessageAreaController.onViewAttached(); 74 verify(mKeyguardUpdateMonitor).registerCallback( 75 keyguardUpdateMonitorCallbackArgumentCaptor.capture()); 76 77 mMessageAreaController.onViewDetached(); 78 verify(mKeyguardUpdateMonitor).removeCallback( 79 eq(keyguardUpdateMonitorCallbackArgumentCaptor.getValue())); 80 } 81 82 @Test testClearsTextField()83 public void testClearsTextField() { 84 mMessageAreaController.setMessage(""); 85 verify(mKeyguardMessageArea).setMessage(""); 86 } 87 } 88