Make the test more robust by counting down the latch only when the then to be tested property is set
1.1 --- a/boot-fx/src/test/java/net/java/html/boot/fx/FXBrowsersTest.java Sat Oct 31 18:06:19 2015 +0100
1.2 +++ b/boot-fx/src/test/java/net/java/html/boot/fx/FXBrowsersTest.java Sun Nov 01 16:59:42 2015 +0100
1.3 @@ -60,7 +60,8 @@
1.4 * @author Jaroslav Tulach
1.5 */
1.6 public class FXBrowsersTest {
1.7 -
1.8 + private static CountDownLatch PROPERTY_SET;
1.9 +
1.10 public FXBrowsersTest() {
1.11 }
1.12
1.13 @@ -85,7 +86,6 @@
1.14 @Test
1.15 public void behaviorOfTwoWebViewsAtOnce() throws Throwable {
1.16 class R implements Runnable {
1.17 - CountDownLatch DONE = new CountDownLatch(1);
1.18 Throwable t;
1.19
1.20 @Override
1.21 @@ -94,8 +94,6 @@
1.22 doTest();
1.23 } catch (Throwable ex) {
1.24 t = ex;
1.25 - } finally {
1.26 - DONE.countDown();
1.27 }
1.28 }
1.29
1.30 @@ -103,22 +101,12 @@
1.31 URL u = FXBrowsersTest.class.getResource("/org/netbeans/html/boot/fx/empty.html");
1.32 assertNotNull(u, "URL found");
1.33 FXBrowsers.load(App.getV1(), u, OnPages.class, "first");
1.34 -
1.35 }
1.36 }
1.37 R run = new R();
1.38 + PROPERTY_SET = new CountDownLatch(2);
1.39 Platform.runLater(run);
1.40 - run.DONE.await();
1.41 - for (int i = 0; i < 100; i++) {
1.42 - if (run.t != null) {
1.43 - throw run.t;
1.44 - }
1.45 - if (System.getProperty("finalSecond") == null) {
1.46 - Thread.sleep(100);
1.47 - }
1.48 - }
1.49 -
1.50 -
1.51 + PROPERTY_SET.await();
1.52
1.53 assertEquals(Integer.getInteger("finalFirst"), Integer.valueOf(3), "Three times in view one");
1.54 assertEquals(Integer.getInteger("finalSecond"), Integer.valueOf(2), "Two times in view one");
1.55 @@ -161,6 +149,7 @@
1.56
1.57 assertEquals(increment(), 2, "Now it is two and not influenced by second view");
1.58 System.setProperty("finalFirst", "" + increment());
1.59 + PROPERTY_SET.countDown();
1.60 }
1.61
1.62 public static void second(String... args) {
1.63 @@ -175,6 +164,7 @@
1.64
1.65 assertEquals(increment(), 1, "Counting starts from zero");
1.66 System.setProperty("finalSecond", "" + increment());
1.67 + PROPERTY_SET.countDown();
1.68 }
1.69
1.70 @JavaScriptBody(args = {}, body = "return window;")