Loading tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java +3 −8 Original line number Diff line number Diff line Loading @@ -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)); } } Loading @@ -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 { Loading tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -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; Loading tests/src/com/android/launcher3/util/Condition.java +20 −31 Original line number Diff line number Diff line Loading @@ -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 { return () -> { 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() { executor.execute(() -> { try { value.set(condition.isTrue()); } catch (Throwable e) { exceptions[0] = e; } } }); 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; } } Loading
tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java +3 −8 Original line number Diff line number Diff line Loading @@ -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)); } } Loading @@ -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 { Loading
tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -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; Loading
tests/src/com/android/launcher3/util/Condition.java +20 −31 Original line number Diff line number Diff line Loading @@ -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 { return () -> { 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() { executor.execute(() -> { try { value.set(condition.isTrue()); } catch (Throwable e) { exceptions[0] = e; } } }); 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; } }