2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertSame;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.datamodel.Alignment;
28 import jalview.datamodel.Sequence;
29 import jalview.datamodel.SequenceI;
30 import jalview.viewmodel.AlignmentViewport;
32 import java.awt.Component;
33 import java.util.List;
36 import javax.swing.JPanel;
38 import org.testng.annotations.AfterMethod;
39 import org.testng.annotations.BeforeMethod;
40 import org.testng.annotations.Test;
42 public class PaintRefresherTest
44 // TODO would prefer PaintRefresher to be a single rather than static
45 @BeforeMethod(alwaysRun = true)
48 PaintRefresher.components.clear();
52 public void tearDown()
54 PaintRefresher.components.clear();
57 @Test(groups = { "Functional" })
58 public void testRegister()
60 JPanel jp = new JPanel();
61 JPanel jp2 = new JPanel();
62 JPanel jp3 = new JPanel();
63 JPanel jp4 = new JPanel();
64 PaintRefresher.Register(jp, "22");
65 PaintRefresher.Register(jp, "22");
66 PaintRefresher.Register(jp2, "22");
67 PaintRefresher.Register(jp3, "33");
68 PaintRefresher.Register(jp3, "44");
69 PaintRefresher.Register(jp4, "44");
71 Map<String, List<Component>> registered = PaintRefresher.components;
72 assertEquals(3, registered.size());
73 assertEquals(2, registered.get("22").size());
74 assertEquals(1, registered.get("33").size());
75 assertEquals(2, registered.get("44").size());
76 assertTrue(registered.get("22").contains(jp));
77 assertTrue(registered.get("22").contains(jp2));
78 assertTrue(registered.get("33").contains(jp3));
79 assertTrue(registered.get("44").contains(jp3));
80 assertTrue(registered.get("44").contains(jp4));
83 @Test(groups = { "Functional" })
84 public void testRemoveComponent()
86 Map<String, List<Component>> registered = PaintRefresher.components;
88 // no error with an empty PaintRefresher
89 JPanel jp = new JPanel();
90 JPanel jp2 = new JPanel();
91 PaintRefresher.RemoveComponent(jp);
92 assertTrue(registered.isEmpty());
95 * Add then remove one item
97 PaintRefresher.Register(jp, "11");
98 PaintRefresher.RemoveComponent(jp);
99 assertTrue(registered.isEmpty());
102 * Add one item under two ids, then remove it. It is removed from both ids,
103 * and the now empty id is removed.
105 PaintRefresher.Register(jp, "11");
106 PaintRefresher.Register(jp, "22");
107 PaintRefresher.Register(jp2, "22");
108 PaintRefresher.RemoveComponent(jp);
109 // "11" is removed as now empty, only 22/jp2 left
110 assertEquals(1, registered.size());
111 assertEquals(1, registered.get("22").size());
112 assertTrue(registered.get("22").contains(jp2));
115 @Test(groups = { "Functional" })
116 public void testGetAssociatedPanels()
118 SequenceI[] seqs = new SequenceI[] { new Sequence("", "ABC") };
119 Alignment al = new Alignment(seqs);
122 * AlignFrame constructor has side-effects: AlignmentPanel is constructed,
123 * and SeqCanvas, IdPanel, AlignmentPanel are all registered under the
124 * sequence set id of the viewport.
126 AlignmentViewport av = new AlignViewport(al);
127 AlignFrame af = new AlignFrame(al, 4, 1);
128 AlignmentPanel ap1 = af.alignPanel;
129 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(av
130 .getSequenceSetId());
131 assertEquals(1, panels.length);
132 assertSame(ap1, panels[0]);
134 panels = PaintRefresher.getAssociatedPanels(av.getSequenceSetId() + 1);
135 assertEquals(0, panels.length);