Skip to content
Snippets Groups Projects

changes waitForNode to use assertion

Closed George Adrian Stoica requested to merge 24-refactoring-of-waitfornode into master
1 file
+ 8
8
Compare changes
  • Side-by-side
  • Inline
@@ -6,6 +6,7 @@ import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Predicate;
import static java.time.Duration.ofSeconds;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
@@ -14,13 +15,13 @@ import javafx.scene.control.ListView;
import javafx.stage.Stage;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.testfx.framework.junit5.ApplicationTest;
import org.testfx.util.WaitForAsyncUtils;
import todolist.core.AbstractTodoList;
@@ -157,8 +158,9 @@ public class TodoListControllerTest extends ApplicationTest {
private Node waitForNode(Predicate<Node> nodeTest, int num) {
WaitForAsyncUtils.waitForFxEvents();
Node[] nodes = new Node[1];
try {
WaitForAsyncUtils.waitFor(2000, TimeUnit.MILLISECONDS,
boolean nodeFound;
nodeFound = assertTimeoutPreemptively(ofSeconds(2),
() -> {
while (true) {
if ((nodes[0] = findNode(nodeTest, num)) != null) {
@@ -166,11 +168,9 @@ public class TodoListControllerTest extends ApplicationTest {
}
Thread.sleep(100);
}
}
);
} catch (TimeoutException e) {
fail("No appropriate node available");
}
},
"No appropriate node available"
);
return nodes[0];
}
Loading