Skip to content

Commit 656f1f5

Browse files
Reworked test.
1 parent 0d6789e commit 656f1f5

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java

+23-31
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939

4040
import java.io.IOException;
4141
import java.net.URL;
42-
import java.util.concurrent.ExecutionException;
43-
import java.util.concurrent.FutureTask;
42+
import java.util.concurrent.Callable;
4443

4544
import org.junit.BeforeClass;
4645
import org.junit.Test;
@@ -49,6 +48,7 @@
4948
import com.oracle.javafx.scenebuilder.kit.JfxInitializer;
5049

5150
import javafx.application.Platform;
51+
import javafx.concurrent.Task;
5252
import javafx.fxml.FXMLLoader;
5353

5454
public class FXOMDocumentTest {
@@ -147,43 +147,35 @@ public void that_fxml_with_defines_loads_without_error_without_normalization() t
147147
URL resource = getClass().getResource("DynamicScreenSize.fxml");
148148
String validFxmlText = FXOMDocument.readContentFromURL(resource);
149149

150-
invokeAndWait(() -> {
151-
try {
152-
FXOMDocument classUnderTest = new FXOMDocument(validFxmlText, resource, null, null, false);
153-
String beforeNormalization = classUnderTest.getFxmlText(false);
154-
assertFalse(beforeNormalization.isBlank());
155-
} catch (IOException e) {
156-
throw new AssertionError("unexpected error: " + e);
157-
}
158-
});
150+
FXOMDocument classUnderTest = waitFor(() -> new FXOMDocument(validFxmlText, resource, null, null, false));
151+
String beforeNormalization = classUnderTest.getFxmlText(false);
152+
assertFalse(beforeNormalization.isBlank());
159153
}
160154

161155
@Test
162156
public void that_missing_imports_during_defines_resolution_cause_exception() throws Exception {
163157
URL resource = getClass().getResource("DynamicScreenSize.fxml");
164158
String validFxmlText = FXOMDocument.readContentFromURL(resource);
165159

166-
Throwable t = assertThrows(ExecutionException.class,
167-
() -> invokeAndWait(
168-
() -> {
169-
try {
170-
/* normalization enabled */
171-
FXOMDocument classUnderTest = new FXOMDocument(validFxmlText, resource, null, null, true);
172-
String beforeNormalization = classUnderTest.getFxmlText(false);
173-
assertFalse(beforeNormalization.isBlank());
174-
} catch (IOException e) {
175-
throw new AssertionError("unexpected error: " + e);
176-
}
177-
}));
160+
Throwable t = assertThrows(Throwable.class,
161+
() -> waitFor(() -> new FXOMDocument(validFxmlText, resource, null, null, true /* normalization enabled */)));
178162

179-
assertTrue(t.getCause() instanceof IllegalStateException);
180-
String message = t.getCause().getMessage();
181-
assertTrue(message.startsWith("Bug in FXOMRefresher: FXML dumped in "));
163+
if (t.getCause() != null) {
164+
t = t.getCause();
165+
}
166+
167+
assertEquals(IllegalStateException.class, t.getClass());
168+
assertTrue(t.getMessage().contains("Bug in FXOMRefresher"));
182169
}
183-
184-
void invokeAndWait(Runnable r) throws Exception {
185-
FutureTask<?> task = new FutureTask<>(r, null);
186-
Platform.runLater(task);
187-
task.get();
170+
171+
private <T> T waitFor(Callable<T> callable) throws Exception {
172+
Task<T> task = new Task<T>() {
173+
@Override
174+
protected T call() throws Exception {
175+
return callable.call();
176+
}
177+
};
178+
Platform.runLater(()->task.run());
179+
return task.get();
188180
}
189181
}

0 commit comments

Comments
 (0)