From bce6bc4fda3db5c17c3141c0cb1b4a08c43a3042 Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 16 Jan 2018 12:15:07 +0000 Subject: [PATCH] JAL-2759 Unit test for PopupMenu hideInsertions code --- test/jalview/gui/PopupMenuTest.java | 115 +++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 4 deletions(-) diff --git a/test/jalview/gui/PopupMenuTest.java b/test/jalview/gui/PopupMenuTest.java index 335240b..7e077d0 100644 --- a/test/jalview/gui/PopupMenuTest.java +++ b/test/jalview/gui/PopupMenuTest.java @@ -29,9 +29,12 @@ import static org.testng.AssertJUnit.assertTrue; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; +import jalview.datamodel.ColumnSelection; import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; import jalview.io.FileFormat; @@ -41,6 +44,7 @@ import jalview.util.MessageManager; import java.awt.Component; import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import javax.swing.JMenu; @@ -100,7 +104,7 @@ public class PopupMenuTest public void testConfigureReferenceAnnotationsMenu_noSequenceSelected() { JMenuItem menu = new JMenuItem(); - List seqs = new ArrayList(); + List seqs = new ArrayList<>(); testee.configureReferenceAnnotationsMenu(menu, seqs); assertFalse(menu.isEnabled()); // now try null list @@ -469,8 +473,8 @@ public class PopupMenuTest List seqs = parentPanel.getAlignment().getSequences(); // create list of links and list of DBRefs - List links = new ArrayList(); - List refs = new ArrayList(); + List links = new ArrayList<>(); + List refs = new ArrayList<>(); // links as might be added into Preferences | Connections dialog links.add("EMBL-EBI Search | http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$" @@ -548,7 +552,7 @@ public class PopupMenuTest } // if there are no valid links the Links submenu is disabled - List nomatchlinks = new ArrayList(); + List nomatchlinks = new ArrayList<>(); nomatchlinks.add("NOMATCH | http://www.uniprot.org/uniprot/$" + DB_ACCESSION + "$"); @@ -559,4 +563,107 @@ public class PopupMenuTest assertFalse(linkMenu.isEnabled()); } + + /** + * Test for adding feature links + */ + @Test(groups = { "Functional" }) + public void testHideInsertions() + { + // get sequences from the alignment + List seqs = parentPanel.getAlignment().getSequences(); + + // get the Popup Menu for first sequence - no insertions + testee = new PopupMenu(parentPanel, (Sequence) seqs.get(0), null); + testee.hideInsertions_actionPerformed(null); + + HiddenColumns hidden = parentPanel.av.getAlignment().getHiddenColumns(); + Iterator it = hidden.iterator(); + assertFalse(it.hasNext()); + + Sequence seqGap1 = new Sequence("GappySeq", + "AAAA----AA-AAAAAAA---AAA-----------AAAAAAAAAA--"); + seqGap1.createDatasetSequence(); + seqs.add(seqGap1); + Sequence seqGap2 = new Sequence("LessGappySeq", + "AAAAAA-AAAAA---AAA--AAAAA--AAAAAAA-AAAAAA"); + seqGap2.createDatasetSequence(); + seqs.add(seqGap2); + Sequence seqGap3 = new Sequence("OneGapSeq", + "AAAAAA-AAAAAA--AAAAAA-AAAAAAAAAAA---AAAAAAAA"); + seqGap3.createDatasetSequence(); + seqs.add(seqGap3); + + // get the Popup Menu for GappySeq - this time we have insertions + testee = new PopupMenu(parentPanel, (Sequence) seqs.get(4), null); + testee.hideInsertions_actionPerformed(null); + hidden = parentPanel.av.getAlignment().getHiddenColumns(); + it = hidden.iterator(); + + assertTrue(it.hasNext()); + int[] region = it.next(); + assertEquals(region[0], 4); + assertEquals(region[1], 7); + + assertTrue(it.hasNext()); + region = it.next(); + assertEquals(region[0], 10); + assertEquals(region[1], 10); + + assertTrue(it.hasNext()); + region = it.next(); + assertEquals(region[0], 18); + assertEquals(region[1], 20); + + assertTrue(it.hasNext()); + region = it.next(); + assertEquals(region[0], 24); + assertEquals(region[1], 34); + + assertTrue(it.hasNext()); + region = it.next(); + assertEquals(region[0], 45); + assertEquals(region[1], 46); + + assertFalse(it.hasNext()); + + ColumnSelection sel = new ColumnSelection(); + hidden.revealAllHiddenColumns(sel); + + // make a sequence group and hide insertions within the group + SequenceGroup sg = new SequenceGroup(); + sg.setStartRes(8); + sg.setEndRes(42); + sg.addSequence(seqGap2, false); + sg.addSequence(seqGap3, false); + parentPanel.av.setSelectionGroup(sg); + + // hide columns outside and within selection + // only hidden columns outside the collection will be retained (unless also + // gaps in the selection) + hidden.hideColumns(1, 10); + hidden.hideColumns(31, 40); + + // get the Popup Menu for LessGappySeq in the sequence group + testee = new PopupMenu(parentPanel, (Sequence) seqs.get(5), null); + testee.hideInsertions_actionPerformed(null); + hidden = parentPanel.av.getAlignment().getHiddenColumns(); + it = hidden.iterator(); + + assertTrue(it.hasNext()); + region = it.next(); + assertEquals(region[0], 1); + assertEquals(region[1], 7); + + assertTrue(it.hasNext()); + region = it.next(); + assertEquals(region[0], 13); + assertEquals(region[1], 14); + + assertTrue(it.hasNext()); + region = it.next(); + assertEquals(region[0], 34); + assertEquals(region[1], 34); + } + } -- 1.7.10.2