Merge "Remove dead code for DataPlanUsageSummary"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c9f1d89dd3
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.widget.DonutView;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class
|
||||
}
|
||||
)
|
||||
public final class DataPlanSummaryPreferenceTest {
|
||||
|
||||
private static final String TEST_PLAN_USAGE = "Test plan usage";
|
||||
private static final String TEST_PLAN_NAME = "Test plan name";
|
||||
private static final String TEST_PLAN_DESCRIPTION = "Test plan description";
|
||||
private static int sPlanUsageTextColor;
|
||||
private static int sMeterBackgroundColor;
|
||||
private static int sMeterConsumedColor;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
sPlanUsageTextColor = Color.parseColor("#FF5C94F1");
|
||||
sMeterBackgroundColor = Color.parseColor("#FFDBDCDC");
|
||||
sMeterConsumedColor = Color.parseColor("#FF5C94F1");
|
||||
}
|
||||
|
||||
private DataPlanSummaryPreference mPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_headlineFontFamily, "");
|
||||
Context context = RuntimeEnvironment.application;
|
||||
mPreference = new DataPlanSummaryPreference(context);
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(context), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withoutData() {
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView planUsageTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(planUsageTextView.getText().toString()).isEmpty();
|
||||
TextView planNameTextView = (TextView) mHolder.findViewById(android.R.id.text1);
|
||||
assertThat(planNameTextView.getText().toString()).isEmpty();
|
||||
TextView planDescriptionTextView = (TextView) mHolder.findViewById(android.R.id.text2);
|
||||
assertThat(planDescriptionTextView.getText().toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withData() {
|
||||
mPreference.setTitle(TEST_PLAN_USAGE);
|
||||
mPreference.setUsageTextColor(sPlanUsageTextColor);
|
||||
mPreference.setName(TEST_PLAN_NAME);
|
||||
mPreference.setDescription(TEST_PLAN_DESCRIPTION);
|
||||
mPreference.setPercentageUsage(0.25D);
|
||||
mPreference.setMeterBackgroundColor(sMeterBackgroundColor);
|
||||
mPreference.setMeterConsumedColor(sMeterConsumedColor);
|
||||
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView planUsageTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(planUsageTextView.getTextColors().getDefaultColor())
|
||||
.isEqualTo(sPlanUsageTextColor);
|
||||
assertThat(planUsageTextView.getText()).isEqualTo(TEST_PLAN_USAGE);
|
||||
|
||||
TextView planNameTextView = (TextView) mHolder.findViewById(android.R.id.text1);
|
||||
assertThat(planNameTextView.getText()).isEqualTo(TEST_PLAN_NAME);
|
||||
|
||||
TextView planDescriptionTextView = (TextView) mHolder.findViewById(android.R.id.text2);
|
||||
assertThat(planDescriptionTextView.getText()).isEqualTo(TEST_PLAN_DESCRIPTION);
|
||||
|
||||
DonutView donutView = (DonutView) mHolder.findViewById(R.id.donut);
|
||||
assertThat(donutView.getMeterBackgroundColor()).isEqualTo(sMeterBackgroundColor);
|
||||
assertThat(donutView.getMeterConsumedColor()).isEqualTo(sMeterConsumedColor);
|
||||
}
|
||||
}
|
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.NetworkPolicyEditor;
|
||||
import java.util.ArrayList;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DataPlanUsageSummaryTest {
|
||||
@Mock
|
||||
private ConnectivityManager mManager;
|
||||
|
||||
private Context mContext;
|
||||
private DataPlanUsageSummary mDataUsageSummary;
|
||||
private NetworkPolicyEditor mPolicyEditor;
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
private NetworkPolicy mNetworkPolicy;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowContext = ShadowApplication.getInstance();
|
||||
shadowContext.setSystemService(Context.CONNECTIVITY_SERVICE, mManager);
|
||||
mContext = shadowContext.getApplicationContext();
|
||||
when(mManager.isNetworkSupported(anyInt())).thenReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNetworkRestrictionSummary_shouldSetSummary() {
|
||||
mDataUsageSummary = spy(new DataPlanUsageSummary());
|
||||
NetworkRestrictionsPreference preference = mock(NetworkRestrictionsPreference.class);
|
||||
mPolicyEditor = mock(NetworkPolicyEditor.class);
|
||||
WifiManager wifiManager = mock(WifiManager.class);
|
||||
ReflectionHelpers.setField(mDataUsageSummary, "mPolicyEditor", mPolicyEditor);
|
||||
ReflectionHelpers.setField(mDataUsageSummary, "mWifiManager", wifiManager);
|
||||
when(wifiManager.getConfiguredNetworks()).thenReturn(new ArrayList<>());
|
||||
doReturn(mContext.getResources()).when(mDataUsageSummary).getResources();
|
||||
|
||||
mDataUsageSummary.updateNetworkRestrictionSummary(preference);
|
||||
|
||||
verify(preference).setSummary(mContext.getResources().getQuantityString(
|
||||
R.plurals.network_restrictions_summary, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noSsid_shouldReturnFalse() {
|
||||
initTest();
|
||||
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noNetworkPolicy_shouldReturnFalse() {
|
||||
initTest();
|
||||
mWifiConfiguration.SSID = "network1";
|
||||
doReturn(null).when(mPolicyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_policyHasLimit_shouldReturnTrue() {
|
||||
initTest();
|
||||
mWifiConfiguration.SSID = "network1";
|
||||
mNetworkPolicy = mock(NetworkPolicy.class);
|
||||
mNetworkPolicy.limitBytes = 100;
|
||||
doReturn(mNetworkPolicy).when(mPolicyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noPolicyLimit_shouldReturnMeteredValue() {
|
||||
initTest();
|
||||
mWifiConfiguration.SSID = "network1";
|
||||
mNetworkPolicy = mock(NetworkPolicy.class);
|
||||
mNetworkPolicy.limitBytes = NetworkPolicy.LIMIT_DISABLED;
|
||||
doReturn(mNetworkPolicy).when(mPolicyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
mNetworkPolicy.metered = true;
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isTrue();
|
||||
|
||||
mNetworkPolicy.metered = false;
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isFalse();
|
||||
}
|
||||
|
||||
private void initTest() {
|
||||
mDataUsageSummary = new DataPlanUsageSummary();
|
||||
mPolicyEditor = mock(NetworkPolicyEditor.class);
|
||||
ReflectionHelpers.setField(mDataUsageSummary, "mPolicyEditor", mPolicyEditor);
|
||||
mWifiConfiguration = mock(WifiConfiguration.class);
|
||||
}
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
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.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class DataPlansSyncTimePreferenceTest {
|
||||
private static final String SYNC_TIME = "Today 12:24pm";
|
||||
|
||||
private Preference mPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Context context = RuntimeEnvironment.application;
|
||||
mPreference = new Preference(context);
|
||||
mPreference.setLayoutResource(R.layout.data_plans_sync_time_preference);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(context), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withData() {
|
||||
mPreference.setTitle(SYNC_TIME);
|
||||
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView syncTimeTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(syncTimeTextView.getText()).isEqualTo(SYNC_TIME);
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
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.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class ManageDataPlansPreferenceTest {
|
||||
private Preference mPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setLayoutResource(R.layout.manage_data_plans_preference);
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(mContext), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withData() {
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
Button managePlanButton = (Button) mHolder.findViewById(R.id.manage_data_plans);
|
||||
assertThat(managePlanButton.getText())
|
||||
.isEqualTo(mContext.getString(R.string.data_plan_usage_manage_plans_button_text));
|
||||
}
|
||||
}
|
@@ -27,7 +27,6 @@ import com.android.settings.bluetooth.BluetoothFeatureProvider;
|
||||
import com.android.settings.connecteddevice.SmsMirroringFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.datausage.DataPlanFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.gestures.AssistGestureFeatureProvider;
|
||||
@@ -62,7 +61,6 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public final UserFeatureProvider userFeatureProvider;
|
||||
public final AssistGestureFeatureProvider assistGestureFeatureProvider;
|
||||
public final BluetoothFeatureProvider bluetoothFeatureProvider;
|
||||
public final DataPlanFeatureProvider dataPlanFeatureProvider;
|
||||
public final SmsMirroringFeatureProvider smsMirroringFeatureProvider;
|
||||
public final SlicesFeatureProvider slicesFeatureProvider;
|
||||
public SearchFeatureProvider searchFeatureProvider;
|
||||
@@ -103,7 +101,6 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
userFeatureProvider = mock(UserFeatureProvider.class);
|
||||
assistGestureFeatureProvider = mock(AssistGestureFeatureProvider.class);
|
||||
bluetoothFeatureProvider = mock(BluetoothFeatureProvider.class);
|
||||
dataPlanFeatureProvider = mock(DataPlanFeatureProvider.class);
|
||||
smsMirroringFeatureProvider = mock(SmsMirroringFeatureProvider.class);
|
||||
slicesFeatureProvider = mock(SlicesFeatureProvider.class);
|
||||
mAccountFeatureProvider = mock(AccountFeatureProvider.class);
|
||||
@@ -174,11 +171,6 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
return bluetoothFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataPlanFeatureProvider getDataPlanFeatureProvider() {
|
||||
return dataPlanFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssistGestureFeatureProvider getAssistGestureFeatureProvider() {
|
||||
return assistGestureFeatureProvider;
|
||||
|
Reference in New Issue
Block a user