JAL-1889 hack to ensure endRes is computed in setUp
[jalview.git] / test / jalview / gui / AlignmentPanelTest.java
index b228ba1..58f7324 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.gui;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
 
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
@@ -30,6 +31,10 @@ import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 import jalview.viewmodel.ViewportRanges;
 
+import java.lang.reflect.InvocationTargetException;
+
+import javax.swing.SwingUtilities;
+
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -130,7 +135,7 @@ 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" });
@@ -139,6 +144,15 @@ 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
@@ -218,4 +232,31 @@ public class AlignmentPanelTest
             .getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden
                                                   // columns
   }
+
+  /**
+   * Test that update layout reverts to original (unwrapped) values for endRes
+   * when switching from wrapped back to unwrapped mode (JAL-2739)
+   */
+  @Test(groups = "Functional")
+  public void TestUpdateLayout_endRes()
+  {
+    // get details of original alignment dimensions
+    ViewportRanges ranges = af.getViewport().getRanges();
+    int endres = ranges.getEndRes();
+
+    // wrap
+    af.alignPanel.getAlignViewport().setWrapAlignment(true);
+    af.alignPanel.updateLayout();
+
+    // endRes has changed
+    assertNotEquals(ranges.getEndRes(), endres);
+
+    // unwrap
+    af.alignPanel.getAlignViewport().setWrapAlignment(false);
+    af.alignPanel.updateLayout();
+
+    // endRes back to original value
+    assertEquals(ranges.getEndRes(), endres);
+
+  }
 }