Skip to content

Commit c535151

Browse files
committed
Replaced Awaitility with WaitForAsyncUtils
1 parent 40fab98 commit c535151

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/main/java/javafxlibrary/utils/HelperFunctions.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import org.apache.commons.lang3.reflect.MethodUtils;
3434
import org.apache.maven.model.Model;
3535
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
36-
import org.awaitility.Awaitility;
37-
import org.awaitility.core.ConditionTimeoutException;
3836
import org.hamcrest.Matchers;
3937
import org.testfx.robot.Motion;
4038
import javafx.scene.input.MouseButton;
@@ -58,7 +56,6 @@
5856
import java.util.List;
5957
import java.util.concurrent.TimeUnit;
6058
import java.util.concurrent.TimeoutException;
61-
import java.util.concurrent.atomic.AtomicReference;
6259
import java.util.jar.JarEntry;
6360
import java.util.jar.JarFile;
6461
import java.util.regex.Matcher;
@@ -78,28 +75,21 @@ public static Node waitUntilExists(String target) {
7875
}
7976

8077
public static Node waitUntilExists(String target, int timeout, String timeUnit) {
81-
RobotLog.trace("Waiting until target \"" + target + "\" becomes existent, timeout=" + timeout + ", timeUnit=" + timeUnit);
78+
RobotLog.trace("Waiting until target \"" + target + "\" becomes existent, timeout="
79+
+ Integer.toString(timeout) + ", timeUnit=" + timeUnit);
8280

8381
try {
84-
Awaitility.setDefaultTimeout(timeout, getTimeUnit(timeUnit));
85-
AtomicReference<Node> node = new AtomicReference<>();
86-
Awaitility.await().until(() -> {
87-
try {
88-
node.set(createFinder().find(target));
89-
return node.get() != null;
90-
} catch (Exception e) {
91-
RobotLog.trace("Exception in waitUntilExists: " + e + "\n" + e.getCause());
92-
return Boolean.FALSE;
93-
}
94-
});
9582

96-
RobotLog.trace("Node located: \"" + node.get() + "\"");
97-
return node.get();
83+
WaitForAsyncUtils.waitFor((long) timeout,
84+
getTimeUnit(timeUnit),
85+
() -> Matchers.is(isNotNull()).matches(createFinder().find(target)));
86+
return createFinder().find(target);
9887

99-
} catch (ConditionTimeoutException e) {
88+
} catch (TimeoutException te) {
10089
throw new JavaFXLibraryNonFatalException("Given element \"" + target + "\" was not found within given timeout of "
10190
+ Integer.toString(timeout) + " " + timeUnit);
10291
} catch (Exception e) {
92+
RobotLog.trace("Exception in waitUntilExists: " + e + "\n" + e.getCause().toString());
10393
throw new JavaFXLibraryNonFatalException("waitUntilExist failed: " + e);
10494
}
10595
}

0 commit comments

Comments
 (0)