version:1.5
fix:迁移到奥乐云平台 add:
This commit is contained in:
43
tests/src/com/aoleyun/os/util/Condition.java
Normal file
43
tests/src/com/aoleyun/os/util/Condition.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.aoleyun.os.util;
|
||||
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
|
||||
import com.aoleyun.os.MainThreadExecutor;
|
||||
|
||||
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 MainThreadExecutor executor = new MainThreadExecutor();
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user