Clean up SystemUpdatePreferences tests.

SystemUpdatePrefenceControllerTest had some logic that seemed irrelevant
to its testing class, which seems to have moved to
AdditionalSystemUpdatePreferenceController. Removed the irrelevant
test cases and added additional test coverage on
AdditionalSystemUpdatePreferenceController.

Bug: None
Test: RunSettingsRoboTests
Change-Id: I5224900bc3449a9f329a1d02ee3cb597b4748d91
This commit is contained in:
Ben Lin
2018-01-23 12:01:19 -08:00
parent 0608d2dc9d
commit 2a63861a52
3 changed files with 74 additions and 17 deletions

View File

@@ -20,6 +20,7 @@
<bool name="config_show_camera_laser_sensor">false</bool> <bool name="config_show_camera_laser_sensor">false</bool>
<bool name="config_show_connectivity_monitor">false</bool> <bool name="config_show_connectivity_monitor">false</bool>
<bool name="config_display_recent_apps">false</bool> <bool name="config_display_recent_apps">false</bool>
<bool name="config_additional_system_update_setting_enable">true</bool>
<bool name="config_show_wifi_settings">false</bool> <bool name="config_show_wifi_settings">false</bool>
<bool name="config_show_toggle_airplane">false</bool> <bool name="config_show_toggle_airplane">false</bool>
<bool name="config_show_high_power_apps">false</bool> <bool name="config_show_high_power_apps">false</bool>

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.deviceinfo;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AdditionalSystemUpdatePreferenceControllerTest {
private Context mContext;
private AdditionalSystemUpdatePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new AdditionalSystemUpdatePreferenceController(mContext);
}
@Test
public void displayPrefs_ifNotAvailable_shouldNotDisplay() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
@Config(qualifiers = "mcc999")
public void displayPrefs_ifAvailable_shouldDisplay() {
assertThat(mController.isAvailable()).isTrue();
}
}

View File

@@ -66,12 +66,9 @@ public class SystemUpdatePreferenceControllerTest {
} }
@Test @Test
public void updateNonIndexable_bothAvailable_shouldNotUpdate() { public void updateNonIndexable_ifAvailable_shouldNotUpdate() {
final List<String> keys = new ArrayList<>(); final List<String> keys = new ArrayList<>();
when(mUserManager.isAdminUser()).thenReturn(true); when(mUserManager.isAdminUser()).thenReturn(true);
when(mContext.getResources().getBoolean(
R.bool.config_additional_system_update_setting_enable))
.thenReturn(true);
mController.updateNonIndexableKeys(keys); mController.updateNonIndexableKeys(keys);
@@ -79,7 +76,8 @@ public class SystemUpdatePreferenceControllerTest {
} }
@Test @Test
public void updateNonIndexable_nothingAvailable_shouldUpdateWith2Prefs() { public void updateNonIndexable_ifNotAvailable_shouldUpdate() {
// mUserManager.isAdminUser() returns false here
final List<String> keys = new ArrayList<>(); final List<String> keys = new ArrayList<>();
mController.updateNonIndexableKeys(keys); mController.updateNonIndexableKeys(keys);
@@ -88,12 +86,22 @@ public class SystemUpdatePreferenceControllerTest {
} }
@Test @Test
public void displayPrefs_nothingAvailable_shouldNotDisplay() { public void displayPrefs_ifNotAvailable_shouldNotDisplay() {
// mUserManager.isAdminUser() returns false here
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isFalse(); assertThat(mPreference.isVisible()).isFalse();
} }
@Test
public void displayPrefs_ifAvailable_shouldDisplay() {
when(mUserManager.isAdminUser()).thenReturn(true);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isTrue();
}
@Test @Test
public void updateState_shouldSetToAndroidVersion() { public void updateState_shouldSetToAndroidVersion() {
mController = new SystemUpdatePreferenceController(RuntimeEnvironment.application); mController = new SystemUpdatePreferenceController(RuntimeEnvironment.application);
@@ -104,15 +112,4 @@ public class SystemUpdatePreferenceControllerTest {
.isEqualTo(RuntimeEnvironment.application.getString(R.string.about_summary, .isEqualTo(RuntimeEnvironment.application.getString(R.string.about_summary,
Build.VERSION.RELEASE)); Build.VERSION.RELEASE));
} }
@Test
public void displayPrefs_oneAvailable_shouldDisplayOne() {
when(mContext.getResources().getBoolean(
R.bool.config_additional_system_update_setting_enable))
.thenReturn(true);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isFalse();
}
} }