Merge "Add work-only-category controller"

This commit is contained in:
TreeHugger Robot
2017-10-17 19:10:29 +00:00
committed by Android (Google) Code Review
10 changed files with 166 additions and 25 deletions

View File

@@ -17,6 +17,14 @@
package com.android.settings.widget;
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.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.View;
@@ -33,14 +41,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
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.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ValidatedEditTextPreferenceTest {

View File

@@ -0,0 +1,75 @@
/*
* 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.widget;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import android.content.Context;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.AbstractPreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class WorkOnlyCategoryPreferenceControllerTest {
private Context mContext;
private WorkOnlyCategoryPreferenceController mController;
private List<AbstractPreferenceController> mChildren;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mChildren = new ArrayList<>();
mController = new WorkOnlyCategoryPreferenceController(mContext, "pref_key", mChildren);
}
@Test
public void isAvailable_noChildren_true() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_childrenAvailable_true() {
final AbstractPreferenceController child = mock(AbstractPreferenceController.class);
when(child.isAvailable()).thenReturn(true);
mChildren.add(child);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_childrenUnavailable_false() {
final AbstractPreferenceController child = mock(AbstractPreferenceController.class);
when(child.isAvailable()).thenReturn(false);
mChildren.add(child);
assertThat(mController.isAvailable()).isFalse();
}
}