diff --git a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java index a5c2e69af7..ee774571ec 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 dcb564a778..02a79b384d 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 e9ee67cdb0..78c652a29e 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; } }