Merge "Migrate to androidx.test.espresso"
diff --git a/core/tests/coretests/Android.mk b/core/tests/coretests/Android.mk
index 6a81050..40ebd44 100644
--- a/core/tests/coretests/Android.mk
+++ b/core/tests/coretests/Android.mk
@@ -36,12 +36,11 @@
frameworks-core-util-lib \
mockwebserver \
guava \
- androidx.test.runner \
- androidx.test.ext.junit \
- androidx.test.rules \
androidx.test.espresso.core \
+ androidx.test.ext.junit \
+ androidx.test.runner \
+ androidx.test.rules \
mockito-target-minus-junit4 \
- espresso-core \
ub-uiautomator \
platform-test-annotations \
truth-prebuilt \
diff --git a/core/tests/coretests/src/android/animation/AnimatorInflaterTest.java b/core/tests/coretests/src/android/animation/AnimatorInflaterTest.java
index be1d44c..c71bc73 100644
--- a/core/tests/coretests/src/android/animation/AnimatorInflaterTest.java
+++ b/core/tests/coretests/src/android/animation/AnimatorInflaterTest.java
@@ -16,22 +16,28 @@
package android.animation;
-import android.test.ActivityInstrumentationTestCase2;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import androidx.test.filters.LargeTest;
+import androidx.test.rule.ActivityTestRule;
import com.android.frameworks.coretests.R;
+import org.junit.Rule;
+import org.junit.Test;
+
import java.util.HashSet;
import java.util.Set;
@LargeTest
-public class AnimatorInflaterTest extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> {
- Set<Integer> identityHashes = new HashSet<Integer>();
+public class AnimatorInflaterTest {
+ @Rule
+ public final ActivityTestRule<BasicAnimatorActivity> mActivityRule =
+ new ActivityTestRule<>(BasicAnimatorActivity.class);
- public AnimatorInflaterTest() {
- super(BasicAnimatorActivity.class);
- }
+ private final Set<Integer> mIdentityHashes = new HashSet<>();
private void assertUnique(Object object) {
assertUnique(object, "");
@@ -39,15 +45,16 @@
private void assertUnique(Object object, String msg) {
final int code = System.identityHashCode(object);
- assertTrue("object should be unique " + msg + ", obj:" + object, identityHashes.add(code));
-
+ assertTrue("object should be unique " + msg + ", obj:" + object, mIdentityHashes.add(code));
}
+ @Test
public void testLoadStateListAnimator() {
- StateListAnimator sla1 = AnimatorInflater.loadStateListAnimator(getActivity(),
+ final BasicAnimatorActivity activity = mActivityRule.getActivity();
+ StateListAnimator sla1 = AnimatorInflater.loadStateListAnimator(activity,
R.anim.test_state_anim);
- sla1.setTarget(getActivity().mAnimatingButton);
- StateListAnimator sla2 = AnimatorInflater.loadStateListAnimator(getActivity(),
+ sla1.setTarget(activity.mAnimatingButton);
+ StateListAnimator sla2 = AnimatorInflater.loadStateListAnimator(activity,
R.anim.test_state_anim);
assertNull(sla2.getTarget());
for (StateListAnimator sla : new StateListAnimator[]{sla1, sla2}) {
diff --git a/core/tests/coretests/src/android/animation/AnimatorSetActivityTest.java b/core/tests/coretests/src/android/animation/AnimatorSetActivityTest.java
index 55837ba..7a1de0c 100644
--- a/core/tests/coretests/src/android/animation/AnimatorSetActivityTest.java
+++ b/core/tests/coretests/src/android/animation/AnimatorSetActivityTest.java
@@ -16,27 +16,38 @@
package android.animation;
-import android.test.ActivityInstrumentationTestCase2;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import android.view.View;
import androidx.test.annotation.UiThreadTest;
import androidx.test.filters.SmallTest;
+import androidx.test.rule.ActivityTestRule;
import com.android.frameworks.coretests.R;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
import java.util.ArrayList;
-public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<AnimatorSetActivity> {
+@SmallTest
+public class AnimatorSetActivityTest {
+
+ @Rule
+ public final ActivityTestRule<AnimatorSetActivity> mActivityRule =
+ new ActivityTestRule<>(AnimatorSetActivity.class);
private static final long POLL_INTERVAL = 100; // ms
private AnimatorSetActivity mActivity;
private ObjectAnimator a1,a2,a3;
private ValueAnimator a4,a5;
- public AnimatorSetActivityTest() {
- super(AnimatorSetActivity.class);
- }
-
static class MyListener implements Animator.AnimatorListener {
boolean startIsCalled = false;
boolean endIsCalled = false;
@@ -63,10 +74,9 @@
}
}
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
- mActivity = getActivity();
+ mActivity = mActivityRule.getActivity();
View square1 = mActivity.findViewById(R.id.square1);
View square2 = mActivity.findViewById(R.id.square2);
@@ -78,7 +88,7 @@
a5 = ValueAnimator.ofFloat(10f, 5f).setDuration(850);
}
- @Override
+ @After
public void tearDown() throws Exception {
mActivity = null;
a1 = null;
@@ -86,10 +96,9 @@
a3 = null;
a4 = null;
a5 = null;
- super.tearDown();
}
- @SmallTest
+ @Test
public void testGetChildAnimations() {
AnimatorSet s1 = new AnimatorSet();
s1.playTogether(a1, a2, a3);
@@ -129,7 +138,7 @@
}
}
- @SmallTest
+ @Test
public void testTotalDuration() {
ArrayList<Animator> list = getAnimatorList();
@@ -192,7 +201,7 @@
}
- @SmallTest
+ @Test
public void testGetDuration() {
AnimatorSet s = new AnimatorSet();
assertTrue(s.getDuration() < 0);
@@ -205,8 +214,8 @@
}
- @SmallTest
@UiThreadTest
+ @Test
public void testSetDuration() {
AnimatorSet s = getSequentialSet();
assertTrue(s.getDuration() < 0);
@@ -224,7 +233,7 @@
assertEquals(duration, a5.getDuration());
}
- @SmallTest
+ @Test
public void testAddListener() throws InterruptedException {
// Verify that the listener is added to the list of listeners in the AnimatorSet
// and that newly added listener gets callback for lifecycle events of the animator
@@ -241,13 +250,10 @@
assertFalse(listener.endIsCalled);
try {
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- s.start();
- assertTrue(listener.startIsCalled);
- assertFalse(listener.endIsCalled);
- }
+ mActivityRule.runOnUiThread(() -> {
+ s.start();
+ assertTrue(listener.startIsCalled);
+ assertFalse(listener.endIsCalled);
});
} catch (Throwable throwable) {
throwable.printStackTrace();
@@ -258,18 +264,13 @@
assertTrue(listener.endIsCalled);
}
- @SmallTest
+ @Test
public void testRemoveListener() throws Throwable {
final AnimatorSet s = new AnimatorSet();
s.playTogether(a1, a2, a3, a4);
MyListener listener = new MyListener();
s.addListener(listener);
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- s.start();
- }
- });
+ mActivityRule.runOnUiThread(s::start);
Thread.sleep(s.getTotalDuration() + 100);
assertTrue(listener.startIsCalled);
@@ -282,18 +283,13 @@
listener.startIsCalled = false;
listener.endIsCalled = false;
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- s.start();
- }
- });
+ mActivityRule.runOnUiThread(s::start);
Thread.sleep(s.getTotalDuration() + 100);
assertFalse(listener.startIsCalled);
assertFalse(listener.endIsCalled);
}
- @SmallTest
+ @Test
public void testEnd() throws Throwable {
// End animator set
final AnimatorSet s = new AnimatorSet();
@@ -301,37 +297,30 @@
final MyListener listener = new MyListener();
s.addListener(listener);
assertFalse(listener.endIsCalled);
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- s.start();
- assertTrue(s.isStarted());
- assertTrue(listener.startIsCalled);
- assertFalse(listener.endIsCalled);
- }
+ mActivityRule.runOnUiThread(() -> {
+ s.start();
+ assertTrue(s.isStarted());
+ assertTrue(listener.startIsCalled);
+ assertFalse(listener.endIsCalled);
});
Thread.sleep(a2.getTotalDuration());
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- s.end();
- assertTrue(listener.startIsCalled);
- assertTrue(listener.endIsCalled);
- assertFalse(s.isRunning());
- assertFalse(s.isStarted());
+ mActivityRule.runOnUiThread(() -> {
+ s.end();
+ assertTrue(listener.startIsCalled);
+ assertTrue(listener.endIsCalled);
+ assertFalse(s.isRunning());
+ assertFalse(s.isStarted());
- assertFalse(a1.isStarted());
- assertFalse(a2.isStarted());
- assertFalse(a3.isStarted());
- assertFalse(a4.isStarted());
- }
+ assertFalse(a1.isStarted());
+ assertFalse(a2.isStarted());
+ assertFalse(a3.isStarted());
+ assertFalse(a4.isStarted());
});
-
}
- @SmallTest
+ @Test
public void testStart() throws Throwable {
final AnimatorSet s = new AnimatorSet();
ArrayList<Animator> animators = getAnimatorList();
@@ -355,12 +344,9 @@
assertFalse(l.endIsCalled);
}
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- s.start();
- assertTrue(l.startIsCalled);
- }
+ mActivityRule.runOnUiThread(() -> {
+ s.start();
+ assertTrue(l.startIsCalled);
});
long timeout = s.getTotalDuration() * 2;
@@ -383,7 +369,7 @@
}
}
- @SmallTest
+ @Test
public void testCancel() throws Throwable {
// Check whether cancel would trigger onAnimationCanceled and cancel all the unfinished
// animations
@@ -411,42 +397,33 @@
assertFalse(l.endIsCalled);
}
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- s.start();
- }
- });
+ mActivityRule.runOnUiThread(s::start);
Thread.sleep(a1.getTotalDuration());
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- assertTrue(s.isStarted());
- ArrayList<Integer> runningAnimIds = new ArrayList<Integer>();
- for (int i = 0; i < animators.size(); i++) {
- if (animators.get(i).isStarted()) {
- runningAnimIds.add(i);
- }
- }
- s.cancel();
- assertTrue(l.startIsCalled);
- assertTrue(l.cancelIsCalled);
- assertTrue(l.endIsCalled);
-
- for (int i = 0; i < listeners.size(); i++) {
- assertTrue(listeners.get(i).startIsCalled);
- if (runningAnimIds.contains(i)) {
- assertTrue(listeners.get(i).cancelIsCalled);
- }
- assertTrue(listeners.get(i).endIsCalled);
+ mActivityRule.runOnUiThread(() -> {
+ assertTrue(s.isStarted());
+ ArrayList<Integer> runningAnimIds = new ArrayList<>();
+ for (int i = 0; i < animators.size(); i++) {
+ if (animators.get(i).isStarted()) {
+ runningAnimIds.add(i);
}
}
- });
+ s.cancel();
+ assertTrue(l.startIsCalled);
+ assertTrue(l.cancelIsCalled);
+ assertTrue(l.endIsCalled);
+ for (int i = 0; i < listeners.size(); i++) {
+ assertTrue(listeners.get(i).startIsCalled);
+ if (runningAnimIds.contains(i)) {
+ assertTrue(listeners.get(i).cancelIsCalled);
+ }
+ assertTrue(listeners.get(i).endIsCalled);
+ }
+ });
}
- @SmallTest
+ @Test
public void testIsRunning() throws Throwable {
final AnimatorSet s = new AnimatorSet();
final long startDelay = 500;
@@ -455,12 +432,7 @@
s.setStartDelay(startDelay);
MyListener listener = new MyListener();
s.addListener(listener);
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- s.start();
- }
- });
+ mActivityRule.runOnUiThread(s::start);
while (!listener.endIsCalled) {
boolean passedStartDelay = a1.isStarted() || a2.isStarted() || a3.isStarted() ||
@@ -471,35 +443,29 @@
assertFalse(s.isRunning());
}
- @SmallTest
+ @Test
public void testPauseAndResume() throws Throwable {
final AnimatorSet set = getSequentialSet();
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- // Calling pause before start should have no effect, per documentation
- set.pause();
- set.start();
- assertFalse(set.isPaused());
- }
+ mActivityRule.runOnUiThread(() -> {
+ // Calling pause before start should have no effect, per documentation
+ set.pause();
+ set.start();
+ assertFalse(set.isPaused());
});
while (!a2.isStarted()) {
Thread.sleep(50);
}
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- assertFalse(set.isPaused());
- set.pause();
- assertTrue(set.isPaused());
- set.resume();
- assertFalse(set.isPaused());
- }
+ mActivityRule.runOnUiThread(() -> {
+ assertFalse(set.isPaused());
+ set.pause();
+ assertTrue(set.isPaused());
+ set.resume();
+ assertFalse(set.isPaused());
});
}
- @SmallTest
+ @Test
public void testClone() throws Throwable {
// Set up an AnimatorSet and two clones, add one listener to each. When the clones animate,
// listeners of both the clone and the animator being cloned should receive animation
@@ -535,14 +501,11 @@
// Start the animation, and make the first clone during its run and the second clone once
// it ends.
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- assertFalse(l1.startIsCalled);
- assertFalse(l1.endIsCalled);
+ mActivityRule.runOnUiThread(() -> {
+ assertFalse(l1.startIsCalled);
+ assertFalse(l1.endIsCalled);
- s1.start();
- }
+ s1.start();
});
// Make the first clone, during the animation's run.
@@ -552,20 +515,12 @@
s2.addListener(l2);
Thread.sleep(POLL_INTERVAL);
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- s1.end();
- }
- });
+ mActivityRule.runOnUiThread(s1::end);
Thread.sleep(POLL_INTERVAL);
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- assertTrue(l1.startIsCalled);
- assertTrue(l1.endIsCalled);
- }
+ mActivityRule.runOnUiThread(() -> {
+ assertTrue(l1.startIsCalled);
+ assertTrue(l1.endIsCalled);
});
Thread.sleep(POLL_INTERVAL);
@@ -574,59 +529,49 @@
final MyListener l3 = new MyListener();
s3.addListener(l3);
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- // Checking the fields before animations start.
- assertFalse(l2.startIsCalled);
- assertFalse(l2.cancelIsCalled);
- assertFalse(l2.endIsCalled);
- assertFalse(l3.startIsCalled);
- assertFalse(l3.cancelIsCalled);
- assertFalse(l3.endIsCalled);
+ mActivityRule.runOnUiThread(() -> {
+ // Checking the fields before animations start.
+ assertFalse(l2.startIsCalled);
+ assertFalse(l2.cancelIsCalled);
+ assertFalse(l2.endIsCalled);
+ assertFalse(l3.startIsCalled);
+ assertFalse(l3.cancelIsCalled);
+ assertFalse(l3.endIsCalled);
- s2.start();
- s3.start();
- }
+ s2.start();
+ s3.start();
});
Thread.sleep(POLL_INTERVAL);
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- // Make sure the listeners receive the callbacks
- // At this time only onAnimationStart() should be called.
- assertTrue(l2.startIsCalled);
- assertTrue(l3.startIsCalled);
- assertFalse(l2.endIsCalled);
- assertFalse(l3.endIsCalled);
- assertFalse(l2.cancelIsCalled);
- assertFalse(l3.cancelIsCalled);
+ mActivityRule.runOnUiThread(() -> {
+ // Make sure the listeners receive the callbacks
+ // At this time only onAnimationStart() should be called.
+ assertTrue(l2.startIsCalled);
+ assertTrue(l3.startIsCalled);
+ assertFalse(l2.endIsCalled);
+ assertFalse(l3.endIsCalled);
+ assertFalse(l2.cancelIsCalled);
+ assertFalse(l3.cancelIsCalled);
- s2.end();
- s3.cancel();
- }
+ s2.end();
+ s3.cancel();
});
Thread.sleep(POLL_INTERVAL);
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- // Check that the new listeners for the new animations gets called for the events.
- assertTrue(l2.startIsCalled);
- assertFalse(l2.cancelIsCalled);
- assertTrue(l2.endIsCalled);
- assertTrue(l3.startIsCalled);
- assertTrue(l3.cancelIsCalled);
- assertTrue(l3.endIsCalled);
+ mActivityRule.runOnUiThread(() -> {
+ // Check that the new listeners for the new animations gets called for the events.
+ assertTrue(l2.startIsCalled);
+ assertFalse(l2.cancelIsCalled);
+ assertTrue(l2.endIsCalled);
+ assertTrue(l3.startIsCalled);
+ assertTrue(l3.cancelIsCalled);
+ assertTrue(l3.endIsCalled);
- // Check that the listener on the animation that was being clone receive the
- // animation lifecycle events for the clones.
- assertTrue(onlyContains(startedAnimators, s1, s2, s3));
- assertTrue(onlyContains(canceledAnimators, s3));
- assertTrue(onlyContains(endedAnimators, s1, s2, s3));
- }
+ // Check that the listener on the animation that was being clone receive the
+ // animation lifecycle events for the clones.
+ assertTrue(onlyContains(startedAnimators, s1, s2, s3));
+ assertTrue(onlyContains(canceledAnimators, s3));
+ assertTrue(onlyContains(endedAnimators, s1, s2, s3));
});
-
}
/**
@@ -663,5 +608,4 @@
list.add(a5);
return list;
}
-
}
diff --git a/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java b/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java
index 4e90d1a..94c90aa 100644
--- a/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java
+++ b/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java
@@ -23,6 +23,8 @@
import com.android.frameworks.coretests.R;
+import org.junit.Test;
+
import java.util.concurrent.TimeUnit;
/**
@@ -36,7 +38,7 @@
@Override
public void setUp() throws Exception {
- button = (Button) getActivity().findViewById(R.id.animatingButton);
+ button = mActivityRule.getActivity().findViewById(R.id.animatingButton);
mAnimator = new AnimatorSet();
((AnimatorSet)mAnimator).playSequentially(xAnim, yAnim);
super.setUp();
@@ -53,23 +55,21 @@
* its children
*/
@MediumTest
- public void testPlayingCancelDuringChildDelay() throws Exception {
+ @Test
+ public void testPlayingCancelDuringChildDelay() throws Throwable {
yAnim.setStartDelay(500);
final AnimatorSet animSet = new AnimatorSet();
animSet.playSequentially(xAnim, yAnim);
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- animSet.addListener(mFutureListener);
- mRunning = true;
- animSet.start();
- handler.postDelayed(new Canceler(animSet, mFuture), ANIM_DURATION + 250);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ animSet.addListener(mFutureListener);
+ mRunning = true;
+ animSet.start();
+ handler.postDelayed(new Canceler(animSet, mFuture), ANIM_DURATION + 250);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
diff --git a/core/tests/coretests/src/android/animation/AutoCancelTest.java b/core/tests/coretests/src/android/animation/AutoCancelTest.java
index b3ec92c..7df7336 100644
--- a/core/tests/coretests/src/android/animation/AutoCancelTest.java
+++ b/core/tests/coretests/src/android/animation/AutoCancelTest.java
@@ -16,15 +16,24 @@
package android.animation;
+import static org.junit.Assert.assertTrue;
+
import android.os.Handler;
-import android.test.ActivityInstrumentationTestCase2;
import androidx.test.filters.SmallTest;
+import androidx.test.rule.ActivityTestRule;
+
+import org.junit.Rule;
+import org.junit.Test;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
-public class AutoCancelTest extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> {
+public class AutoCancelTest {
+
+ @Rule
+ public final ActivityTestRule<BasicAnimatorActivity> mActivityRule =
+ new ActivityTestRule<>(BasicAnimatorActivity.class);
boolean mAnimX1Canceled = false;
boolean mAnimXY1Canceled = false;
@@ -37,10 +46,6 @@
HashMap<Animator, Boolean> mCanceledMap = new HashMap<Animator, Boolean>();
- public AutoCancelTest() {
- super(BasicAnimatorActivity.class);
- }
-
ObjectAnimator setupAnimator(long startDelay, String... properties) {
ObjectAnimator returnVal;
if (properties.length == 1) {
@@ -58,8 +63,7 @@
return returnVal;
}
- private void setupAnimators(long startDelay, boolean startLater, final FutureWaiter future)
- throws Exception {
+ private void setupAnimators(long startDelay, boolean startLater, final FutureWaiter future) {
// Animators to be auto-canceled
final ObjectAnimator animX1 = setupAnimator(startDelay, "x");
final ObjectAnimator animY1 = setupAnimator(startDelay, "y");
@@ -123,64 +127,56 @@
}
@SmallTest
- public void testAutoCancel() throws Exception {
+ @Test
+ public void testAutoCancel() throws Throwable {
final FutureWaiter future = new FutureWaiter();
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- setupAnimators(0, false, future);
- } catch (Exception e) {
- future.setException(e);
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ setupAnimators(0, false, future);
+ } catch (Exception e) {
+ future.setException(e);
}
});
assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS));
}
@SmallTest
- public void testAutoCancelDelayed() throws Exception {
+ @Test
+ public void testAutoCancelDelayed() throws Throwable {
final FutureWaiter future = new FutureWaiter();
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- setupAnimators(START_DELAY, false, future);
- } catch (Exception e) {
- future.setException(e);
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ setupAnimators(START_DELAY, false, future);
+ } catch (Exception e) {
+ future.setException(e);
}
});
assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS));
}
@SmallTest
- public void testAutoCancelTestLater() throws Exception {
+ @Test
+ public void testAutoCancelTestLater() throws Throwable {
final FutureWaiter future = new FutureWaiter();
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- setupAnimators(0, true, future);
- } catch (Exception e) {
- future.setException(e);
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ setupAnimators(0, true, future);
+ } catch (Exception e) {
+ future.setException(e);
}
});
assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS));
}
@SmallTest
- public void testAutoCancelDelayedTestLater() throws Exception {
+ @Test
+ public void testAutoCancelDelayedTestLater() throws Throwable {
final FutureWaiter future = new FutureWaiter();
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- setupAnimators(START_DELAY, true, future);
- } catch (Exception e) {
- future.setException(e);
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ setupAnimators(START_DELAY, true, future);
+ } catch (Exception e) {
+ future.setException(e);
}
});
assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS));
diff --git a/core/tests/coretests/src/android/animation/EventsTest.java b/core/tests/coretests/src/android/animation/EventsTest.java
index ba7413a..0c40a95 100644
--- a/core/tests/coretests/src/android/animation/EventsTest.java
+++ b/core/tests/coretests/src/android/animation/EventsTest.java
@@ -16,12 +16,20 @@
package android.animation;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import android.annotation.CallSuper;
import android.os.Handler;
-import android.test.ActivityInstrumentationTestCase2;
import androidx.test.annotation.UiThreadTest;
import androidx.test.filters.MediumTest;
import androidx.test.filters.SmallTest;
+import androidx.test.rule.ActivityTestRule;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -38,8 +46,11 @@
* wait for some later event to occur before ending. These tests use a combination of an
* AbstractFuture mechanism and a delayed action to release that Future later.
*/
-public abstract class EventsTest
- extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> {
+public abstract class EventsTest {
+
+ @Rule
+ public final ActivityTestRule<BasicAnimatorActivity> mActivityRule =
+ new ActivityTestRule<>(BasicAnimatorActivity.class);
protected static final int ANIM_DURATION = 400;
protected static final int ANIM_DELAY = 100;
@@ -55,7 +66,6 @@
private boolean mCanceled; // tracks whether we've canceled the animator
protected Animator.AnimatorListener mFutureListener; // mechanism for delaying end of the test
protected FutureWaiter mFuture; // Mechanism for waiting for the UI test to complete
- private Animator.AnimatorListener mListener; // Listener that handles/tests the events
protected Animator mAnimator; // The animator used in the tests. Must be set in subclass
// setup() method prior to calling the superclass setup()
@@ -67,10 +77,12 @@
protected static class Canceler implements Runnable {
Animator mAnim;
FutureWaiter mFuture;
+
public Canceler(Animator anim, FutureWaiter future) {
mAnim = anim;
mFuture = future;
}
+
@Override
public void run() {
try {
@@ -79,7 +91,7 @@
mFuture.setException(new RuntimeException(e));
}
}
- };
+ }
/**
* Timeout length, based on when the animation should reasonably be complete.
@@ -95,10 +107,12 @@
static class Ender implements Runnable {
Animator mAnim;
FutureWaiter mFuture;
+
public Ender(Animator anim, FutureWaiter future) {
mAnim = anim;
mFuture = future;
}
+
@Override
public void run() {
try {
@@ -107,7 +121,7 @@
mFuture.setException(new RuntimeException(e));
}
}
- };
+ }
/**
* Pauses the given animator. Used to delay pausing until some later time (after the
@@ -116,10 +130,12 @@
static class Pauser implements Runnable {
Animator mAnim;
FutureWaiter mFuture;
+
public Pauser(Animator anim, FutureWaiter future) {
mAnim = anim;
mFuture = future;
}
+
@Override
public void run() {
try {
@@ -128,7 +144,7 @@
mFuture.setException(new RuntimeException(e));
}
}
- };
+ }
/**
* Resumes the given animator. Used to delay resuming until some later time (after the
@@ -137,10 +153,12 @@
static class Resumer implements Runnable {
Animator mAnim;
FutureWaiter mFuture;
+
public Resumer(Animator anim, FutureWaiter future) {
mAnim = anim;
mFuture = future;
}
+
@Override
public void run() {
try {
@@ -149,7 +167,7 @@
mFuture.setException(new RuntimeException(e));
}
}
- };
+ }
/**
* Releases the given Future object when the listener's end() event is called. Specifically,
@@ -171,28 +189,14 @@
public FutureReleaseListener(FutureWaiter future, long timeout) {
mFuture = future;
Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- mFuture.release();
- }
- }, timeout);
+ handler.postDelayed(mFuture::release, timeout);
}
@Override
public void onAnimationEnd(Animator animation) {
Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- mFuture.release();
- }
- }, FUTURE_RELEASE_DELAY);
+ handler.postDelayed(mFuture::release, FUTURE_RELEASE_DELAY);
}
- };
-
- public EventsTest() {
- super(BasicAnimatorActivity.class);
}
/**
@@ -201,13 +205,12 @@
* and then call super.setup(), where further properties are set on that animator.
* @throws Exception
*/
- @Override
+ @CallSuper
+ @Before
public void setUp() throws Exception {
- super.setUp();
-
// mListener is the main testing mechanism of this file. The asserts of each test
// are embedded in the listener callbacks that it implements.
- mListener = new AnimatorListenerAdapter() {
+ final Animator.AnimatorListener listener = new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
// This should only be called on an animation that has not yet been started
@@ -236,9 +239,8 @@
}
};
- mAnimator.addListener(mListener);
+ mAnimator.addListener(listener);
mAnimator.setDuration(ANIM_DURATION);
-
mFuture = new FutureWaiter();
mRunning = false;
@@ -251,6 +253,7 @@
*/
@UiThreadTest
@SmallTest
+ @Test
public void testCancel() throws Exception {
mAnimator.cancel();
}
@@ -260,6 +263,7 @@
*/
@UiThreadTest
@SmallTest
+ @Test
public void testEnd() throws Exception {
mRunning = true; // end() implicitly starts an unstarted animator
mAnimator.end();
@@ -270,19 +274,17 @@
*/
@UiThreadTest
@SmallTest
- public void testStartCancel() throws Exception {
+ @Test
+ public void testStartCancel() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.cancel();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.cancel();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -293,19 +295,17 @@
*/
@UiThreadTest
@SmallTest
- public void testStartEnd() throws Exception {
+ @Test
+ public void testStartEnd() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.end();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.end();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -315,20 +315,18 @@
* Same as testStartCancel, but with a startDelayed animator
*/
@SmallTest
- public void testStartDelayedCancel() throws Exception {
+ @Test
+ public void testStartDelayedCancel() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
mAnimator.setStartDelay(ANIM_DELAY);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.cancel();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.cancel();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -338,20 +336,18 @@
* Same as testStartEnd, but with a startDelayed animator
*/
@SmallTest
- public void testStartDelayedEnd() throws Exception {
+ @Test
+ public void testStartDelayedEnd() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
mAnimator.setStartDelay(ANIM_DELAY);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.end();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.end();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -361,20 +357,18 @@
* Verify that canceling an animator that is playing does the right thing.
*/
@MediumTest
- public void testPlayingCancel() throws Exception {
+ @Test
+ public void testPlayingCancel() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- mAnimator.addListener(mFutureListener);
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -384,20 +378,18 @@
* Verify that ending an animator that is playing does the right thing.
*/
@MediumTest
- public void testPlayingEnd() throws Exception {
+ @Test
+ public void testPlayingEnd() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- mAnimator.addListener(mFutureListener);
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Ender(mAnimator, mFuture), ANIM_MID_DURATION);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Ender(mAnimator, mFuture), ANIM_MID_DURATION);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -407,21 +399,19 @@
* Same as testPlayingCancel, but with a startDelayed animator
*/
@MediumTest
- public void testPlayingDelayedCancel() throws Exception {
+ @Test
+ public void testPlayingDelayedCancel() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- mAnimator.addListener(mFutureListener);
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -431,21 +421,19 @@
* Same as testPlayingEnd, but with a startDelayed animator
*/
@MediumTest
- public void testPlayingDelayedEnd() throws Exception {
+ @Test
+ public void testPlayingDelayedEnd() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- mAnimator.addListener(mFutureListener);
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Ender(mAnimator, mFuture), ANIM_MID_DURATION);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Ender(mAnimator, mFuture), ANIM_MID_DURATION);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -455,24 +443,21 @@
* Same as testPlayingDelayedCancel, but cancel during the startDelay period
*/
@MediumTest
- public void testPlayingDelayedCancelMidDelay() throws Exception {
+ @Test
+ public void testPlayingDelayedCancelMidDelay() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- // Set the listener to automatically timeout after an uncanceled animation
- // would have finished. This tests to make sure that we're not calling
- // the listeners with cancel/end callbacks since they won't be called
- // with the start event.
- mFutureListener = new FutureReleaseListener(mFuture, getTimeout());
- Handler handler = new Handler();
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DELAY);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ // Set the listener to automatically timeout after an uncanceled animation would
+ // have finished. This tests to make sure that we're not calling the listeners with
+ // cancel/end callbacks since they won't be called with the start event.
+ mFutureListener = new FutureReleaseListener(mFuture, getTimeout());
+ Handler handler = new Handler();
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DELAY);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout() + 100, TimeUnit.MILLISECONDS);
@@ -482,24 +467,21 @@
* Same as testPlayingDelayedEnd, but end during the startDelay period
*/
@MediumTest
- public void testPlayingDelayedEndMidDelay() throws Exception {
+ @Test
+ public void testPlayingDelayedEndMidDelay() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- // Set the listener to automatically timeout after an uncanceled animation
- // would have finished. This tests to make sure that we're not calling
- // the listeners with cancel/end callbacks since they won't be called
- // with the start event.
- mFutureListener = new FutureReleaseListener(mFuture, getTimeout());
- Handler handler = new Handler();
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Ender(mAnimator, mFuture), ANIM_MID_DELAY);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ // Set the listener to automatically timeout after an uncanceled animation would
+ // have finished. This tests to make sure that we're not calling the listeners with
+ // cancel/end callbacks since they won't be called with the start event.
+ mFutureListener = new FutureReleaseListener(mFuture, getTimeout());
+ Handler handler = new Handler();
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Ender(mAnimator, mFuture), ANIM_MID_DELAY);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout() + 100, TimeUnit.MILLISECONDS);
@@ -510,20 +492,18 @@
* does nothing.
*/
@MediumTest
- public void testStartDoubleCancel() throws Exception {
+ @Test
+ public void testStartDoubleCancel() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.cancel();
- mAnimator.cancel();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.cancel();
+ mAnimator.cancel();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -534,21 +514,19 @@
* does nothing.
*/
@MediumTest
- public void testStartDoubleEnd() throws Exception {
+ @Test
+ public void testStartDoubleEnd() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.end();
- mRunning = true; // end() implicitly starts an unstarted animator
- mAnimator.end();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.end();
+ mRunning = true; // end() implicitly starts an unstarted animator
+ mAnimator.end();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -558,21 +536,19 @@
* Same as testStartDoubleCancel, but with a startDelayed animator
*/
@MediumTest
- public void testStartDelayedDoubleCancel() throws Exception {
+ @Test
+ public void testStartDelayedDoubleCancel() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.cancel();
- mAnimator.cancel();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.cancel();
+ mAnimator.cancel();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -582,22 +558,20 @@
* Same as testStartDoubleEnd, but with a startDelayed animator
*/
@MediumTest
- public void testStartDelayedDoubleEnd() throws Exception {
+ @Test
+ public void testStartDelayedDoubleEnd() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.end();
- mRunning = true; // end() implicitly starts an unstarted animator
- mAnimator.end();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.end();
+ mRunning = true; // end() implicitly starts an unstarted animator
+ mAnimator.end();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -608,22 +582,20 @@
* the appropriate timeout duration.
*/
@MediumTest
- public void testPauseResume() throws Exception {
+ @Test
+ public void testPauseResume() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- mAnimator.addListener(mFutureListener);
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
- handler.postDelayed(new Resumer(mAnimator, mFuture),
- ANIM_PAUSE_DELAY + ANIM_PAUSE_DURATION);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
+ handler.postDelayed(new Resumer(mAnimator, mFuture),
+ ANIM_PAUSE_DELAY + ANIM_PAUSE_DURATION);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout() + ANIM_PAUSE_DURATION, TimeUnit.MILLISECONDS);
@@ -634,23 +606,21 @@
* the appropriate timeout duration.
*/
@MediumTest
- public void testPauseResumeDelayed() throws Exception {
+ @Test
+ public void testPauseResumeDelayed() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- mAnimator.addListener(mFutureListener);
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
- handler.postDelayed(new Resumer(mAnimator, mFuture),
- ANIM_PAUSE_DELAY + ANIM_PAUSE_DURATION);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
+ handler.postDelayed(new Resumer(mAnimator, mFuture),
+ ANIM_PAUSE_DELAY + ANIM_PAUSE_DURATION);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout() + ANIM_PAUSE_DURATION + ANIM_FULL_DURATION_SLOP,
@@ -661,20 +631,18 @@
* Verify that pausing an animator without resuming it causes a timeout.
*/
@MediumTest
- public void testPauseTimeout() throws Exception {
+ @Test
+ public void testPauseTimeout() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- mAnimator.addListener(mFutureListener);
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
try {
@@ -689,21 +657,19 @@
* Verify that pausing a startDelayed animator without resuming it causes a timeout.
*/
@MediumTest
- public void testPauseTimeoutDelayed() throws Exception {
+ @Test
+ public void testPauseTimeoutDelayed() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- mAnimator.addListener(mFutureListener);
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
try {
diff --git a/core/tests/coretests/src/android/animation/ObjectAnimatorEventsTest.java b/core/tests/coretests/src/android/animation/ObjectAnimatorEventsTest.java
index 53f9472..63ad061 100644
--- a/core/tests/coretests/src/android/animation/ObjectAnimatorEventsTest.java
+++ b/core/tests/coretests/src/android/animation/ObjectAnimatorEventsTest.java
@@ -27,11 +27,10 @@
@Override
public void setUp() throws Exception {
- final BasicAnimatorActivity activity = getActivity();
- Button button = (Button) activity.findViewById(R.id.animatingButton);
+ final BasicAnimatorActivity activity = mActivityRule.getActivity();
+ Button button = activity.findViewById(R.id.animatingButton);
mAnimator = ObjectAnimator.ofFloat(button, "translationX", 0, 100);
super.setUp();
}
-
}
diff --git a/core/tests/coretests/src/android/animation/StateListAnimatorTest.java b/core/tests/coretests/src/android/animation/StateListAnimatorTest.java
index e755b89..12f1977 100644
--- a/core/tests/coretests/src/android/animation/StateListAnimatorTest.java
+++ b/core/tests/coretests/src/android/animation/StateListAnimatorTest.java
@@ -16,41 +16,47 @@
package android.animation;
-import android.test.ActivityInstrumentationTestCase2;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import android.util.StateSet;
import android.view.View;
import android.view.ViewGroup;
import androidx.test.annotation.UiThreadTest;
import androidx.test.filters.LargeTest;
+import androidx.test.rule.ActivityTestRule;
import com.android.frameworks.coretests.R;
+import org.junit.Rule;
+import org.junit.Test;
+
import java.util.concurrent.atomic.AtomicInteger;
@LargeTest
-public class StateListAnimatorTest extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> {
+public class StateListAnimatorTest {
- public StateListAnimatorTest() {
- super(BasicAnimatorActivity.class);
- }
+ @Rule
+ public final ActivityTestRule<BasicAnimatorActivity> mActivityRule =
+ new ActivityTestRule<>(BasicAnimatorActivity.class);
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
+ @Test
public void testInflateFromAnimator() throws Exception {
StateListAnimator stateListAnimator = AnimatorInflater
- .loadStateListAnimator(getActivity(), R.anim.test_state_anim);
+ .loadStateListAnimator(mActivityRule.getActivity(), R.anim.test_state_anim);
assertNotNull("A state list animator should be returned", stateListAnimator);
assertEquals("State list animator should have three items", 3,
stateListAnimator.getTuples().size());
}
@UiThreadTest
+ @Test
public void testAttachDetach() throws Exception {
- View view = new View(getActivity());
+ final BasicAnimatorActivity activity = mActivityRule.getActivity();
+ View view = new View(activity);
final AtomicInteger setStateCount = new AtomicInteger(0);
StateListAnimator stateListAnimator = new StateListAnimator() {
@Override
@@ -62,7 +68,7 @@
view.setStateListAnimator(stateListAnimator);
assertNotNull("State list animator should have a reference to view even if it is detached",
stateListAnimator.getTarget());
- ViewGroup viewGroup = (ViewGroup) getActivity().findViewById(android.R.id.content);
+ ViewGroup viewGroup = activity.findViewById(android.R.id.content);
int preSetStateCount = setStateCount.get();
viewGroup.addView(view);
assertTrue("When view is attached, state list drawable's setState should be called",
@@ -82,9 +88,10 @@
stateListAnimator2.getTarget());
}
+ @Test
public void testStateListLoading() throws InterruptedException {
StateListAnimator stateListAnimator = AnimatorInflater
- .loadStateListAnimator(getActivity(), R.anim.test_state_anim);
+ .loadStateListAnimator(mActivityRule.getActivity(), R.anim.test_state_anim);
assertNotNull("A state list animator should be returned", stateListAnimator);
assertEquals("Steate list animator should have two items", 3,
stateListAnimator.getTuples().size());
diff --git a/core/tests/coretests/src/android/animation/ValueAnimatorEventsTest.java b/core/tests/coretests/src/android/animation/ValueAnimatorEventsTest.java
index f6d71b8..ba9aef8 100644
--- a/core/tests/coretests/src/android/animation/ValueAnimatorEventsTest.java
+++ b/core/tests/coretests/src/android/animation/ValueAnimatorEventsTest.java
@@ -26,5 +26,4 @@
mAnimator = ValueAnimator.ofFloat(0, 1);
super.setUp();
}
-
}
diff --git a/core/tests/coretests/src/android/animation/ViewPropertyAnimatorTest.java b/core/tests/coretests/src/android/animation/ViewPropertyAnimatorTest.java
index 997af00..81cd4da 100644
--- a/core/tests/coretests/src/android/animation/ViewPropertyAnimatorTest.java
+++ b/core/tests/coretests/src/android/animation/ViewPropertyAnimatorTest.java
@@ -16,17 +16,24 @@
package android.animation;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import android.os.Handler;
-import android.test.ActivityInstrumentationTestCase2;
import android.view.ViewPropertyAnimator;
import android.widget.Button;
import androidx.test.annotation.UiThreadTest;
import androidx.test.filters.MediumTest;
import androidx.test.filters.SmallTest;
+import androidx.test.rule.ActivityTestRule;
import com.android.frameworks.coretests.R;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
import java.util.concurrent.TimeUnit;
/**
@@ -41,8 +48,11 @@
* wait for some later event to occur before ending. These tests use a combination of an
* AbstractFuture mechanism and a delayed action to release that Future later.
*/
-public abstract class ViewPropertyAnimatorTest
- extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> {
+public class ViewPropertyAnimatorTest {
+
+ @Rule
+ public final ActivityTestRule<BasicAnimatorActivity> mActivityRule =
+ new ActivityTestRule<>(BasicAnimatorActivity.class);
protected static final int ANIM_DURATION = 400;
protected static final int ANIM_DELAY = 100;
@@ -79,7 +89,7 @@
mFuture.setException(new RuntimeException(e));
}
}
- };
+ }
/**
* Timeout length, based on when the animation should reasonably be complete.
@@ -108,28 +118,14 @@
public FutureReleaseListener(FutureWaiter future, long timeout) {
mFuture = future;
Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- mFuture.release();
- }
- }, timeout);
+ handler.postDelayed(mFuture::release, timeout);
}
@Override
public void onAnimationEnd(Animator animation) {
Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- mFuture.release();
- }
- }, FUTURE_RELEASE_DELAY);
+ handler.postDelayed(mFuture::release, FUTURE_RELEASE_DELAY);
}
- };
-
- public ViewPropertyAnimatorTest() {
- super(BasicAnimatorActivity.class);
}
/**
@@ -138,15 +134,13 @@
* and then call super.setup(), where further properties are set on that animator.
* @throws Exception
*/
- @Override
+ @Before
public void setUp() throws Exception {
- final BasicAnimatorActivity activity = getActivity();
- Button button = (Button) activity.findViewById(R.id.animatingButton);
+ final BasicAnimatorActivity activity = mActivityRule.getActivity();
+ Button button = activity.findViewById(R.id.animatingButton);
mAnimator = button.animate().x(100).y(100);
- super.setUp();
-
// mListener is the main testing mechanism of this file. The asserts of each test
// are embedded in the listener callbacks that it implements.
mListener = new AnimatorListenerAdapter() {
@@ -195,6 +189,7 @@
*/
@UiThreadTest
@SmallTest
+ @Test
public void testCancel() throws Exception {
mAnimator.cancel();
}
@@ -204,19 +199,17 @@
*/
@UiThreadTest
@SmallTest
- public void testStartCancel() throws Exception {
+ @Test
+ public void testStartCancel() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.cancel();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.cancel();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -226,20 +219,18 @@
* Same as testStartCancel, but with a startDelayed animator
*/
@SmallTest
- public void testStartDelayedCancel() throws Exception {
+ @Test
+ public void testStartDelayedCancel() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
mAnimator.setStartDelay(ANIM_DELAY);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.cancel();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.cancel();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -249,20 +240,18 @@
* Verify that canceling an animator that is playing does the right thing.
*/
@MediumTest
- public void testPlayingCancel() throws Exception {
+ @Test
+ public void testPlayingCancel() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- mAnimator.setListener(mFutureListener);
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ mAnimator.setListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -272,21 +261,19 @@
* Same as testPlayingCancel, but with a startDelayed animator
*/
@MediumTest
- public void testPlayingDelayedCancel() throws Exception {
+ @Test
+ public void testPlayingDelayedCancel() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- Handler handler = new Handler();
- mAnimator.setListener(mFutureListener);
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ Handler handler = new Handler();
+ mAnimator.setListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -296,24 +283,21 @@
* Same as testPlayingDelayedCancel, but cancel during the startDelay period
*/
@MediumTest
- public void testPlayingDelayedCancelMidDelay() throws Exception {
+ @Test
+ public void testPlayingDelayedCancelMidDelay() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- // Set the listener to automatically timeout after an uncanceled animation
- // would have finished. This tests to make sure that we're not calling
- // the listeners with cancel/end callbacks since they won't be called
- // with the start event.
- mFutureListener = new FutureReleaseListener(mFuture, getTimeout());
- Handler handler = new Handler();
- mRunning = true;
- mAnimator.start();
- handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DELAY);
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ // Set the listener to automatically timeout after an uncanceled animation would
+ // have finished. This tests to make sure that we're not calling the listeners with
+ // cancel/end callbacks since they won't be called with the start event.
+ mFutureListener = new FutureReleaseListener(mFuture, getTimeout());
+ Handler handler = new Handler();
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DELAY);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout() + 100, TimeUnit.MILLISECONDS);
@@ -324,20 +308,18 @@
* does nothing.
*/
@MediumTest
- public void testStartDoubleCancel() throws Exception {
+ @Test
+ public void testStartDoubleCancel() throws Throwable {
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.cancel();
- mAnimator.cancel();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.cancel();
+ mAnimator.cancel();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
@@ -347,24 +329,21 @@
* Same as testStartDoubleCancel, but with a startDelayed animator
*/
@MediumTest
- public void testStartDelayedDoubleCancel() throws Exception {
+ @Test
+ public void testStartDelayedDoubleCancel() throws Throwable {
mAnimator.setStartDelay(ANIM_DELAY);
mFutureListener = new FutureReleaseListener(mFuture);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- mRunning = true;
- mAnimator.start();
- mAnimator.cancel();
- mAnimator.cancel();
- mFuture.release();
- } catch (junit.framework.AssertionFailedError e) {
- mFuture.setException(new RuntimeException(e));
- }
+ mActivityRule.runOnUiThread(() -> {
+ try {
+ mRunning = true;
+ mAnimator.start();
+ mAnimator.cancel();
+ mAnimator.cancel();
+ mFuture.release();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
}
-
}
diff --git a/core/tests/coretests/src/android/hardware/hdmi/HdmiUtilsTest.java b/core/tests/coretests/src/android/hardware/hdmi/HdmiUtilsTest.java
index 16be0b0..d8799cb 100644
--- a/core/tests/coretests/src/android/hardware/hdmi/HdmiUtilsTest.java
+++ b/core/tests/coretests/src/android/hardware/hdmi/HdmiUtilsTest.java
@@ -17,7 +17,7 @@
import static com.google.common.truth.Truth.assertThat;
-import android.support.test.filters.SmallTest;
+import androidx.test.filters.SmallTest;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/core/tests/coretests/src/android/view/AccessibilityInteractionControllerTest.java b/core/tests/coretests/src/android/view/AccessibilityInteractionControllerTest.java
index d0719cb..7855ef9 100644
--- a/core/tests/coretests/src/android/view/AccessibilityInteractionControllerTest.java
+++ b/core/tests/coretests/src/android/view/AccessibilityInteractionControllerTest.java
@@ -26,9 +26,6 @@
import android.app.UiAutomation;
import android.graphics.Rect;
import android.os.SystemClock;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.rule.ActivityTestRule;
-import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
@@ -36,6 +33,10 @@
import android.view.accessibility.AccessibilityTestActivity;
import android.view.accessibility.AccessibilityWindowInfo;
+import androidx.test.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.rule.ActivityTestRule;
+
import com.android.compatibility.common.util.TestUtils;
import com.android.frameworks.coretests.R;
diff --git a/core/tests/coretests/src/android/view/PinchZoomAction.java b/core/tests/coretests/src/android/view/PinchZoomAction.java
index bec9b55..cfdec4d 100644
--- a/core/tests/coretests/src/android/view/PinchZoomAction.java
+++ b/core/tests/coretests/src/android/view/PinchZoomAction.java
@@ -16,20 +16,21 @@
package android.view;
-import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
-import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
+import static androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.hamcrest.Matchers.allOf;
import android.os.SystemClock;
-import android.support.test.espresso.InjectEventSecurityException;
-import android.support.test.espresso.PerformException;
-import android.support.test.espresso.UiController;
-import android.support.test.espresso.ViewAction;
-import android.support.test.espresso.action.Swiper;
-import android.support.test.espresso.util.HumanReadables;
+
+import androidx.test.espresso.InjectEventSecurityException;
+import androidx.test.espresso.PerformException;
+import androidx.test.espresso.UiController;
+import androidx.test.espresso.ViewAction;
+import androidx.test.espresso.action.Swiper;
+import androidx.test.espresso.util.HumanReadables;
import org.hamcrest.Matcher;
diff --git a/core/tests/coretests/src/android/view/ScaleGestureDetectorTest.java b/core/tests/coretests/src/android/view/ScaleGestureDetectorTest.java
index 1990135..f63a454 100644
--- a/core/tests/coretests/src/android/view/ScaleGestureDetectorTest.java
+++ b/core/tests/coretests/src/android/view/ScaleGestureDetectorTest.java
@@ -16,48 +16,43 @@
package android.view;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import android.content.Context;
-import android.test.ActivityInstrumentationTestCase2;
import android.util.DisplayMetrics;
import android.widget.TextView;
-import androidx.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
+import androidx.test.rule.ActivityTestRule;
import com.android.frameworks.coretests.R;
-import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
@LargeTest
-public class ScaleGestureDetectorTest extends ActivityInstrumentationTestCase2<ScaleGesture> {
- private ScaleGesture mScaleGestureActivity;
+public class ScaleGestureDetectorTest {
- public ScaleGestureDetectorTest() {
- super("com.android.frameworks.coretests", ScaleGesture.class);
- }
+ @Rule
+ public final ActivityTestRule<ScaleGesture> mActivityRule =
+ new ActivityTestRule<>(ScaleGesture.class);
+ private ScaleGesture mScaleGestureActivity;
@Before
public void setUp() throws Exception {
- super.setUp();
- injectInstrumentation(InstrumentationRegistry.getInstrumentation());
- mScaleGestureActivity = getActivity();
- }
-
- @After
- public void tearDown() throws Exception {
- super.tearDown();
+ mScaleGestureActivity = mActivityRule.getActivity();
}
@Test
public void testScaleGestureDetector() {
// No scaling should have occurred prior to performing pinch zoom action.
final float initialScaleFactor = 1.0f;
- assertEquals(initialScaleFactor, mScaleGestureActivity.getScaleFactor());
+ assertEquals(initialScaleFactor, mScaleGestureActivity.getScaleFactor(), 0f);
// Specify start and end coordinates, irrespective of device display size.
final DisplayMetrics dm = new DisplayMetrics();
diff --git a/core/tests/coretests/src/android/widget/EditorCursorTest.java b/core/tests/coretests/src/android/widget/EditorCursorTest.java
index e4f55df..585c601 100644
--- a/core/tests/coretests/src/android/widget/EditorCursorTest.java
+++ b/core/tests/coretests/src/android/widget/EditorCursorTest.java
@@ -16,11 +16,12 @@
package android.widget;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.action.ViewActions.click;
import static android.widget.espresso.TextViewAssertions.hasInsertionPointerOnLeft;
import static android.widget.espresso.TextViewAssertions.hasInsertionPointerOnRight;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.action.ViewActions.click;
+
import static junit.framework.Assert.fail;
import static org.hamcrest.MatcherAssert.assertThat;
diff --git a/core/tests/coretests/src/android/widget/SuggestionsPopupWindowTest.java b/core/tests/coretests/src/android/widget/SuggestionsPopupWindowTest.java
index 483270e..f6e02bc 100644
--- a/core/tests/coretests/src/android/widget/SuggestionsPopupWindowTest.java
+++ b/core/tests/coretests/src/android/widget/SuggestionsPopupWindowTest.java
@@ -16,15 +16,6 @@
package android.widget;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.Espresso.pressBack;
-import static android.support.test.espresso.action.ViewActions.clearText;
-import static android.support.test.espresso.action.ViewActions.click;
-import static android.support.test.espresso.action.ViewActions.replaceText;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static android.widget.espresso.DragHandleUtils.onHandleView;
import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarContainsItem;
import static android.widget.espresso.FloatingToolbarEspressoUtils.clickFloatingToolbarItem;
@@ -37,43 +28,55 @@
import static android.widget.espresso.TextViewActions.clickOnTextAtIndex;
import static android.widget.espresso.TextViewActions.longPressOnTextAtIndex;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.Espresso.pressBack;
+import static androidx.test.espresso.action.ViewActions.clearText;
+import static androidx.test.espresso.action.ViewActions.click;
+import static androidx.test.espresso.action.ViewActions.replaceText;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.RootMatchers.withDecorView;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
+import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
+
import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import android.content.res.TypedArray;
-import android.support.test.espresso.NoMatchingViewException;
-import android.support.test.espresso.ViewAssertion;
-import android.test.ActivityInstrumentationTestCase2;
import android.text.Selection;
import android.text.Spannable;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.SuggestionSpan;
import android.text.style.TextAppearanceSpan;
-import android.view.View;
import androidx.test.filters.SmallTest;
+import androidx.test.rule.ActivityTestRule;
import com.android.frameworks.coretests.R;
+import org.junit.Rule;
+import org.junit.Test;
+
/**
* SuggestionsPopupWindowTest tests.
*
* TODO: Add tests for when there are no suggestions
*/
-public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2<TextViewActivity> {
+@SmallTest
+public class SuggestionsPopupWindowTest {
- public SuggestionsPopupWindowTest() {
- super(TextViewActivity.class);
- }
+ @Rule
+ public final ActivityTestRule<TextViewActivity> mActivityRule =
+ new ActivityTestRule<>(TextViewActivity.class);
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- getActivity();
+ private TextViewActivity getActivity() {
+ return mActivityRule.getActivity();
}
private void setSuggestionSpan(SuggestionSpan span, int start, int end) {
- final TextView textView = (TextView) getActivity().findViewById(R.id.textview);
+ final TextView textView = getActivity().findViewById(R.id.textview);
textView.post(
() -> {
final Spannable text = (Spannable) textView.getText();
@@ -83,7 +86,7 @@
getInstrumentation().waitForIdleSync();
}
- @SmallTest
+ @Test
public void testOnTextContextMenuItem() {
final String text = "abc def ghi";
@@ -94,14 +97,14 @@
new String[]{"DEF", "Def"}, SuggestionSpan.FLAG_AUTO_CORRECTION);
setSuggestionSpan(suggestionSpan, text.indexOf('d'), text.indexOf('f') + 1);
- final TextView textView = (TextView) getActivity().findViewById(R.id.textview);
+ final TextView textView = getActivity().findViewById(R.id.textview);
textView.post(() -> textView.onTextContextMenuItem(TextView.ID_REPLACE));
getInstrumentation().waitForIdleSync();
assertSuggestionsPopupIsDisplayed();
}
- @SmallTest
+ @Test
public void testSelectionActionMode() {
final String text = "abc def ghi";
@@ -123,7 +126,7 @@
assertSuggestionsPopupIsDisplayed();
}
- @SmallTest
+ @Test
public void testInsertionActionMode() {
final String text = "abc def ghi";
@@ -146,13 +149,13 @@
}
private void showSuggestionsPopup() {
- final TextView textView = (TextView) getActivity().findViewById(R.id.textview);
+ final TextView textView = getActivity().findViewById(R.id.textview);
textView.post(() -> textView.onTextContextMenuItem(TextView.ID_REPLACE));
getInstrumentation().waitForIdleSync();
assertSuggestionsPopupIsDisplayed();
}
- @SmallTest
+ @Test
public void testSuggestionItems() {
final String text = "abc def ghi";
@@ -190,7 +193,7 @@
onView(withId(R.id.textview)).check(matches(withText("abc ghi")));
}
- @SmallTest
+ @Test
public void testMisspelled() {
final String text = "abc def ghi";
@@ -217,7 +220,7 @@
// TODO: Check if add to dictionary dialog is displayed.
}
- @SmallTest
+ @Test
public void testEasyCorrect() {
final String text = "abc def ghi";
@@ -253,7 +256,7 @@
getActivity().getString(com.android.internal.R.string.delete));
}
- @SmallTest
+ @Test
public void testTextAppearanceInSuggestionsPopup() {
final String text = "abc def ghi";
@@ -302,53 +305,49 @@
assertSuggestionsPopupContainsItem(
getActivity().getString(com.android.internal.R.string.delete));
- onSuggestionsPopup().check(new ViewAssertion() {
- @Override
- public void check(View view, NoMatchingViewException e) {
- final ListView listView = (ListView) view.findViewById(
- com.android.internal.R.id.suggestionContainer);
- assertNotNull(listView);
- final int childNum = listView.getChildCount();
- assertEquals(singleWordCandidates.length + multiWordCandidates.length,
- childNum);
+ onSuggestionsPopup().check((view, e) -> {
+ final ListView listView = view.findViewById(
+ com.android.internal.R.id.suggestionContainer);
+ assertNotNull(listView);
+ final int childNum = listView.getChildCount();
+ assertEquals(singleWordCandidates.length + multiWordCandidates.length, childNum);
- for (int j = 0; j < childNum; j++) {
- final TextView suggestion = (TextView) listView.getChildAt(j);
- assertNotNull(suggestion);
- final Spanned spanned = (Spanned) suggestion.getText();
- assertNotNull(spanned);
+ for (int j = 0; j < childNum; j++) {
+ final TextView suggestion = (TextView) listView.getChildAt(j);
+ assertNotNull(suggestion);
+ final Spanned spanned = (Spanned) suggestion.getText();
+ assertNotNull(spanned);
- // Check that the suggestion item order is kept.
- final String expectedText;
- if (j < singleWordCandidates.length) {
- expectedText = "abc " + singleWordCandidates[j] + " ghi";
- } else {
- expectedText = multiWordCandidates[j - singleWordCandidates.length];
- }
- assertEquals(expectedText, spanned.toString());
-
- // Check that the text is highlighted with correct color and text size.
- final TextAppearanceSpan[] taSpan = spanned.getSpans(
- text.indexOf('d'), text.indexOf('f') + 1, TextAppearanceSpan.class);
- assertEquals(1, taSpan.length);
- TextPaint tp = new TextPaint();
- taSpan[0].updateDrawState(tp);
- assertEquals(expectedHighlightTextColor, tp.getColor());
- assertEquals(expectedHighlightTextSize, tp.getTextSize());
-
- // Check the correct part of the text is highlighted.
- final int expectedStart;
- final int expectedEnd;
- if (j < singleWordCandidates.length) {
- expectedStart = text.indexOf('d');
- expectedEnd = text.indexOf('f') + 1;
- } else {
- expectedStart = 0;
- expectedEnd = text.length();
- }
- assertEquals(expectedStart, spanned.getSpanStart(taSpan[0]));
- assertEquals(expectedEnd, spanned.getSpanEnd(taSpan[0]));
+ // Check that the suggestion item order is kept.
+ final String expectedText;
+ if (j < singleWordCandidates.length) {
+ expectedText = "abc " + singleWordCandidates[j] + " ghi";
+ } else {
+ expectedText = multiWordCandidates[j - singleWordCandidates.length];
}
+ assertEquals(expectedText, spanned.toString());
+
+ // Check that the text is highlighted with correct color and text size.
+ final TextAppearanceSpan[] taSpan = spanned.getSpans(
+ text.indexOf('d'), text.indexOf('f') + 1, TextAppearanceSpan.class);
+ assertEquals(1, taSpan.length);
+ TextPaint tp = new TextPaint();
+ taSpan[0].updateDrawState(tp);
+ assertEquals(expectedHighlightTextColor, tp.getColor());
+ assertEquals(expectedHighlightTextSize, tp.getTextSize(), 0f);
+
+ // Check the correct part of the text is highlighted.
+ final int expectedStart;
+ final int expectedEnd;
+ if (j < singleWordCandidates.length) {
+ expectedStart = text.indexOf('d');
+ expectedEnd = text.indexOf('f') + 1;
+ } else {
+ expectedStart = 0;
+ expectedEnd = text.length();
+ }
+ assertEquals(expectedStart, spanned.getSpanStart(taSpan[0]));
+ assertEquals(expectedEnd, spanned.getSpanEnd(taSpan[0]));
}
});
pressBack();
diff --git a/core/tests/coretests/src/android/widget/TextViewActivityMouseTest.java b/core/tests/coretests/src/android/widget/TextViewActivityMouseTest.java
index 41fa08b..b411668 100644
--- a/core/tests/coretests/src/android/widget/TextViewActivityMouseTest.java
+++ b/core/tests/coretests/src/android/widget/TextViewActivityMouseTest.java
@@ -16,15 +16,6 @@
package android.widget;
-
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.Espresso.pressBack;
-import static android.support.test.espresso.action.ViewActions.replaceText;
-import static android.support.test.espresso.action.ViewActions.typeText;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static android.widget.espresso.ContextMenuUtils.assertContextMenuContainsItemDisabled;
import static android.widget.espresso.ContextMenuUtils.assertContextMenuContainsItemEnabled;
import static android.widget.espresso.ContextMenuUtils.assertContextMenuIsNotDisplayed;
@@ -42,6 +33,15 @@
import static android.widget.espresso.TextViewAssertions.hasInsertionPointerAtIndex;
import static android.widget.espresso.TextViewAssertions.hasSelection;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.Espresso.pressBack;
+import static androidx.test.espresso.action.ViewActions.replaceText;
+import static androidx.test.espresso.action.ViewActions.typeText;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
+
import android.app.Activity;
import android.view.MotionEvent;
import android.view.textclassifier.TextClassificationManager;
diff --git a/core/tests/coretests/src/android/widget/TextViewActivityTest.java b/core/tests/coretests/src/android/widget/TextViewActivityTest.java
index 9d93421..267a9c8 100644
--- a/core/tests/coretests/src/android/widget/TextViewActivityTest.java
+++ b/core/tests/coretests/src/android/widget/TextViewActivityTest.java
@@ -16,15 +16,6 @@
package android.widget;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.action.ViewActions.click;
-import static android.support.test.espresso.action.ViewActions.longClick;
-import static android.support.test.espresso.action.ViewActions.pressKey;
-import static android.support.test.espresso.action.ViewActions.replaceText;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static android.widget.espresso.CustomViewActions.longPressAtRelativeCoordinates;
import static android.widget.espresso.DragHandleUtils.onHandleView;
import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarContainsItem;
@@ -44,6 +35,16 @@
import static android.widget.espresso.TextViewAssertions.hasInsertionPointerAtIndex;
import static android.widget.espresso.TextViewAssertions.hasSelection;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.action.ViewActions.click;
+import static androidx.test.espresso.action.ViewActions.longClick;
+import static androidx.test.espresso.action.ViewActions.pressKey;
+import static androidx.test.espresso.action.ViewActions.replaceText;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
+
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
@@ -60,7 +61,6 @@
import android.app.Instrumentation;
import android.content.ClipData;
import android.content.ClipboardManager;
-import android.support.test.espresso.action.EspressoKey;
import android.support.test.uiautomator.UiDevice;
import android.text.InputType;
import android.text.Selection;
@@ -79,6 +79,7 @@
import android.widget.espresso.CustomViewActions.RelativeCoordinatesProvider;
import androidx.test.InstrumentationRegistry;
+import androidx.test.espresso.action.EspressoKey;
import androidx.test.filters.MediumTest;
import androidx.test.filters.Suppress;
import androidx.test.rule.ActivityTestRule;
diff --git a/core/tests/coretests/src/android/widget/espresso/ContextMenuUtils.java b/core/tests/coretests/src/android/widget/espresso/ContextMenuUtils.java
index 02ee9be..0f8faa8 100644
--- a/core/tests/coretests/src/android/widget/espresso/ContextMenuUtils.java
+++ b/core/tests/coretests/src/android/widget/espresso/ContextMenuUtils.java
@@ -16,28 +16,29 @@
package android.widget.espresso;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.action.ViewActions.click;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
-import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
-import static android.support.test.espresso.matcher.ViewMatchers.hasFocus;
-import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast;
-import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.action.ViewActions.click;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.RootMatchers.withDecorView;
+import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
+import static androidx.test.espresso.matcher.ViewMatchers.hasFocus;
+import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast;
+import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.not;
-import android.support.test.espresso.NoMatchingRootException;
-import android.support.test.espresso.NoMatchingViewException;
-import android.support.test.espresso.ViewInteraction;
-import android.support.test.espresso.matcher.ViewMatchers;
import android.view.View;
import android.widget.MenuPopupWindow.MenuDropDownListView;
+import androidx.test.espresso.NoMatchingRootException;
+import androidx.test.espresso.NoMatchingViewException;
+import androidx.test.espresso.ViewInteraction;
+import androidx.test.espresso.matcher.ViewMatchers;
+
import com.android.internal.view.menu.ListMenuItemView;
import org.hamcrest.Description;
diff --git a/core/tests/coretests/src/android/widget/espresso/CustomViewActions.java b/core/tests/coretests/src/android/widget/espresso/CustomViewActions.java
index daf9e78..217553e 100644
--- a/core/tests/coretests/src/android/widget/espresso/CustomViewActions.java
+++ b/core/tests/coretests/src/android/widget/espresso/CustomViewActions.java
@@ -16,15 +16,15 @@
package android.widget.espresso;
-import static android.support.test.espresso.action.ViewActions.actionWithAssertions;
+import static androidx.test.espresso.action.ViewActions.actionWithAssertions;
import android.view.View;
-import android.support.test.espresso.ViewAction;
-import android.support.test.espresso.action.CoordinatesProvider;
-import android.support.test.espresso.action.GeneralClickAction;
-import android.support.test.espresso.action.Press;
-import android.support.test.espresso.action.Tap;
+import androidx.test.espresso.ViewAction;
+import androidx.test.espresso.action.CoordinatesProvider;
+import androidx.test.espresso.action.GeneralClickAction;
+import androidx.test.espresso.action.Press;
+import androidx.test.espresso.action.Tap;
import com.android.internal.util.Preconditions;
diff --git a/core/tests/coretests/src/android/widget/espresso/DragAction.java b/core/tests/coretests/src/android/widget/espresso/DragAction.java
index b2c8e38..afdc4d3 100644
--- a/core/tests/coretests/src/android/widget/espresso/DragAction.java
+++ b/core/tests/coretests/src/android/widget/espresso/DragAction.java
@@ -16,27 +16,30 @@
package android.widget.espresso;
-import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
-import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
+import static androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
+
import static com.android.internal.util.Preconditions.checkNotNull;
+
import static org.hamcrest.Matchers.allOf;
+
import android.annotation.Nullable;
import android.os.SystemClock;
-import android.support.test.espresso.UiController;
-import android.support.test.espresso.PerformException;
-import android.support.test.espresso.ViewAction;
-import android.support.test.espresso.action.CoordinatesProvider;
-import android.support.test.espresso.action.MotionEvents;
-import android.support.test.espresso.action.PrecisionDescriber;
-import android.support.test.espresso.action.Swiper;
-import android.support.test.espresso.util.HumanReadables;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
-import org.hamcrest.Matcher;
+import androidx.test.espresso.PerformException;
+import androidx.test.espresso.UiController;
+import androidx.test.espresso.ViewAction;
+import androidx.test.espresso.action.CoordinatesProvider;
+import androidx.test.espresso.action.MotionEvents;
+import androidx.test.espresso.action.PrecisionDescriber;
+import androidx.test.espresso.action.Swiper;
+import androidx.test.espresso.util.HumanReadables;
+import org.hamcrest.Matcher;
/**
* Drags on a View using touch events.<br>
diff --git a/core/tests/coretests/src/android/widget/espresso/DragHandleUtils.java b/core/tests/coretests/src/android/widget/espresso/DragHandleUtils.java
index 1693e54..1b849b5 100644
--- a/core/tests/coretests/src/android/widget/espresso/DragHandleUtils.java
+++ b/core/tests/coretests/src/android/widget/espresso/DragHandleUtils.java
@@ -16,22 +16,23 @@
package android.widget.espresso;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup;
-import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
-import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
-import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.RootMatchers.isPlatformPopup;
+import static androidx.test.espresso.matcher.RootMatchers.withDecorView;
+import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
+import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.allOf;
-import android.support.test.espresso.NoMatchingRootException;
-import android.support.test.espresso.NoMatchingViewException;
-import android.support.test.espresso.ViewInteraction;
import android.widget.Editor;
+import androidx.test.espresso.NoMatchingRootException;
+import androidx.test.espresso.NoMatchingViewException;
+import androidx.test.espresso.ViewInteraction;
+
public final class DragHandleUtils {
private DragHandleUtils() {}
diff --git a/core/tests/coretests/src/android/widget/espresso/FloatingToolbarEspressoUtils.java b/core/tests/coretests/src/android/widget/espresso/FloatingToolbarEspressoUtils.java
index 0355f82..d45d4b0 100644
--- a/core/tests/coretests/src/android/widget/espresso/FloatingToolbarEspressoUtils.java
+++ b/core/tests/coretests/src/android/widget/espresso/FloatingToolbarEspressoUtils.java
@@ -16,30 +16,31 @@
package android.widget.espresso;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.action.ViewActions.click;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup;
-import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
-import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
-import static android.support.test.espresso.matcher.ViewMatchers.withTagValue;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.action.ViewActions.click;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.RootMatchers.isPlatformPopup;
+import static androidx.test.espresso.matcher.RootMatchers.withDecorView;
+import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.matcher.ViewMatchers.withTagValue;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.is;
-import android.support.test.espresso.NoMatchingRootException;
-import android.support.test.espresso.NoMatchingViewException;
-import android.support.test.espresso.UiController;
-import android.support.test.espresso.ViewAction;
-import android.support.test.espresso.ViewInteraction;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import androidx.test.espresso.NoMatchingRootException;
+import androidx.test.espresso.NoMatchingViewException;
+import androidx.test.espresso.UiController;
+import androidx.test.espresso.ViewAction;
+import androidx.test.espresso.ViewInteraction;
+
import com.android.internal.widget.FloatingToolbar;
import org.hamcrest.Description;
diff --git a/core/tests/coretests/src/android/widget/espresso/MouseClickAction.java b/core/tests/coretests/src/android/widget/espresso/MouseClickAction.java
index b50d6f4..f56af5a 100644
--- a/core/tests/coretests/src/android/widget/espresso/MouseClickAction.java
+++ b/core/tests/coretests/src/android/widget/espresso/MouseClickAction.java
@@ -16,18 +16,19 @@
package android.widget.espresso;
-import android.support.test.espresso.UiController;
-import android.support.test.espresso.ViewAction;
-import android.support.test.espresso.action.CoordinatesProvider;
-import android.support.test.espresso.action.MotionEvents;
-import android.support.test.espresso.action.MotionEvents.DownResultHolder;
-import android.support.test.espresso.action.Press;
-import android.support.test.espresso.action.Tapper;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
+import androidx.test.espresso.UiController;
+import androidx.test.espresso.ViewAction;
+import androidx.test.espresso.action.CoordinatesProvider;
+import androidx.test.espresso.action.MotionEvents;
+import androidx.test.espresso.action.MotionEvents.DownResultHolder;
+import androidx.test.espresso.action.Press;
+import androidx.test.espresso.action.Tapper;
+
import org.hamcrest.Matcher;
/**
diff --git a/core/tests/coretests/src/android/widget/espresso/MouseUiController.java b/core/tests/coretests/src/android/widget/espresso/MouseUiController.java
index 022be76..abee736 100644
--- a/core/tests/coretests/src/android/widget/espresso/MouseUiController.java
+++ b/core/tests/coretests/src/android/widget/espresso/MouseUiController.java
@@ -18,16 +18,19 @@
import static com.android.internal.util.Preconditions.checkNotNull;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
import android.annotation.IntDef;
-import android.support.test.espresso.InjectEventSecurityException;
-import android.support.test.espresso.UiController;
+import android.os.SystemClock;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
+import androidx.test.espresso.InjectEventSecurityException;
+import androidx.test.espresso.UiController;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.Iterator;
+
/**
* Class to wrap an UiController to overwrite source of motion events to SOURCE_MOUSE.
* Note that this doesn't change the tool type.
@@ -71,6 +74,32 @@
return mUiController.injectMotionEvent(event);
}
+ /**
+ * Copied from latest {@link androidx.test.espresso.UiController}, since current
+ * {@link androidx.test.espresso.UiController#injectMotionEventSequence(Iterable)} seems not a
+ * default method.
+ */
+ @Override
+ public boolean injectMotionEventSequence(Iterable<MotionEvent> events)
+ throws InjectEventSecurityException {
+ android.util.Log.w(
+ "UIC",
+ "Using default injectMotionEventSeq() - this may not inject a sequence properly. "
+ + "If wrapping UIController please override this method and delegate.");
+ Iterator<MotionEvent> mei = events.iterator();
+ boolean success = true;
+ while (mei.hasNext()) {
+ MotionEvent me = mei.next();
+ if (me.getEventTime() - SystemClock.uptimeMillis() > 10) {
+ // Because the loopMainThreadForAtLeast is overkill for waiting, intentially only
+ // call it with a smaller amount of milliseconds as best effort
+ loopMainThreadForAtLeast(10);
+ }
+ success &= injectMotionEvent(me);
+ }
+ return success;
+ }
+
@Override
public boolean injectString(String str) throws InjectEventSecurityException {
return mUiController.injectString(str);
diff --git a/core/tests/coretests/src/android/widget/espresso/SuggestionsPopupwindowUtils.java b/core/tests/coretests/src/android/widget/espresso/SuggestionsPopupwindowUtils.java
index b5a96ae..32c02403 100644
--- a/core/tests/coretests/src/android/widget/espresso/SuggestionsPopupwindowUtils.java
+++ b/core/tests/coretests/src/android/widget/espresso/SuggestionsPopupwindowUtils.java
@@ -16,36 +16,40 @@
package android.widget.espresso;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
-import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.RootMatchers.withDecorView;
+import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
+import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
+
+import android.view.View;
+
+import androidx.test.espresso.NoMatchingRootException;
+import androidx.test.espresso.NoMatchingViewException;
+import androidx.test.espresso.UiController;
+import androidx.test.espresso.ViewAction;
+import androidx.test.espresso.ViewInteraction;
+import androidx.test.espresso.action.GeneralLocation;
+import androidx.test.espresso.action.Press;
+import androidx.test.espresso.action.Tap;
import org.hamcrest.Matcher;
-import android.support.test.espresso.NoMatchingRootException;
-import android.support.test.espresso.NoMatchingViewException;
-import android.support.test.espresso.UiController;
-import android.support.test.espresso.ViewAction;
-import android.support.test.espresso.ViewInteraction;
-import android.support.test.espresso.action.GeneralLocation;
-import android.support.test.espresso.action.Press;
-import android.support.test.espresso.action.Tap;
-import android.view.View;
-
public final class SuggestionsPopupwindowUtils {
private static final int id = com.android.internal.R.id.suggestionWindowContainer;
private SuggestionsPopupwindowUtils() {};
public static ViewInteraction onSuggestionsPopup() {
+ getInstrumentation().waitForIdleSync();
return onView(withId(id)).inRoot(withDecorView(hasDescendant(withId(id))));
}
private static ViewInteraction onSuggestionsPopupItem(Matcher<View> matcher) {
+ getInstrumentation().waitForIdleSync();
return onView(matcher).inRoot(withDecorView(hasDescendant(withId(id))));
}
diff --git a/core/tests/coretests/src/android/widget/espresso/TextViewActions.java b/core/tests/coretests/src/android/widget/espresso/TextViewActions.java
index b4c547e..83ce67b 100644
--- a/core/tests/coretests/src/android/widget/espresso/TextViewActions.java
+++ b/core/tests/coretests/src/android/widget/espresso/TextViewActions.java
@@ -16,16 +16,9 @@
package android.widget.espresso;
-import static android.support.test.espresso.action.ViewActions.actionWithAssertions;
+import static androidx.test.espresso.action.ViewActions.actionWithAssertions;
import android.graphics.Rect;
-import android.support.test.espresso.PerformException;
-import android.support.test.espresso.ViewAction;
-import android.support.test.espresso.action.CoordinatesProvider;
-import android.support.test.espresso.action.GeneralLocation;
-import android.support.test.espresso.action.Press;
-import android.support.test.espresso.action.Tap;
-import android.support.test.espresso.util.HumanReadables;
import android.text.Layout;
import android.view.MotionEvent;
import android.view.View;
@@ -33,6 +26,14 @@
import android.widget.Editor.HandleView;
import android.widget.TextView;
+import androidx.test.espresso.PerformException;
+import androidx.test.espresso.ViewAction;
+import androidx.test.espresso.action.CoordinatesProvider;
+import androidx.test.espresso.action.GeneralLocation;
+import androidx.test.espresso.action.Press;
+import androidx.test.espresso.action.Tap;
+import androidx.test.espresso.util.HumanReadables;
+
/**
* A collection of actions on a {@link android.widget.TextView}.
*/
diff --git a/core/tests/coretests/src/android/widget/espresso/TextViewAssertions.java b/core/tests/coretests/src/android/widget/espresso/TextViewAssertions.java
index 5ed69e0..d638da5 100644
--- a/core/tests/coretests/src/android/widget/espresso/TextViewAssertions.java
+++ b/core/tests/coretests/src/android/widget/espresso/TextViewAssertions.java
@@ -16,7 +16,7 @@
package android.widget.espresso;
-import static android.support.test.espresso.matcher.ViewMatchers.assertThat;
+import static androidx.test.espresso.matcher.ViewMatchers.assertThat;
import static com.android.internal.util.Preconditions.checkNotNull;
@@ -26,14 +26,15 @@
import android.annotation.IntDef;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
-import android.support.test.espresso.NoMatchingViewException;
-import android.support.test.espresso.ViewAssertion;
import android.text.Spanned;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
+import androidx.test.espresso.NoMatchingViewException;
+import androidx.test.espresso.ViewAssertion;
+
import junit.framework.AssertionFailedError;
import org.hamcrest.Matcher;
diff --git a/core/tests/coretests/src/android/widget/espresso/ViewClickAction.java b/core/tests/coretests/src/android/widget/espresso/ViewClickAction.java
index 8bce1b0..1e6447d 100644
--- a/core/tests/coretests/src/android/widget/espresso/ViewClickAction.java
+++ b/core/tests/coretests/src/android/widget/espresso/ViewClickAction.java
@@ -16,17 +16,18 @@
package android.widget.espresso;
-import org.hamcrest.Matcher;
-
-import android.support.test.espresso.UiController;
-import android.support.test.espresso.ViewAction;
-import android.support.test.espresso.action.CoordinatesProvider;
-import android.support.test.espresso.action.GeneralClickAction;
-import android.support.test.espresso.action.PrecisionDescriber;
-import android.support.test.espresso.action.Tapper;
import android.view.View;
import android.view.ViewConfiguration;
+import androidx.test.espresso.UiController;
+import androidx.test.espresso.ViewAction;
+import androidx.test.espresso.action.CoordinatesProvider;
+import androidx.test.espresso.action.GeneralClickAction;
+import androidx.test.espresso.action.PrecisionDescriber;
+import androidx.test.espresso.action.Tapper;
+
+import org.hamcrest.Matcher;
+
public final class ViewClickAction implements ViewAction {
private final GeneralClickAction mGeneralClickAction;
diff --git a/core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java b/core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java
index fe2fb85..7430c7a 100644
--- a/core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java
+++ b/core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java
@@ -16,12 +16,12 @@
package com.android.internal.app;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.action.ViewActions.click;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.action.ViewActions.click;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.android.internal.app.ResolverWrapperActivity.sOverrides;
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java
index 3ddd8aa..64b7c2c 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java
@@ -22,8 +22,9 @@
import android.os.Process;
import android.os.SystemClock;
-import android.support.test.filters.LargeTest;
-import android.support.test.runner.AndroidJUnit4;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.LargeTest;
import com.android.internal.os.KernelCpuThreadReader.ProcessCpuUsage;
import com.android.internal.os.KernelCpuThreadReader.ThreadCpuUsage;
diff --git a/core/tests/coretests/src/com/android/internal/statusbar/NotificationVisibilityTest.java b/core/tests/coretests/src/com/android/internal/statusbar/NotificationVisibilityTest.java
index b740ecc..22432a8 100644
--- a/core/tests/coretests/src/com/android/internal/statusbar/NotificationVisibilityTest.java
+++ b/core/tests/coretests/src/com/android/internal/statusbar/NotificationVisibilityTest.java
@@ -19,8 +19,8 @@
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;