JAL-3438 spotless for 2.11.2.0
[jalview.git] / test / jalview / gui / ProgressBarTest.java
index ae531fc..a77942c 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
- * Copyright (C) 2015 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -29,13 +29,22 @@ import java.awt.GridLayout;
 
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
 
 import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 public class ProgressBarTest
 {
 
+  @BeforeClass(alwaysRun = true)
+  public void setUpJvOptionPane()
+  {
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+  }
+
   private JPanel statusPanel;
 
   private JLabel statusBar;
@@ -111,18 +120,33 @@ public class ProgressBarTest
    * @param layout
    * @param msgs
    */
-  private void verifyProgress(GridLayout layout, String[] msgs)
+  private void verifyProgress(final GridLayout layout, final String[] msgs)
   {
-    int msgCount = msgs.length;
-    assertEquals(1 + msgCount, layout.getRows());
-    assertEquals(msgCount, statusPanel.getComponentCount());
-    int i = 0;
-    for (Component c : statusPanel.getComponents())
+    try
+    {
+      SwingUtilities.invokeAndWait(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+          int msgCount = msgs.length;
+          assertEquals(1 + msgCount, layout.getRows());
+          assertEquals(msgCount, statusPanel.getComponentCount());
+          int i = 0;
+          for (Component c : statusPanel.getComponents())
+          {
+            assertTrue(c instanceof JPanel);
+            assertTrue(((JPanel) c).getComponent(0) instanceof JLabel);
+            assertEquals(msgs[i++],
+                    ((JLabel) ((JPanel) c).getComponent(0)).getText());
+          }
+        }
+      });
+    } catch (Exception e)
     {
-      assertTrue(c instanceof JPanel);
-      assertTrue(((JPanel) c).getComponent(0) instanceof JLabel);
-      assertEquals(msgs[i++],
-              ((JLabel) ((JPanel) c).getComponent(0)).getText());
+      throw new AssertionError(
+              "Unexpected exception waiting for progress bar validation",
+              e);
     }
   }
 }