< prev index next >

modules/javafx.swing/src/test/java/test/javafx/embed/swing/JFXPanelTest.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2014, 2016 Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

@@ -28,43 +28,43 @@
  import javafx.application.Application;
  import javafx.application.Platform;
  import javafx.embed.swing.JFXPanel;
  import javafx.scene.Group;
  import javafx.scene.shape.Circle;
- import javafx.stage.Stage;
- import jdk.swing.interop.SwingInterOpUtils;
- import junit.framework.AssertionFailedError;
- import org.junit.BeforeClass;
- import org.junit.Test;
  import javafx.scene.Scene;
+ import javafx.stage.Stage;
  import javax.swing.JPanel;
  import javax.swing.JFrame;
  import javax.swing.SwingUtilities;
+ import junit.framework.AssertionFailedError;
+ import org.junit.BeforeClass;
+ import org.junit.Test;
  
  import java.awt.Dimension;
  import java.awt.event.MouseEvent;
  import java.util.concurrent.CountDownLatch;
  import java.util.concurrent.TimeUnit;
  
- import static junit.framework.Assert.assertEquals;
+ import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertNotNull;
  import static org.junit.Assert.assertTrue;
  
+ 
  public class JFXPanelTest {
  
      // Used to launch the application before running any test
      private static final CountDownLatch launchLatch = new CountDownLatch(1);
- 
+     private static boolean setupIsDone = false;
  
      @BeforeClass
      public static void doSetupOnce() {
+         if (setupIsDone) return;
          Platform.startup(() -> {
              Platform.setImplicitExit(false);
              launchLatch.countDown();
          });
  
- 
          try {
              if (!launchLatch.await(5000, TimeUnit.MILLISECONDS)) {
                  throw new AssertionFailedError("Timeout waiting for Application to launch");
              }
          } catch (InterruptedException ex) {

@@ -72,25 +72,26 @@
              err.initCause(ex);
              throw err;
          }
  
          assertEquals(0, launchLatch.getCount());
+         setupIsDone = true;
      }
  
-     class TestFXPanel extends JFXPanel {
+     static class TestFXPanel extends JFXPanel {
          protected void processMouseEventPublic(MouseEvent e) {
              processMouseEvent(e);
          }
      };
  
      @Test
      public void testNoDoubleClickOnFirstClick() throws Exception {
  
-         CountDownLatch firstPressedEventLatch = new CountDownLatch(1);
+         final CountDownLatch firstPressedEventLatch = new CountDownLatch(1);
  
          // It's an array, so we can mutate it inside of lambda statement
-         int[] pressedEventCounter = {0};
+         final int[] pressedEventCounter = {0};
  
          SwingUtilities.invokeLater(() -> {
              TestFXPanel fxPnl = new TestFXPanel();
              fxPnl.setPreferredSize(new Dimension(100, 100));
              JFrame jframe = new JFrame();

@@ -118,16 +119,13 @@
                      fxPnl.processMouseEventPublic(e);
                  });
              });
          });
  
-         if(!firstPressedEventLatch.await(5000, TimeUnit.MILLISECONDS)) {
-             throw new Exception();
+         if (!firstPressedEventLatch.await(5000, TimeUnit.MILLISECONDS)) {
+             throw new Exception("No first click detected.");
          };
  
          Thread.sleep(100); // there should be no pressed event after the initial one. Let's wait for 0.1s and check again.
- 
          assertEquals(1, pressedEventCounter[0]);
      }
- 
- 
  }
< prev index next >