Home | History | Annotate | Download | only in development
      1 /*
      2  * Copyright (C) 2018 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.development;
     18 
     19 import static com.android.settings.development.BluetoothA2dpHwOffloadPreferenceController.A2DP_OFFLOAD_DISABLED_PROPERTY;
     20 import static com.google.common.truth.Truth.assertThat;
     21 import static org.mockito.Mockito.spy;
     22 import static org.mockito.Mockito.verify;
     23 import static org.mockito.Mockito.when;
     24 
     25 import android.content.Context;
     26 import android.os.SystemProperties;
     27 import android.support.v14.preference.SwitchPreference;
     28 import android.support.v7.preference.PreferenceScreen;
     29 
     30 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     31 
     32 import org.junit.Before;
     33 import org.junit.Test;
     34 import org.junit.runner.RunWith;
     35 import org.mockito.Mock;
     36 import org.mockito.MockitoAnnotations;
     37 import org.robolectric.RuntimeEnvironment;
     38 
     39 @RunWith(SettingsRobolectricTestRunner.class)
     40 public class BluetoothA2dpHwOffloadPreferenceControllerTest {
     41 
     42     @Mock
     43     private PreferenceScreen mPreferenceScreen;
     44     @Mock
     45     private DevelopmentSettingsDashboardFragment mFragment;
     46 
     47     private Context mContext;
     48     private SwitchPreference mPreference;
     49     private BluetoothA2dpHwOffloadPreferenceController mController;
     50 
     51     @Before
     52     public void setup() {
     53         MockitoAnnotations.initMocks(this);
     54         mContext = RuntimeEnvironment.application;
     55         mPreference = new SwitchPreference(mContext);
     56         mController = spy(new BluetoothA2dpHwOffloadPreferenceController(mContext, mFragment));
     57         when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
     58             .thenReturn(mPreference);
     59         mController.displayPreference(mPreferenceScreen);
     60     }
     61 
     62     @Test
     63     public void onA2dpHwDialogConfirmed_shouldChangeProperty() {
     64         SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false));
     65 
     66         mController.onA2dpHwDialogConfirmed();
     67         final boolean mode = SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false);
     68         assertThat(mode).isTrue();
     69 
     70         mController.onA2dpHwDialogConfirmed();
     71         final boolean mode2 = SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false);
     72         assertThat(mode2).isFalse();
     73     }
     74 }
     75