|
39 | 39 |
|
40 | 40 | import java.io.IOException;
|
41 | 41 | import java.net.URL;
|
42 |
| -import java.util.concurrent.ExecutionException; |
43 |
| -import java.util.concurrent.FutureTask; |
| 42 | +import java.util.concurrent.Callable; |
44 | 43 |
|
45 | 44 | import org.junit.BeforeClass;
|
46 | 45 | import org.junit.Test;
|
|
49 | 48 | import com.oracle.javafx.scenebuilder.kit.JfxInitializer;
|
50 | 49 |
|
51 | 50 | import javafx.application.Platform;
|
| 51 | +import javafx.concurrent.Task; |
52 | 52 | import javafx.fxml.FXMLLoader;
|
53 | 53 |
|
54 | 54 | public class FXOMDocumentTest {
|
@@ -147,43 +147,35 @@ public void that_fxml_with_defines_loads_without_error_without_normalization() t
|
147 | 147 | URL resource = getClass().getResource("DynamicScreenSize.fxml");
|
148 | 148 | String validFxmlText = FXOMDocument.readContentFromURL(resource);
|
149 | 149 |
|
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()); |
159 | 153 | }
|
160 | 154 |
|
161 | 155 | @Test
|
162 | 156 | public void that_missing_imports_during_defines_resolution_cause_exception() throws Exception {
|
163 | 157 | URL resource = getClass().getResource("DynamicScreenSize.fxml");
|
164 | 158 | String validFxmlText = FXOMDocument.readContentFromURL(resource);
|
165 | 159 |
|
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 */))); |
178 | 162 |
|
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")); |
182 | 169 | }
|
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(); |
188 | 180 | }
|
189 | 181 | }
|
0 commit comments