JAL-3829 JAL-3865 test structure chooser queries to mocked 3D Beacons FTS
[jalview.git] / test / jalview / gui / AlignmentPanelTest.java
index 85ca37c..8871249 100644 (file)
@@ -23,6 +23,16 @@ package jalview.gui;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotEquals;
 
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.swing.SwingUtilities;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
 import jalview.api.AlignViewportI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
@@ -32,18 +42,12 @@ import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 import jalview.viewmodel.ViewportRanges;
 
-import java.awt.Dimension;
-import java.awt.Font;
-
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
 public class AlignmentPanelTest
 {
   AlignFrame af;
 
   @BeforeMethod(alwaysRun = true)
-  public void setUp()
+  public void setUp() throws InvocationTargetException, InterruptedException
   {
     Jalview.main(new String[] { "-nonews", "-props",
         "test/jalview/testProps.jvprops" });
@@ -52,22 +56,28 @@ public class AlignmentPanelTest
             Boolean.TRUE.toString());
     af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
             DataSourceType.FILE);
+    
+    /*
+     * ensure the panel has been repainted and so ViewportRanges set
+     */
+    SwingUtilities.invokeAndWait(new Runnable() {
+               @Override
+               public void run() {
+                   af.repaint();
+               }});
 
     /*
      * wait for Consensus thread to complete
      */
-    synchronized (this)
+    do
     {
-      while (af.getViewport().getConsensusSeq() == null)
+      try
+      {
+        Thread.sleep(50);
+      } catch (InterruptedException x)
       {
-        try
-        {
-          wait(50);
-        } catch (InterruptedException e)
-        {
-        }
       }
-    }
+    } while (af.getViewport().getCalcManager().isWorking());
   }
 
   /**
@@ -226,8 +236,12 @@ public class AlignmentPanelTest
      */
     AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[0];
     aa.label = "THIS IS A VERY LONG LABEL INDEED";
+    FontMetrics fmfor = af.alignPanel
+            .getFontMetrics(af.alignPanel.getAlabels().getFont());
+    // Assumption ID_WIDTH_PADDING == 4
+    int expwidth = 4 + fmfor.stringWidth(aa.label);
     d = af.alignPanel.calculateIdWidth(2000);
-    assertEquals(d.width, 229); // 4 + pixel width of "THIS IS A VERY LONG LABEL INDEED"
+    assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of "THIS IS A VERY LONG LABEL INDEED"
     assertEquals(d.height, 12);
 
     /*
@@ -239,7 +253,7 @@ public class AlignmentPanelTest
     assertEquals(d.height, 12);
   }
 
-  @Test(groups = "Functional")
+  @Test(groups = { "Functional", "Not-bamboo" })
   public void testGetVisibleWidth()
   {
     /*