Remove Settings robolectric tests which also have a junit test.
Before the JUnit test suite was a blocking presubmit, new junit tests would be written without removing the old robolectric test. Now that the JUnit tests are productionized, we can remove the robolectric tests if there is also an associated Junit one. Utility script which was used to generate this list can be found at https://paste.googleplex.com/5113068112576512. Bug: 175389659 Test: atest SettingsUnitTests Change-Id: Iabf4dbcccd573e9e1482b3a3e61c0f169f81bcb4
This commit is contained in:
@@ -1,82 +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.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AppPrefLoaderTest {
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
private AppPrefLoader mLoader;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
final ArraySet<String> pkgs = new ArraySet<>(2);
|
||||
pkgs.add("pkg0");
|
||||
pkgs.add("pkg1");
|
||||
mLoader = new AppPrefLoader(RuntimeEnvironment.application, pkgs, mPackageManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadInBackground_packageNotFound_shouldReturnEmptySet()
|
||||
throws NameNotFoundException {
|
||||
when(mPackageManager.getApplicationInfo(anyString(), anyInt()))
|
||||
.thenThrow(new NameNotFoundException());
|
||||
|
||||
assertThat(mLoader.loadInBackground()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadInBackground_shouldReturnPreference() throws NameNotFoundException {
|
||||
ApplicationInfo info = mock(ApplicationInfo.class);
|
||||
when(mPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn(info);
|
||||
final Drawable drawable = mock(Drawable.class);
|
||||
final String label = "Label1";
|
||||
when(info.loadIcon(mPackageManager)).thenReturn(drawable);
|
||||
when(info.loadLabel(mPackageManager)).thenReturn(label);
|
||||
|
||||
Preference preference = mLoader.loadInBackground().valueAt(0);
|
||||
assertThat(preference.getTitle()).isEqualTo(label);
|
||||
assertThat(preference.getIcon()).isEqualTo(drawable);
|
||||
assertThat(preference.isSelectable()).isFalse();
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.network.ProxySubscriptionManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class CellDataPreferenceTest {
|
||||
|
||||
@Mock
|
||||
private ProxySubscriptionManager mProxySubscriptionMgr;
|
||||
@Mock
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@Mock
|
||||
private SubscriptionInfo mSubInfo;
|
||||
|
||||
private Context mContext;
|
||||
private PreferenceViewHolder mHolder;
|
||||
private CellDataPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreference = new CellDataPreference(mContext, null) {
|
||||
@Override
|
||||
ProxySubscriptionManager getProxySubscriptionManager() {
|
||||
return mProxySubscriptionMgr;
|
||||
}
|
||||
@Override
|
||||
SubscriptionInfo getActiveSubscriptionInfo(int subId) {
|
||||
return mSubInfo;
|
||||
}
|
||||
};
|
||||
doNothing().when(mSubscriptionManager).setDefaultDataSubId(anyInt());
|
||||
doReturn(mSubscriptionManager).when(mProxySubscriptionMgr).get();
|
||||
doNothing().when(mProxySubscriptionMgr).addActiveSubscriptionsListener(any());
|
||||
doNothing().when(mProxySubscriptionMgr).removeActiveSubscriptionsListener(any());
|
||||
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(mContext), false);
|
||||
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noActiveSub_shouldDisable() {
|
||||
mSubInfo = null;
|
||||
mPreference.mOnSubscriptionsChangeListener.onChanged();
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasActiveSub_shouldEnable() {
|
||||
mPreference.mOnSubscriptionsChangeListener.onChanged();
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.NetworkTemplate;
|
||||
|
||||
import com.android.settingslib.net.DataUsageController.DataUsageInfo;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class DataUsageInfoControllerTest {
|
||||
|
||||
private static final int NEGATIVE = -1;
|
||||
private static final int ZERO = 0;
|
||||
private static final int POSITIVE_SMALL = 1;
|
||||
private static final int POSITIVE_LARGE = 5;
|
||||
|
||||
private DataUsageInfoController mInfoController;
|
||||
private DataUsageInfo info;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mInfoController = new DataUsageInfoController();
|
||||
info = new DataUsageInfo();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowUsageLowWarning_LimitUsed() {
|
||||
info.warningLevel = POSITIVE_SMALL;
|
||||
info.limitLevel = POSITIVE_LARGE;
|
||||
info.usageLevel = POSITIVE_SMALL;
|
||||
assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.limitLevel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowUsageEqualWarning_LimitUsed() {
|
||||
info.warningLevel = POSITIVE_LARGE;
|
||||
info.limitLevel = POSITIVE_LARGE;
|
||||
info.usageLevel = POSITIVE_SMALL;
|
||||
assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.limitLevel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoLimitNoUsage_WarningUsed() {
|
||||
info.warningLevel = POSITIVE_LARGE;
|
||||
info.limitLevel = ZERO;
|
||||
info.usageLevel = ZERO;
|
||||
assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.warningLevel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoLimitLowUsage_WarningUsed() {
|
||||
info.warningLevel = POSITIVE_LARGE;
|
||||
info.limitLevel = ZERO;
|
||||
info.usageLevel = POSITIVE_SMALL;
|
||||
assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.warningLevel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowWarningNoLimit_UsageUsed() {
|
||||
info.warningLevel = POSITIVE_SMALL;
|
||||
info.limitLevel = ZERO;
|
||||
info.usageLevel = POSITIVE_LARGE;
|
||||
assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.usageLevel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowWarningLowLimit_UsageUsed() {
|
||||
info.warningLevel = POSITIVE_SMALL;
|
||||
info.limitLevel = POSITIVE_SMALL;
|
||||
info.usageLevel = POSITIVE_LARGE;
|
||||
assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.usageLevel);
|
||||
}
|
||||
|
||||
private NetworkPolicy getDefaultNetworkPolicy() {
|
||||
NetworkTemplate template =
|
||||
new NetworkTemplate(NetworkTemplate.MATCH_WIFI_WILDCARD, null, null);
|
||||
int cycleDay = -1;
|
||||
String cycleTimezone = "UTC";
|
||||
long warningBytes = -1;
|
||||
long limitBytes = -1;
|
||||
return new NetworkPolicy(template, cycleDay, cycleTimezone, warningBytes, limitBytes, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullArguments_NoError() {
|
||||
mInfoController.updateDataLimit(null, null);
|
||||
mInfoController.updateDataLimit(info, null);
|
||||
mInfoController.updateDataLimit(null, getDefaultNetworkPolicy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeWarning_UpdatedToZero() {
|
||||
NetworkPolicy policy = getDefaultNetworkPolicy();
|
||||
policy.warningBytes = NEGATIVE;
|
||||
mInfoController.updateDataLimit(info, policy);
|
||||
assertThat(info.warningLevel).isEqualTo(ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWarningZero_UpdatedToZero() {
|
||||
NetworkPolicy policy = getDefaultNetworkPolicy();
|
||||
policy.warningBytes = ZERO;
|
||||
mInfoController.updateDataLimit(info, policy);
|
||||
assertThat(info.warningLevel).isEqualTo(ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWarningPositive_UpdatedToWarning() {
|
||||
NetworkPolicy policy = getDefaultNetworkPolicy();
|
||||
policy.warningBytes = POSITIVE_SMALL;
|
||||
mInfoController.updateDataLimit(info, policy);
|
||||
assertThat(info.warningLevel).isEqualTo(policy.warningBytes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLimitNegative_UpdatedToZero() {
|
||||
NetworkPolicy policy = getDefaultNetworkPolicy();
|
||||
policy.limitBytes = NEGATIVE;
|
||||
mInfoController.updateDataLimit(info, policy);
|
||||
assertThat(info.limitLevel).isEqualTo(ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLimitZero_UpdatedToZero() {
|
||||
NetworkPolicy policy = getDefaultNetworkPolicy();
|
||||
policy.limitBytes = ZERO;
|
||||
mInfoController.updateDataLimit(info, policy);
|
||||
assertThat(info.limitLevel).isEqualTo(ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLimitPositive_UpdatedToLimit() {
|
||||
NetworkPolicy policy = getDefaultNetworkPolicy();
|
||||
policy.limitBytes = POSITIVE_SMALL;
|
||||
mInfoController.updateDataLimit(info, policy);
|
||||
assertThat(info.limitLevel).isEqualTo(policy.limitBytes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user