summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2018-08-14 10:27:29 -0700
committerSunny Goyal <sunnygoyal@google.com>2018-08-14 10:27:48 -0700
commit6edb1b84bf4815619e2417e3796054a372845c98 (patch)
treea9843695fe2d87b68335dec42ee7dcb8eac7070d /tests
parentb6ecb17356da95cdc4c9d66d1a47024a38fc4d23 (diff)
downloadandroid_packages_apps_Trebuchet-6edb1b84bf4815619e2417e3796054a372845c98.tar.gz
android_packages_apps_Trebuchet-6edb1b84bf4815619e2417e3796054a372845c98.tar.bz2
android_packages_apps_Trebuchet-6edb1b84bf4815619e2417e3796054a372845c98.zip
Changing Condition to an interface to allow using lambdas
Change-Id: Ib7ad6a45d2ce556f843cd3a9767001904707dced
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java11
-rw-r--r--tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java2
-rw-r--r--tests/src/com/android/launcher3/util/Condition.java51
3 files changed, 24 insertions, 40 deletions
diff --git a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java
index a5c2e69af..ee774571e 100644
--- a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java
@@ -126,12 +126,8 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest {
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
} else {
// Verify that the widget id is deleted.
- assertTrue(Wait.atMost(new Condition() {
- @Override
- public boolean isTrue() throws Throwable {
- return mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null;
- }
- }, DEFAULT_ACTIVITY_TIMEOUT));
+ assertTrue(Wait.atMost(() -> mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null,
+ DEFAULT_ACTIVITY_TIMEOUT));
}
}
@@ -145,8 +141,7 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest {
/**
* Condition for searching widget id
*/
- private class WidgetSearchCondition extends Condition
- implements Workspace.ItemOperator {
+ private class WidgetSearchCondition implements Condition, Workspace.ItemOperator {
@Override
public boolean isTrue() throws Throwable {
diff --git a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
index dcb564a77..02a79b384 100644
--- a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
@@ -200,7 +200,7 @@ public class RequestPinItemTest extends AbstractLauncherUiTest {
/**
* Condition for for an item
*/
- private class ItemSearchCondition extends Condition {
+ private class ItemSearchCondition implements Condition {
private final ItemOperator mOp;
diff --git a/tests/src/com/android/launcher3/util/Condition.java b/tests/src/com/android/launcher3/util/Condition.java
index e9ee67cdb..78c652a29 100644
--- a/tests/src/com/android/launcher3/util/Condition.java
+++ b/tests/src/com/android/launcher3/util/Condition.java
@@ -8,47 +8,36 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-public abstract class Condition {
+public interface Condition {
- public abstract boolean isTrue() throws Throwable;
+ boolean isTrue() throws Throwable;
/**
* Converts the condition to be run on UI thread.
*/
- public static Condition runOnUiThread(final Condition condition) {
+ static Condition runOnUiThread(final Condition condition) {
final MainThreadExecutor executor = new MainThreadExecutor();
- return new Condition() {
- @Override
- public boolean isTrue() throws Throwable {
- final AtomicBoolean value = new AtomicBoolean(false);
- final Throwable[] exceptions = new Throwable[1];
- final CountDownLatch latch = new CountDownLatch(1);
- executor.execute(new Runnable() {
- @Override
- public void run() {
- try {
- value.set(condition.isTrue());
- } catch (Throwable e) {
- exceptions[0] = e;
- }
-
- }
- });
- latch.await(1, TimeUnit.SECONDS);
- if (exceptions[0] != null) {
- throw exceptions[0];
+ return () -> {
+ final AtomicBoolean value = new AtomicBoolean(false);
+ final Throwable[] exceptions = new Throwable[1];
+ final CountDownLatch latch = new CountDownLatch(1);
+ executor.execute(() -> {
+ try {
+ value.set(condition.isTrue());
+ } catch (Throwable e) {
+ exceptions[0] = e;
}
- return value.get();
+
+ });
+ latch.await(1, TimeUnit.SECONDS);
+ if (exceptions[0] != null) {
+ throw exceptions[0];
}
+ return value.get();
};
}
- public static Condition minChildCount(final UiObject2 obj, final int childCount) {
- return new Condition() {
- @Override
- public boolean isTrue() {
- return obj.getChildCount() >= childCount;
- }
- };
+ static Condition minChildCount(final UiObject2 obj, final int childCount) {
+ return () -> obj.getChildCount() >= childCount;
}
}