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.bluetooth; 18 19 import static org.mockito.ArgumentMatchers.any; 20 import static org.mockito.Mockito.spy; 21 import static org.mockito.Mockito.times; 22 import static org.mockito.Mockito.verify; 23 24 import android.content.Context; 25 26 import androidx.preference.PreferenceFragmentCompat; 27 import androidx.preference.PreferenceScreen; 28 29 import com.android.settingslib.bluetooth.CachedBluetoothDevice; 30 import com.android.settingslib.core.lifecycle.Lifecycle; 31 32 import org.junit.Ignore; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.robolectric.RobolectricTestRunner; 36 37 @RunWith(RobolectricTestRunner.class) 38 @Ignore 39 public class BluetoothDetailsControllerEventsTest extends BluetoothDetailsControllerTestBase { 40 41 @Test pauseResumeEvents()42 public void pauseResumeEvents() { 43 TestController controller = 44 spy(new TestController(mContext, mFragment, mCachedDevice, mLifecycle)); 45 verify(mLifecycle).addObserver(any(BluetoothDetailsController.class)); 46 47 showScreen(controller); 48 verify(mCachedDevice, times(1)).registerCallback(controller); 49 verify(controller, times(1)).refresh(); 50 51 controller.onPause(); 52 verify(controller, times(1)).refresh(); 53 verify(mCachedDevice).unregisterCallback(controller); 54 55 controller.onResume(); 56 verify(controller, times(2)).refresh(); 57 verify(mCachedDevice, times(2)).registerCallback(controller); 58 59 // The init function should only have been called once 60 verify(controller, times(1)).init(mScreen); 61 } 62 63 private static class TestController extends BluetoothDetailsController { TestController(Context context, PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle)64 private TestController(Context context, PreferenceFragmentCompat fragment, 65 CachedBluetoothDevice device, Lifecycle lifecycle) { 66 super(context, fragment, device, lifecycle); 67 } 68 69 @Override getPreferenceKey()70 public String getPreferenceKey() { 71 return null; 72 } 73 74 @Override init(PreferenceScreen screen)75 protected void init(PreferenceScreen screen) {} 76 77 @Override refresh()78 protected void refresh() {} 79 } 80 } 81