I'm currently moving a Node in JavaFX via a DoubleProperty and Timeline. When I display it in a window, everything works as planned. However, I need to run some JUnit 5 tests.
Below is a simplified version of the Gui and Junit class. I already tried to
-use a while loop, checking the status of the Timeline
-set a listener on the Timeline
-use Thread.sleep for waiting
public DoubleProperty x = new SimpleDoubleProperty(0);
public GuiClass(){ //Constructor
KeyValue keyValueX = new KeyValue(x, 10);
Timeline driveTimeline = new Timeline(
new KeyFrame(Duration.millis(0)),
new KeyFrame(Duration.millis(100), keyValueX)
);
driveTimeline.play();
}
Junit:
class Junit {
@Test
void test() {
GuiClass test = new GuiClass();
//Never finishes
// while(test.driveTimeline.getStatus() != Animation.Status.STOPPED)
// {
// System.out.print(".");
// }
// test.driveTimeline.setOnFinished((pActionEvent) ->
// {
// System.out.println(test.x.get());
// });
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(test.x.get()); // Returns 0.0
}
My question is: How can I let the Junit wait until the Timeline is finished?
Side note: In my original program, the timeline induces several functions when it finishes, which are then being asserted. But the Timeline never seems to finish.
Thank you!