Remove no reference code

- Remove ControllerTask and ControllerFutureTask.
- Remove ControllerTaskTest and ControllerFutureTaskTest.

Fixes: 222661474
Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.dashboard
Change-Id: I36f4e723c40aa59ecb3b087cab11f2a744540812
This commit is contained in:
Tsung-Mao Fang
2022-03-04 17:52:36 +08:00
committed by Sunny Shao
parent cdb08ee92a
commit 6af43b1412
6 changed files with 1 additions and 371 deletions

View File

@@ -1,71 +0,0 @@
/*
* Copyright (C) 2019 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.dashboard;
import static com.android.settingslib.core.instrumentation.Instrumentable.METRICS_CATEGORY_UNKNOWN;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class ControllerFutureTaskTest {
private static final String KEY = "my_key";
private Context mContext;
private TestPreferenceController mTestController;
private PreferenceScreen mScreen;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mTestController = new TestPreferenceController(mContext, KEY);
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
mScreen = preferenceManager.createPreferenceScreen(mContext);
}
@Test
public void getController_addTask_checkControllerKey() {
final ControllerFutureTask futureTask = new ControllerFutureTask(
new ControllerTask(mTestController, mScreen, null /* metricsFeature */,
METRICS_CATEGORY_UNKNOWN), null /* result */);
assertThat(futureTask.getController().getPreferenceKey()).isEqualTo(KEY);
}
static class TestPreferenceController extends BasePreferenceController {
TestPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
}
}

View File

@@ -1,124 +0,0 @@
/*
* Copyright (C) 2019 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.dashboard;
import static com.android.settingslib.core.instrumentation.Instrumentable.METRICS_CATEGORY_UNKNOWN;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import com.android.settingslib.core.AbstractPreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class ControllerTaskTest {
private static final String KEY = "my_key";
private Context mContext;
private PreferenceScreen mScreen;
private TestPreferenceController mTestController;
private ControllerTask mControllerTask;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
mScreen = preferenceManager.createPreferenceScreen(mContext);
mTestController = spy(new TestPreferenceController(mContext));
mControllerTask = new ControllerTask(mTestController, mScreen, null /* metricsFeature */,
METRICS_CATEGORY_UNKNOWN);
}
@Test
public void doRun_controlNotAvailable_noRunUpdateState() {
mTestController.setAvailable(false);
mControllerTask.run();
verify(mTestController, never()).updateState(any(Preference.class));
}
@Test
public void doRun_emptyKey_noRunUpdateState() {
mTestController.setKey("");
mControllerTask.run();
verify(mTestController, never()).updateState(any(Preference.class));
}
@Test
public void doRun_preferenceNotExist_noRunUpdateState() {
mTestController.setKey(KEY);
mControllerTask.run();
verify(mTestController, never()).updateState(any(Preference.class));
}
@Test
public void doRun_executeUpdateState() {
mTestController.setKey(KEY);
final Preference preference = new Preference(mContext);
preference.setKey(KEY);
mScreen.addPreference(preference);
mControllerTask.run();
verify(mTestController).updateState(any(Preference.class));
}
static class TestPreferenceController extends AbstractPreferenceController {
private boolean mAvailable;
private String mKey;
TestPreferenceController(Context context) {
super(context);
mAvailable = true;
}
@Override
public boolean isAvailable() {
return mAvailable;
}
@Override
public String getPreferenceKey() {
return mKey;
}
void setAvailable(boolean available) {
mAvailable = available;
}
void setKey(String key) {
mKey = key;
}
}
}

View File

@@ -390,7 +390,6 @@ public class DashboardFragmentTest {
private final ContentResolver mContentResolver;
public final PreferenceScreen mScreen;
private boolean mIsParalleled;
public TestFragment(Context context) {
mContext = context;
@@ -398,7 +397,6 @@ public class DashboardFragmentTest {
mScreen = mock(PreferenceScreen.class);
mContentResolver = mock(ContentResolver.class);
mControllers = new ArrayList<>();
mIsParalleled = true;
when(mPreferenceManager.getContext()).thenReturn(mContext);
ReflectionHelpers.setField(
@@ -445,13 +443,6 @@ public class DashboardFragmentTest {
return mContentResolver;
}
protected boolean isParalleledControllers() {
return mIsParalleled;
}
void setUsingControllerEnhancement(boolean isParalleled) {
mIsParalleled = isParalleled;
}
}
private static class TestDynamicDataObserver extends DynamicDataObserver {