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.BeforeClass;
40 import org.testng.annotations.BeforeMethod;
41 import org.testng.annotations.Test;
43 public class PaintRefresherTest
46 @BeforeClass(alwaysRun = true)
47 public void setUpJvOptionPane()
49 JvOptionPane.setInteractiveMode(false);
50 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
53 // TODO would prefer PaintRefresher to be a single rather than static
54 @BeforeMethod(alwaysRun = true)
57 PaintRefresher.components.clear();
60 @AfterMethod(alwaysRun = true)
61 public void tearDown()
63 PaintRefresher.components.clear();
66 @Test(groups = { "Functional" })
67 public void testRegister()
69 JPanel jp = new JPanel();
70 JPanel jp2 = new JPanel();
71 JPanel jp3 = new JPanel();
72 JPanel jp4 = new JPanel();
73 PaintRefresher.Register(jp, "22");
74 PaintRefresher.Register(jp, "22");
75 PaintRefresher.Register(jp2, "22");
76 PaintRefresher.Register(jp3, "33");
77 PaintRefresher.Register(jp3, "44");
78 PaintRefresher.Register(jp4, "44");
80 Map<String, List<Component>> registered = PaintRefresher.components;
81 assertEquals(3, registered.size());
82 assertEquals(2, registered.get("22").size());
83 assertEquals(1, registered.get("33").size());
84 assertEquals(2, registered.get("44").size());
85 assertTrue(registered.get("22").contains(jp));
86 assertTrue(registered.get("22").contains(jp2));
87 assertTrue(registered.get("33").contains(jp3));
88 assertTrue(registered.get("44").contains(jp3));
89 assertTrue(registered.get("44").contains(jp4));
92 @Test(groups = { "Functional" })
93 public void testRemoveComponent()
95 Map<String, List<Component>> registered = PaintRefresher.components;
97 // no error with an empty PaintRefresher
98 JPanel jp = new JPanel();
99 JPanel jp2 = new JPanel();
100 PaintRefresher.RemoveComponent(jp);
101 assertTrue(registered.isEmpty());
104 * Add then remove one item
106 PaintRefresher.Register(jp, "11");
107 PaintRefresher.RemoveComponent(jp);
108 assertTrue(registered.isEmpty());
111 * Add one item under two ids, then remove it. It is removed from both ids,
112 * and the now empty id is removed.
114 PaintRefresher.Register(jp, "11");
115 PaintRefresher.Register(jp, "22");
116 PaintRefresher.Register(jp2, "22");
117 PaintRefresher.RemoveComponent(jp);
118 // "11" is removed as now empty, only 22/jp2 left
119 assertEquals(1, registered.size());
120 assertEquals(1, registered.get("22").size());
121 assertTrue(registered.get("22").contains(jp2));
124 @Test(groups = { "Functional" })
125 public void testGetAssociatedPanels()
127 SequenceI[] seqs = new SequenceI[] { new Sequence("", "ABC") };
128 Alignment al = new Alignment(seqs);
131 * AlignFrame constructor has side-effects: AlignmentPanel is constructed,
132 * and SeqCanvas, IdPanel, AlignmentPanel are all registered under the
133 * sequence set id of the viewport.
135 AlignmentViewport av = new AlignViewport(al);
136 AlignFrame af = new AlignFrame(al, 4, 1);
137 AlignmentPanel ap1 = af.alignPanel;
138 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(av
139 .getSequenceSetId());
140 assertEquals(1, panels.length);
141 assertSame(ap1, panels[0]);
143 panels = PaintRefresher.getAssociatedPanels(av.getSequenceSetId() + 1);
144 assertEquals(0, panels.length);