From: kiramt Date: Tue, 21 Feb 2017 10:14:01 +0000 (+0000) Subject: JAL-2421 Unit test X-Git-Tag: Release_2_10_3b1~339^2~1^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b829ed00ada9a60dbfc690fc34ec2386273ddf2d;p=jalview.git JAL-2421 Unit test --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 3d64798..d793e6a 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -688,7 +688,6 @@ public class AlignmentPanel extends GAlignmentPanel implements */ public void setScrollValues(int x, int y) { - // System.err.println("Scroll " + this.av.viewName + " to " + x + "," + y); if (av == null || av.getAlignment() == null) { return; @@ -698,6 +697,7 @@ public class AlignmentPanel extends GAlignmentPanel implements if (av.hasHiddenColumns()) { + // reset the width to exclude hidden columns width = av.getColumnSelection().findColumnPosition(width); } diff --git a/test/jalview/gui/AlignmentPanelTest.java b/test/jalview/gui/AlignmentPanelTest.java index b77dd98..f3b6876 100644 --- a/test/jalview/gui/AlignmentPanelTest.java +++ b/test/jalview/gui/AlignmentPanelTest.java @@ -22,13 +22,14 @@ package jalview.gui; import static org.testng.Assert.assertEquals; -import jalview.datamodel.Alignment; +import jalview.bin.Cache; +import jalview.bin.Jalview; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; +import jalview.io.FileLoader; -import java.awt.Dimension; - -import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class AlignmentPanelTest @@ -125,13 +126,37 @@ public class AlignmentPanelTest "Seq23", "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); - @BeforeClass(alwaysRun = true) + AlignFrame af; + + @BeforeMethod(alwaysRun = true) public void setUp() { - JvOptionPane.setInteractiveMode(false); - JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + Jalview.main(new String[] { "-nonews", "-props", + "test/jalview/testProps.jvprops" }); + + Cache.applicationProperties.setProperty("SHOW_IDENTITY", + Boolean.TRUE.toString()); + af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa", + DataSourceType.FILE); + + /* + * wait for Consensus thread to complete + */ + synchronized (this) + { + while (af.getViewport().getConsensusSeq() == null) + { + try + { + wait(50); + } catch (InterruptedException e) + { + } + } + } } + /** * Test side effect that end residue is set correctly by setScrollValues, with * or without hidden columns @@ -139,32 +164,54 @@ public class AlignmentPanelTest @Test(groups = "Functional") public void TestSetScrollValues() { - SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5, - seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15, - seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 }; - Alignment al = new Alignment(seqs); - al.setDataset(null); - - AlignFrame alignFrame = new AlignFrame(al, 500, 700); - - alignFrame.alignPanel.getSeqPanel().seqCanvas - .setPreferredSize(new Dimension(300, 300)); - - int oldres = alignFrame.getViewport().getEndRes(); - alignFrame.alignPanel.setScrollValues(-1, 5); + int oldres = af.getViewport().getEndRes(); + af.alignPanel.setScrollValues(-1, 5); // setting -ve x value does not change residue - assertEquals(alignFrame.getViewport().getEndRes(), oldres); + assertEquals(af.getViewport().getEndRes(), oldres); - alignFrame.alignPanel.setScrollValues(0, 5); + af.alignPanel.setScrollValues(0, 5); // setting 0 as x value does not change residue - assertEquals(alignFrame.getViewport().getEndRes(), oldres); - - alignFrame.alignPanel.setScrollValues(5, 5); - // setting x value to 20 extends endRes by 20px converted to residues - assertEquals(alignFrame.getViewport().getEndRes(), oldres + 5); - - + assertEquals(af.getViewport().getEndRes(), oldres); + + af.alignPanel.setScrollValues(5, 5); + // setting x value to 5 extends endRes by 5 residues + assertEquals(af.getViewport().getEndRes(), oldres + 5); + + // scroll to position after hidden columns sets endres to oldres (width) + + // position + int scrollpos = 60; + af.getViewport().hideColumns(30, 50); + af.alignPanel.setScrollValues(scrollpos, 5); + assertEquals(af.getViewport().getEndRes(), oldres + scrollpos); + + // scroll to position within hidden columns, still sets endres to oldres + + // position + // not sure if this is actually correct behaviour but this is what Jalview + // currently does + scrollpos = 40; + af.getViewport().showAllHiddenColumns(); + af.getViewport().hideColumns(30, 50); + af.alignPanel.setScrollValues(scrollpos, 5); + assertEquals(af.getViewport().getEndRes(), oldres + scrollpos); + + // scroll to position within distance of the end of the alignment + // endRes should be set to width of alignment - 1 + scrollpos = 130; + af.getViewport().showAllHiddenColumns(); + af.alignPanel.setScrollValues(scrollpos, 5); + assertEquals(af.getViewport().getEndRes(), af.getViewport() + .getAlignment().getWidth() - 1); + + // now hide some columns, and scroll to position within + // distance of the end of the alignment + // endRes should be set to width of alignment - 1 - the number of hidden + // columns + af.getViewport().hideColumns(30, 50); + af.alignPanel.setScrollValues(scrollpos, 5); + assertEquals(af.getViewport().getEndRes(), af.getViewport() + .getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden + // columns } }