JAL-2759 Unit test for PopupMenu hideInsertions code
[jalview.git] / test / jalview / gui / PopupMenuTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import static jalview.util.UrlConstants.DB_ACCESSION;
24 import static jalview.util.UrlConstants.SEQUENCE_ID;
25 import static org.testng.AssertJUnit.assertEquals;
26 import static org.testng.AssertJUnit.assertFalse;
27 import static org.testng.AssertJUnit.assertTrue;
28
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.ColumnSelection;
33 import jalview.datamodel.DBRefEntry;
34 import jalview.datamodel.DBRefSource;
35 import jalview.datamodel.HiddenColumns;
36 import jalview.datamodel.Sequence;
37 import jalview.datamodel.SequenceGroup;
38 import jalview.datamodel.SequenceI;
39 import jalview.io.DataSourceType;
40 import jalview.io.FileFormat;
41 import jalview.io.FormatAdapter;
42 import jalview.util.MessageManager;
43
44 import java.awt.Component;
45 import java.io.IOException;
46 import java.util.ArrayList;
47 import java.util.Iterator;
48 import java.util.List;
49
50 import javax.swing.JMenu;
51 import javax.swing.JMenuItem;
52 import javax.swing.JPopupMenu;
53 import javax.swing.JSeparator;
54
55 import org.testng.annotations.BeforeClass;
56 import org.testng.annotations.BeforeMethod;
57 import org.testng.annotations.Test;
58
59 public class PopupMenuTest
60 {
61
62   @BeforeClass(alwaysRun = true)
63   public void setUpJvOptionPane()
64   {
65     JvOptionPane.setInteractiveMode(false);
66     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
67   }
68
69   // 4 sequences x 13 positions
70   final static String TEST_DATA = ">FER_CAPAA Ferredoxin\n"
71           + "TIETHKEAELVG-\n"
72           + ">FER_CAPAN Ferredoxin, chloroplast precursor\n"
73           + "TIETHKEAELVG-\n"
74           + ">FER1_SOLLC Ferredoxin-1, chloroplast precursor\n"
75           + "TIETHKEEELTA-\n" + ">Q93XJ9_SOLTU Ferredoxin I precursor\n"
76           + "TIETHKEEELTA-\n";
77
78   AlignmentI alignment;
79
80   AlignmentPanel parentPanel;
81
82   PopupMenu testee = null;
83
84   @BeforeMethod(alwaysRun = true)
85   public void setUp() throws IOException
86   {
87     alignment = new FormatAdapter().readFile(TEST_DATA,
88             DataSourceType.PASTE, FileFormat.Fasta);
89     AlignFrame af = new AlignFrame(alignment, 700, 500);
90     parentPanel = new AlignmentPanel(af, af.getViewport());
91     testee = new PopupMenu(parentPanel, null, null);
92     int i = 0;
93     for (SequenceI seq : alignment.getSequences())
94     {
95       final AlignmentAnnotation annotation = new AlignmentAnnotation(
96               "label" + i, "desc" + i, i);
97       annotation.setCalcId("calcId" + i);
98       seq.addAlignmentAnnotation(annotation);
99       annotation.setSequenceRef(seq);
100     }
101   }
102
103   @Test(groups = { "Functional" })
104   public void testConfigureReferenceAnnotationsMenu_noSequenceSelected()
105   {
106     JMenuItem menu = new JMenuItem();
107     List<SequenceI> seqs = new ArrayList<>();
108     testee.configureReferenceAnnotationsMenu(menu, seqs);
109     assertFalse(menu.isEnabled());
110     // now try null list
111     menu.setEnabled(true);
112     testee.configureReferenceAnnotationsMenu(menu, null);
113     assertFalse(menu.isEnabled());
114   }
115
116   /**
117    * Test building the 'add reference annotations' menu for the case where there
118    * are no reference annotations to add to the alignment. The menu item should
119    * be disabled.
120    */
121   @Test(groups = { "Functional" })
122   public void testConfigureReferenceAnnotationsMenu_noReferenceAnnotations()
123   {
124     JMenuItem menu = new JMenuItem();
125
126     /*
127      * Initial state is that sequences have annotations, and have dataset
128      * sequences, but the dataset sequences have no annotations. Hence nothing
129      * to add.
130      */
131     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
132
133     testee.configureReferenceAnnotationsMenu(menu, seqs);
134     assertFalse(menu.isEnabled());
135   }
136
137   /**
138    * Test building the 'add reference annotations' menu for the case where all
139    * reference annotations are already on the alignment. The menu item should be
140    * disabled.
141    */
142   @Test(groups = { "Functional" })
143   public void testConfigureReferenceAnnotationsMenu_alreadyAdded()
144   {
145     JMenuItem menu = new JMenuItem();
146     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
147
148     // make up new annotations and add to dataset sequences, sequences and
149     // alignment
150     attachReferenceAnnotations(seqs, true, true);
151
152     testee.configureReferenceAnnotationsMenu(menu, seqs);
153     assertFalse(menu.isEnabled());
154   }
155
156   /**
157    * Test building the 'add reference annotations' menu for the case where
158    * several reference annotations are on the dataset but not on the sequences.
159    * The menu item should be enabled, and acquire a tooltip which lists the
160    * annotation sources (calcIds) and type (labels).
161    */
162   @Test(groups = { "Functional" })
163   public void testConfigureReferenceAnnotationsMenu()
164   {
165     JMenuItem menu = new JMenuItem();
166     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
167
168     // make up new annotations and add to dataset sequences
169     attachReferenceAnnotations(seqs, false, false);
170
171     testee.configureReferenceAnnotationsMenu(menu, seqs);
172     assertTrue(menu.isEnabled());
173     String s = MessageManager.getString("label.add_annotations_for");
174     String expected = "<html><style> p.ttip {width: 350; text-align: justify; word-wrap: break-word;}</style><p class=\"ttip\">"
175             + s + "<br/>Jmol/secondary structure<br/>PDB/Temp</p></html>";
176     assertEquals(expected, menu.getToolTipText());
177   }
178
179   /**
180    * Test building the 'add reference annotations' menu for the case where
181    * several reference annotations are on the dataset and the sequences but not
182    * on the alignment. The menu item should be enabled, and acquire a tooltip
183    * which lists the annotation sources (calcIds) and type (labels).
184    */
185   @Test(groups = { "Functional" })
186   public void testConfigureReferenceAnnotationsMenu_notOnAlignment()
187   {
188     JMenuItem menu = new JMenuItem();
189     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
190
191     // make up new annotations and add to dataset sequences and sequences
192     attachReferenceAnnotations(seqs, true, false);
193
194     testee.configureReferenceAnnotationsMenu(menu, seqs);
195     assertTrue(menu.isEnabled());
196     String s = MessageManager.getString("label.add_annotations_for");
197     String expected = "<html><style> p.ttip {width: 350; text-align: justify; word-wrap: break-word;}</style><p class=\"ttip\">"
198             + s + "<br/>Jmol/secondary structure<br/>PDB/Temp</p></html>";
199     assertEquals(expected, menu.getToolTipText());
200   }
201
202   /**
203    * Generate annotations and add to dataset sequences and (optionally)
204    * sequences and/or alignment
205    * 
206    * @param seqs
207    * @param addToSequence
208    * @param addToAlignment
209    */
210   private void attachReferenceAnnotations(List<SequenceI> seqs,
211           boolean addToSequence, boolean addToAlignment)
212   {
213     // PDB.secondary structure on Sequence0
214     AlignmentAnnotation annotation = new AlignmentAnnotation(
215             "secondary structure", "", 0);
216     annotation.setCalcId("PDB");
217     seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
218     if (addToSequence)
219     {
220       seqs.get(0).addAlignmentAnnotation(annotation);
221     }
222     if (addToAlignment)
223     {
224       this.alignment.addAnnotation(annotation);
225     }
226
227     // PDB.Temp on Sequence1
228     annotation = new AlignmentAnnotation("Temp", "", 0);
229     annotation.setCalcId("PDB");
230     seqs.get(1).getDatasetSequence().addAlignmentAnnotation(annotation);
231     if (addToSequence)
232     {
233       seqs.get(1).addAlignmentAnnotation(annotation);
234     }
235     if (addToAlignment)
236     {
237       this.alignment.addAnnotation(annotation);
238     }
239
240     // JMOL.secondary structure on Sequence0
241     annotation = new AlignmentAnnotation("secondary structure", "", 0);
242     annotation.setCalcId("Jmol");
243     seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
244     if (addToSequence)
245     {
246       seqs.get(0).addAlignmentAnnotation(annotation);
247     }
248     if (addToAlignment)
249     {
250       this.alignment.addAnnotation(annotation);
251     }
252   }
253
254   /**
255    * Test building the 'add reference annotations' menu for the case where there
256    * are two alignment views:
257    * <ul>
258    * <li>in one view, reference annotations have been added (are on the
259    * datasets, sequences and alignment)</li>
260    * <li>in the current view, reference annotations are on the dataset and
261    * sequence, but not the alignment</li>
262    * </ul>
263    * The menu item should be enabled, and acquire a tooltip which lists the
264    * annotation sources (calcIds) and type (labels).
265    */
266   @Test(groups = { "Functional" })
267   public void testConfigureReferenceAnnotationsMenu_twoViews()
268   {
269   }
270
271   /**
272    * Test for building menu options including 'show' and 'hide' annotation
273    * types.
274    */
275   @Test(groups = { "Functional" })
276   public void testBuildAnnotationTypesMenus()
277   {
278     JMenu showMenu = new JMenu();
279     JMenu hideMenu = new JMenu();
280     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
281
282     // make up new annotations and add to sequences and to the alignment
283
284     // PDB.secondary structure on Sequence0
285     AlignmentAnnotation annotation = new AlignmentAnnotation(
286             "secondary structure", "", new Annotation[] {});
287     annotation.setCalcId("PDB");
288     annotation.visible = true;
289     seqs.get(0).addAlignmentAnnotation(annotation);
290     parentPanel.getAlignment().addAnnotation(annotation);
291
292     // JMOL.secondary structure on Sequence0 - hidden
293     annotation = new AlignmentAnnotation("secondary structure", "",
294             new Annotation[] {});
295     annotation.setCalcId("JMOL");
296     annotation.visible = false;
297     seqs.get(0).addAlignmentAnnotation(annotation);
298     parentPanel.getAlignment().addAnnotation(annotation);
299
300     // Jpred.SSP on Sequence0 - hidden
301     annotation = new AlignmentAnnotation("SSP", "", new Annotation[] {});
302     annotation.setCalcId("JPred");
303     annotation.visible = false;
304     seqs.get(0).addAlignmentAnnotation(annotation);
305     parentPanel.getAlignment().addAnnotation(annotation);
306
307     // PDB.Temp on Sequence1
308     annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
309     annotation.setCalcId("PDB");
310     annotation.visible = true;
311     seqs.get(1).addAlignmentAnnotation(annotation);
312     parentPanel.getAlignment().addAnnotation(annotation);
313
314     /*
315      * Expect menu options to show "secondary structure" and "SSP", and to hide
316      * "secondary structure" and "Temp". Tooltip should be calcId.
317      */
318     testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
319
320     assertTrue(showMenu.isEnabled());
321     assertTrue(hideMenu.isEnabled());
322
323     Component[] showOptions = showMenu.getMenuComponents();
324     Component[] hideOptions = hideMenu.getMenuComponents();
325
326     assertEquals(4, showOptions.length); // includes 'All' and separator
327     assertEquals(4, hideOptions.length);
328     String all = MessageManager.getString("label.all");
329     assertEquals(all, ((JMenuItem) showOptions[0]).getText());
330     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
331     assertEquals(JSeparator.HORIZONTAL,
332             ((JSeparator) showOptions[1]).getOrientation());
333     assertEquals("secondary structure",
334             ((JMenuItem) showOptions[2]).getText());
335     assertEquals("JMOL", ((JMenuItem) showOptions[2]).getToolTipText());
336     assertEquals("SSP", ((JMenuItem) showOptions[3]).getText());
337     assertEquals("JPred", ((JMenuItem) showOptions[3]).getToolTipText());
338
339     assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
340     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
341     assertEquals(JSeparator.HORIZONTAL,
342             ((JSeparator) hideOptions[1]).getOrientation());
343     assertEquals("secondary structure",
344             ((JMenuItem) hideOptions[2]).getText());
345     assertEquals("PDB", ((JMenuItem) hideOptions[2]).getToolTipText());
346     assertEquals("Temp", ((JMenuItem) hideOptions[3]).getText());
347     assertEquals("PDB", ((JMenuItem) hideOptions[3]).getToolTipText());
348   }
349
350   /**
351    * Test for building menu options with only 'hide' annotation types enabled.
352    */
353   @Test(groups = { "Functional" })
354   public void testBuildAnnotationTypesMenus_showDisabled()
355   {
356     JMenu showMenu = new JMenu();
357     JMenu hideMenu = new JMenu();
358     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
359
360     // make up new annotations and add to sequences and to the alignment
361
362     // PDB.secondary structure on Sequence0
363     AlignmentAnnotation annotation = new AlignmentAnnotation(
364             "secondary structure", "", new Annotation[] {});
365     annotation.setCalcId("PDB");
366     annotation.visible = true;
367     seqs.get(0).addAlignmentAnnotation(annotation);
368     parentPanel.getAlignment().addAnnotation(annotation);
369
370     // PDB.Temp on Sequence1
371     annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
372     annotation.setCalcId("PDB");
373     annotation.visible = true;
374     seqs.get(1).addAlignmentAnnotation(annotation);
375     parentPanel.getAlignment().addAnnotation(annotation);
376
377     /*
378      * Expect menu options to hide "secondary structure" and "Temp". Tooltip
379      * should be calcId. 'Show' menu should be disabled.
380      */
381     testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
382
383     assertFalse(showMenu.isEnabled());
384     assertTrue(hideMenu.isEnabled());
385
386     Component[] showOptions = showMenu.getMenuComponents();
387     Component[] hideOptions = hideMenu.getMenuComponents();
388
389     assertEquals(2, showOptions.length); // includes 'All' and separator
390     assertEquals(4, hideOptions.length);
391     String all = MessageManager.getString("label.all");
392     assertEquals(all, ((JMenuItem) showOptions[0]).getText());
393     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
394     assertEquals(JSeparator.HORIZONTAL,
395             ((JSeparator) showOptions[1]).getOrientation());
396
397     assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
398     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
399     assertEquals(JSeparator.HORIZONTAL,
400             ((JSeparator) hideOptions[1]).getOrientation());
401     assertEquals("secondary structure",
402             ((JMenuItem) hideOptions[2]).getText());
403     assertEquals("PDB", ((JMenuItem) hideOptions[2]).getToolTipText());
404     assertEquals("Temp", ((JMenuItem) hideOptions[3]).getText());
405     assertEquals("PDB", ((JMenuItem) hideOptions[3]).getToolTipText());
406   }
407
408   /**
409    * Test for building menu options with only 'show' annotation types enabled.
410    */
411   @Test(groups = { "Functional" })
412   public void testBuildAnnotationTypesMenus_hideDisabled()
413   {
414     JMenu showMenu = new JMenu();
415     JMenu hideMenu = new JMenu();
416     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
417
418     // make up new annotations and add to sequences and to the alignment
419
420     // PDB.secondary structure on Sequence0
421     AlignmentAnnotation annotation = new AlignmentAnnotation(
422             "secondary structure", "", new Annotation[] {});
423     annotation.setCalcId("PDB");
424     annotation.visible = false;
425     seqs.get(0).addAlignmentAnnotation(annotation);
426     parentPanel.getAlignment().addAnnotation(annotation);
427
428     // PDB.Temp on Sequence1
429     annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
430     annotation.setCalcId("PDB2");
431     annotation.visible = false;
432     seqs.get(1).addAlignmentAnnotation(annotation);
433     parentPanel.getAlignment().addAnnotation(annotation);
434
435     /*
436      * Expect menu options to show "secondary structure" and "Temp". Tooltip
437      * should be calcId. 'hide' menu should be disabled.
438      */
439     testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
440
441     assertTrue(showMenu.isEnabled());
442     assertFalse(hideMenu.isEnabled());
443
444     Component[] showOptions = showMenu.getMenuComponents();
445     Component[] hideOptions = hideMenu.getMenuComponents();
446
447     assertEquals(4, showOptions.length); // includes 'All' and separator
448     assertEquals(2, hideOptions.length);
449     String all = MessageManager.getString("label.all");
450     assertEquals(all, ((JMenuItem) showOptions[0]).getText());
451     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
452     assertEquals(JSeparator.HORIZONTAL,
453             ((JSeparator) showOptions[1]).getOrientation());
454     assertEquals("secondary structure",
455             ((JMenuItem) showOptions[2]).getText());
456     assertEquals("PDB", ((JMenuItem) showOptions[2]).getToolTipText());
457     assertEquals("Temp", ((JMenuItem) showOptions[3]).getText());
458     assertEquals("PDB2", ((JMenuItem) showOptions[3]).getToolTipText());
459
460     assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
461     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
462     assertEquals(JSeparator.HORIZONTAL,
463             ((JSeparator) hideOptions[1]).getOrientation());
464   }
465
466   /**
467    * Test for adding feature links
468    */
469   @Test(groups = { "Functional" })
470   public void testAddFeatureLinks()
471   {
472     // sequences from the alignment
473     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
474
475     // create list of links and list of DBRefs
476     List<String> links = new ArrayList<>();
477     List<DBRefEntry> refs = new ArrayList<>();
478
479     // links as might be added into Preferences | Connections dialog
480     links.add("EMBL-EBI Search | http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$"
481             + SEQUENCE_ID + "$");
482     links.add("UNIPROT | http://www.uniprot.org/uniprot/$" + DB_ACCESSION
483             + "$");
484     links.add("INTERPRO | http://www.ebi.ac.uk/interpro/entry/$"
485             + DB_ACCESSION + "$");
486     // Gene3D entry tests for case (in)sensitivity
487     links.add("Gene3D | http://gene3d.biochem.ucl.ac.uk/Gene3D/search?sterm=$"
488             + DB_ACCESSION + "$&mode=protein");
489
490     // make seq0 dbrefs
491     refs.add(new DBRefEntry(DBRefSource.UNIPROT, "1", "P83527"));
492     refs.add(new DBRefEntry("INTERPRO", "1", "IPR001041"));
493     refs.add(new DBRefEntry("INTERPRO", "1", "IPR006058"));
494     refs.add(new DBRefEntry("INTERPRO", "1", "IPR012675"));
495     
496     // make seq1 dbrefs
497     refs.add(new DBRefEntry(DBRefSource.UNIPROT, "1", "Q9ZTS2"));
498     refs.add(new DBRefEntry("GENE3D", "1", "3.10.20.30"));
499
500     // add all the dbrefs to the sequences: Uniprot 1 each, Interpro all 3 to
501     // seq0, Gene3D to seq1
502     seqs.get(0).addDBRef(refs.get(0));
503
504     seqs.get(0).addDBRef(refs.get(1));
505     seqs.get(0).addDBRef(refs.get(2));
506     seqs.get(0).addDBRef(refs.get(3));
507     
508     seqs.get(1).addDBRef(refs.get(4));
509     seqs.get(1).addDBRef(refs.get(5));
510     
511     // get the Popup Menu for first sequence
512     testee = new PopupMenu(parentPanel, (Sequence) seqs.get(0), links);
513     Component[] seqItems = testee.sequenceMenu.getMenuComponents();
514     JMenu linkMenu = (JMenu) seqItems[6];
515     Component[] linkItems = linkMenu.getMenuComponents();
516     
517     // check the number of links are the expected number
518     assertEquals(5, linkItems.length);
519
520     // first entry is EMBL-EBI which just uses sequence id not accession id?
521     assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
522
523     // sequence id for each link should match corresponding DB accession id
524     for (int i = 1; i < 4; i++)
525     {
526       assertEquals(refs.get(i - 1).getSource(), ((JMenuItem) linkItems[i])
527               .getText().split("\\|")[0]);
528       assertEquals(refs.get(i - 1).getAccessionId(),
529               ((JMenuItem) linkItems[i])
530               .getText().split("\\|")[1]);
531     }
532
533     // get the Popup Menu for second sequence
534     testee = new PopupMenu(parentPanel, (Sequence) seqs.get(1), links);
535     seqItems = testee.sequenceMenu.getMenuComponents();
536     linkMenu = (JMenu) seqItems[6];
537     linkItems = linkMenu.getMenuComponents();
538     
539     // check the number of links are the expected number
540     assertEquals(3, linkItems.length);
541
542     // first entry is EMBL-EBI which just uses sequence id not accession id?
543     assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
544
545     // sequence id for each link should match corresponding DB accession id
546     for (int i = 1; i < 3; i++)
547     {
548       assertEquals(refs.get(i + 3).getSource(), ((JMenuItem) linkItems[i])
549               .getText().split("\\|")[0].toUpperCase());
550       assertEquals(refs.get(i + 3).getAccessionId(),
551               ((JMenuItem) linkItems[i]).getText().split("\\|")[1]);
552     }
553
554     // if there are no valid links the Links submenu is disabled
555     List<String> nomatchlinks = new ArrayList<>();
556     nomatchlinks.add("NOMATCH | http://www.uniprot.org/uniprot/$"
557             + DB_ACCESSION + "$");
558
559     testee = new PopupMenu(parentPanel, (Sequence) seqs.get(0),
560             nomatchlinks);
561     seqItems = testee.sequenceMenu.getMenuComponents();
562     linkMenu = (JMenu) seqItems[6];
563     assertFalse(linkMenu.isEnabled());
564
565   }
566
567   /**
568    * Test for adding feature links
569    */
570   @Test(groups = { "Functional" })
571   public void testHideInsertions()
572   {
573     // get sequences from the alignment
574     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
575     
576     // get the Popup Menu for first sequence - no insertions
577     testee = new PopupMenu(parentPanel, (Sequence) seqs.get(0), null);
578     testee.hideInsertions_actionPerformed(null);
579     
580     HiddenColumns hidden = parentPanel.av.getAlignment().getHiddenColumns();
581     Iterator<int[]> it = hidden.iterator();
582     assertFalse(it.hasNext());
583
584     Sequence seqGap1 = new Sequence("GappySeq",
585             "AAAA----AA-AAAAAAA---AAA-----------AAAAAAAAAA--");
586     seqGap1.createDatasetSequence();
587     seqs.add(seqGap1);
588     Sequence seqGap2 = new Sequence("LessGappySeq",
589             "AAAAAA-AAAAA---AAA--AAAAA--AAAAAAA-AAAAAA");
590     seqGap2.createDatasetSequence();
591     seqs.add(seqGap2);
592     Sequence seqGap3 = new Sequence("OneGapSeq",
593             "AAAAAA-AAAAAA--AAAAAA-AAAAAAAAAAA---AAAAAAAA");
594     seqGap3.createDatasetSequence();
595     seqs.add(seqGap3);
596
597     // get the Popup Menu for GappySeq - this time we have insertions
598     testee = new PopupMenu(parentPanel, (Sequence) seqs.get(4), null);
599     testee.hideInsertions_actionPerformed(null);
600     hidden = parentPanel.av.getAlignment().getHiddenColumns();
601     it = hidden.iterator();
602
603     assertTrue(it.hasNext());
604     int[] region = it.next();
605     assertEquals(region[0], 4);
606     assertEquals(region[1], 7);
607
608     assertTrue(it.hasNext());
609     region = it.next();
610     assertEquals(region[0], 10);
611     assertEquals(region[1], 10);
612
613     assertTrue(it.hasNext());
614     region = it.next();
615     assertEquals(region[0], 18);
616     assertEquals(region[1], 20);
617
618     assertTrue(it.hasNext());
619     region = it.next();
620     assertEquals(region[0], 24);
621     assertEquals(region[1], 34);
622
623     assertTrue(it.hasNext());
624     region = it.next();
625     assertEquals(region[0], 45);
626     assertEquals(region[1], 46);
627
628     assertFalse(it.hasNext());
629
630     ColumnSelection sel = new ColumnSelection();
631     hidden.revealAllHiddenColumns(sel);
632
633     // make a sequence group and hide insertions within the group
634     SequenceGroup sg = new SequenceGroup();
635     sg.setStartRes(8);
636     sg.setEndRes(42);
637     sg.addSequence(seqGap2, false);
638     sg.addSequence(seqGap3, false);
639     parentPanel.av.setSelectionGroup(sg);
640
641     // hide columns outside and within selection
642     // only hidden columns outside the collection will be retained (unless also
643     // gaps in the selection)
644     hidden.hideColumns(1, 10);
645     hidden.hideColumns(31, 40);
646
647     // get the Popup Menu for LessGappySeq in the sequence group
648     testee = new PopupMenu(parentPanel, (Sequence) seqs.get(5), null);
649     testee.hideInsertions_actionPerformed(null);
650     hidden = parentPanel.av.getAlignment().getHiddenColumns();
651     it = hidden.iterator();
652
653     assertTrue(it.hasNext());
654     region = it.next();
655     assertEquals(region[0], 1);
656     assertEquals(region[1], 7);
657
658     assertTrue(it.hasNext());
659     region = it.next();
660     assertEquals(region[0], 13);
661     assertEquals(region[1], 14);
662
663     assertTrue(it.hasNext());
664     region = it.next();
665     assertEquals(region[0], 34);
666     assertEquals(region[1], 34);
667   }
668
669 }