1 /* 2 * Copyright (C) 2021 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.applications; 18 19 import static com.android.settings.core.BasePreferenceController.AVAILABLE; 20 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; 21 22 import static com.google.common.truth.Truth.assertThat; 23 24 import static org.mockito.Mockito.spy; 25 import static org.mockito.Mockito.when; 26 27 import android.content.Context; 28 29 import com.android.settings.testutils.FakeFeatureFactory; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.mockito.MockitoAnnotations; 35 import org.robolectric.RobolectricTestRunner; 36 import org.robolectric.RuntimeEnvironment; 37 38 @RunWith(RobolectricTestRunner.class) 39 public class GameSettingsPreferenceControllerTest { 40 41 private GameSettingsPreferenceController mController; 42 private GameSettingsFeatureProvider mProvider; 43 private Context mContext; 44 45 @Before setUp()46 public void setUp() { 47 MockitoAnnotations.initMocks(this); 48 mContext = spy(RuntimeEnvironment.application); 49 50 mProvider = FakeFeatureFactory.setupForTest().getGameSettingsFeatureProvider(); 51 mController = new GameSettingsPreferenceController(mContext, "test_key", mProvider); 52 } 53 54 @Test getAvailabilityStatus_GameSettingsFeatureEnabled_shouldReturnAVAILABLE()55 public void getAvailabilityStatus_GameSettingsFeatureEnabled_shouldReturnAVAILABLE() { 56 when(mProvider.isSupported(mContext)).thenReturn(true); 57 assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); 58 } 59 60 @Test getAvailabilityStatus_GameSettingsFeatureDisabled_shouldReturnUNSUPPORTED_ON_DEVICE()61 public void getAvailabilityStatus_GameSettingsFeatureDisabled_shouldReturnUNSUPPORTED_ON_DEVICE() { 62 when(mProvider.isSupported(mContext)).thenReturn(false); 63 assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); 64 } 65 } 66