Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc86a9c7 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing unnecessary method from tests

Change-Id: I28b180b0e63b277b1bf2b206a848fc6ff14a2722
parent 4b26b214
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ import com.android.launcher3.tapl.Widgets;
import com.android.launcher3.testcomponent.WidgetConfigActivity;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.ui.TestViewHelpers;
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.Wait.Condition;
import com.android.launcher3.util.rule.ShellCommandRule;

import org.junit.Before;
+1 −1
Original line number Diff line number Diff line
@@ -41,8 +41,8 @@ import com.android.launcher3.testcomponent.AppWidgetNoConfig;
import com.android.launcher3.testcomponent.AppWidgetWithConfig;
import com.android.launcher3.testcomponent.RequestPinItemActivity;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.Wait.Condition;
import com.android.launcher3.util.rule.ShellCommandRule;

import org.junit.Before;
+0 −43
Original line number Diff line number Diff line
package com.android.launcher3.util;

import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;

import androidx.test.uiautomator.UiObject2;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public interface Condition {

    boolean isTrue() throws Throwable;

    /**
     * Converts the condition to be run on UI thread.
     */
    static Condition runOnUiThread(final Condition condition) {
        final LooperExecutor executor = MAIN_EXECUTOR;
        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;
                }

            });
            latch.await(1, TimeUnit.SECONDS);
            if (exceptions[0] != null) {
                throw exceptions[0];
            }
            return value.get();
        };
    }

    static Condition minChildCount(final UiObject2 obj, final int childCount) {
        return () -> obj.getChildCount() >= childCount;
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -55,4 +55,12 @@ public class Wait {
        launcher.checkForAnomaly();
        Assert.fail(message.get());
    }

    /**
     * Interface representing a generic condition
     */
    public interface Condition {

        boolean isTrue() throws Throwable;
    }
}