Skip to content
Snippets Groups Projects
Commit c6c46465 authored by George Adrian Stoica's avatar George Adrian Stoica
Browse files

changes waitForNode to use asserttion

closes  #24
parent d270623e
No related branches found
No related tags found
1 merge request!4changes waitForNode to use assertion
...@@ -6,6 +6,7 @@ import java.util.Iterator; ...@@ -6,6 +6,7 @@ import java.util.Iterator;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.function.Predicate; import java.util.function.Predicate;
import static java.time.Duration.ofSeconds;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.Parent; import javafx.scene.Parent;
...@@ -14,13 +15,13 @@ import javafx.scene.control.ListView; ...@@ -14,13 +15,13 @@ import javafx.scene.control.ListView;
import javafx.stage.Stage; import javafx.stage.Stage;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue; 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.fail;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.testfx.framework.junit5.ApplicationTest; import org.testfx.framework.junit5.ApplicationTest;
import org.testfx.util.WaitForAsyncUtils; import org.testfx.util.WaitForAsyncUtils;
import todolist.core.AbstractTodoList; import todolist.core.AbstractTodoList;
...@@ -157,8 +158,9 @@ public class TodoListControllerTest extends ApplicationTest { ...@@ -157,8 +158,9 @@ public class TodoListControllerTest extends ApplicationTest {
private Node waitForNode(Predicate<Node> nodeTest, int num) { private Node waitForNode(Predicate<Node> nodeTest, int num) {
WaitForAsyncUtils.waitForFxEvents(); WaitForAsyncUtils.waitForFxEvents();
Node[] nodes = new Node[1]; Node[] nodes = new Node[1];
try { boolean nodeFound;
WaitForAsyncUtils.waitFor(2000, TimeUnit.MILLISECONDS,
nodeFound = assertTimeoutPreemptively(ofSeconds(2),
() -> { () -> {
while (true) { while (true) {
if ((nodes[0] = findNode(nodeTest, num)) != null) { if ((nodes[0] = findNode(nodeTest, num)) != null) {
...@@ -166,11 +168,9 @@ public class TodoListControllerTest extends ApplicationTest { ...@@ -166,11 +168,9 @@ public class TodoListControllerTest extends ApplicationTest {
} }
Thread.sleep(100); Thread.sleep(100);
} }
} },
"No appropriate node available"
); );
} catch (TimeoutException e) {
fail("No appropriate node available");
}
return nodes[0]; return nodes[0];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment