Add JUnit extension for tests

This commit is contained in:
mkpaz 2023-02-19 17:18:05 +04:00
parent e415674cf7
commit fbbcaa37f9
3 changed files with 24 additions and 16 deletions

@ -0,0 +1,18 @@
package atlantafx.base;
import javafx.application.Platform;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
public class JavaFXTest implements BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext context) {
try {
Platform.startup(() -> {
});
} catch (Throwable t) {
// https://bugs.openjdk.org/browse/JDK-8090933 (2013!)
}
}
}

@ -2,22 +2,17 @@ package atlantafx.base.layout;
import static org.assertj.core.api.Assertions.assertThat;
import atlantafx.base.JavaFXTest;
import java.util.function.Consumer;
import javafx.application.Platform;
import javafx.scene.Node;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith({JavaFXTest.class})
public class DeckPaneTest {
@BeforeAll
public static void startup() {
Platform.startup(() -> {
});
}
@Test
public void testTopNodeOnNewlyCreatedDeck() {
var emptyDeck = new DeckPane();

@ -3,19 +3,14 @@ package atlantafx.base.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import javafx.application.Platform;
import atlantafx.base.JavaFXTest;
import javafx.scene.control.TextField;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith({JavaFXTest.class})
public class PasswordTextFormatterTest {
@BeforeAll
public static void startup() {
Platform.startup(() -> {
});
}
@Test
public void testTextIsMaskedByDefault() {
var field = new TextField();