Migrate robolectric tests to junit tests
This change do the 2 things: 1. Add new junit tests files which replace robolectric RobolectricTestRunner & RuntimeEnvironment with AndroidX objects without problem. 2. Remove the robolectric test files which have it's new junit files. This change migrate 103 files, there are still 1209 files to go. Bug: 174728471 Test: atest make RunSettingsRoboTests Change-Id: I15ed3f4745b85862f720aabbf710ce1475aced93
This commit is contained in:
@@ -1,49 +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.widget;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.After;
|
||||
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 DefaultIndicatorSeekBarTest {
|
||||
|
||||
private DefaultIndicatorSeekBar mDefaultIndicatorSeekBar;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mDefaultIndicatorSeekBar = new DefaultIndicatorSeekBar(RuntimeEnvironment.application);
|
||||
mDefaultIndicatorSeekBar.setMax(100);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
mDefaultIndicatorSeekBar = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultProgress_setSucceeds() {
|
||||
mDefaultIndicatorSeekBar.setDefaultProgress(40);
|
||||
assertEquals(40, mDefaultIndicatorSeekBar.getDefaultProgress());
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package com.android.settings.widget;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class DonutViewTest {
|
||||
@Test
|
||||
public void getPercentageStringSpannable_doesntCrashForMissingPercentage() {
|
||||
Context context = RuntimeEnvironment.application;
|
||||
|
||||
DonutView.getPercentageStringSpannable(context.getResources(), "50%", "h");
|
||||
}
|
||||
}
|
@@ -1,75 +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.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.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PreferenceCategoryControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private PreferenceCategoryController mController;
|
||||
private List<AbstractPreferenceController> mChildren;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mChildren = new ArrayList<>();
|
||||
mController = new PreferenceCategoryController(mContext, "pref_key").setChildren(mChildren);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noChildren_false() {
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_childrenAvailable_true() {
|
||||
final AbstractPreferenceController child = mock(AbstractPreferenceController.class);
|
||||
when(child.isAvailable()).thenReturn(true);
|
||||
mChildren.add(child);
|
||||
mController.setChildren(mChildren);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_childrenUnavailable_false() {
|
||||
final AbstractPreferenceController child = mock(AbstractPreferenceController.class);
|
||||
when(child.isAvailable()).thenReturn(false);
|
||||
mChildren.add(child);
|
||||
mController.setChildren(mChildren);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View.MeasureSpec;
|
||||
|
||||
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 RingProgressBarTest {
|
||||
|
||||
private Context mContext = RuntimeEnvironment.application;
|
||||
|
||||
private RingProgressBar mProgressBar;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mProgressBar = new RingProgressBar(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMeasurePortrait() {
|
||||
mProgressBar.measure(
|
||||
MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(200, MeasureSpec.EXACTLY));
|
||||
assertEquals(100, mProgressBar.getMeasuredHeight());
|
||||
assertEquals(100, mProgressBar.getMeasuredWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMeasureLandscape() {
|
||||
mProgressBar.measure(
|
||||
MeasureSpec.makeMeasureSpec(200, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY));
|
||||
assertEquals(100, mProgressBar.getMeasuredHeight());
|
||||
assertEquals(100, mProgressBar.getMeasuredWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultAttributes() {
|
||||
assertFalse(mProgressBar.isIndeterminate());
|
||||
assertEquals(0, mProgressBar.getProgress());
|
||||
assertEquals(10000, mProgressBar.getMax());
|
||||
}
|
||||
}
|
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class RtlCompatibleViewPagerTest {
|
||||
|
||||
private Locale mLocaleEn;
|
||||
private Locale mLocaleHe;
|
||||
private RtlCompatibleViewPager mViewPager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mViewPager = new RtlCompatibleViewPager(RuntimeEnvironment.application);
|
||||
mViewPager.setAdapter(new ViewPagerAdapter());
|
||||
mLocaleEn = new Locale("en");
|
||||
mLocaleHe = new Locale("he");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCurrentItem_shouldMaintainIndexDuringLocaleChange() {
|
||||
testRtlCompatibleInner(0);
|
||||
testRtlCompatibleInner(1);
|
||||
}
|
||||
|
||||
private void testRtlCompatibleInner(int currentItem) {
|
||||
// Set up the environment
|
||||
Locale.setDefault(mLocaleEn);
|
||||
mViewPager.setCurrentItem(currentItem);
|
||||
|
||||
assertThat(TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()))
|
||||
.isEqualTo(View.LAYOUT_DIRECTION_LTR);
|
||||
assertThat(mViewPager.getCurrentItem()).isEqualTo(currentItem);
|
||||
|
||||
// Simulate to change the language to RTL
|
||||
Parcelable savedInstance = mViewPager.onSaveInstanceState();
|
||||
Locale.setDefault(mLocaleHe);
|
||||
mViewPager.onRestoreInstanceState(savedInstance);
|
||||
|
||||
assertThat(TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()))
|
||||
.isEqualTo(View.LAYOUT_DIRECTION_RTL);
|
||||
assertThat(mViewPager.getCurrentItem()).isEqualTo(currentItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test viewpager adapter, uses 2 view to test it
|
||||
*/
|
||||
private static final class ViewPagerAdapter extends PagerAdapter {
|
||||
|
||||
private static final int ITEM_COUNT = 2;
|
||||
|
||||
private ViewPagerAdapter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return ITEM_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user