Clover icon

Coverage Report

  1. Project Clover database Tue Mar 10 2026 14:58:44 GMT
  2. Package jalview.gui

File PaintRefresherTest.java

 

Code metrics

0
49
6
1
146
93
6
0.12
8.17
6
1

Classes

Class Line # Actions
PaintRefresherTest 43 49 6
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

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 org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertSame;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import jalview.datamodel.Alignment;
28    import jalview.datamodel.Sequence;
29    import jalview.datamodel.SequenceI;
30    import jalview.viewmodel.AlignmentViewport;
31   
32    import java.awt.Component;
33    import java.util.List;
34    import java.util.Map;
35   
36    import javax.swing.JPanel;
37   
38    import org.testng.annotations.AfterMethod;
39    import org.testng.annotations.BeforeClass;
40    import org.testng.annotations.BeforeMethod;
41    import org.testng.annotations.Test;
42   
 
43    public class PaintRefresherTest
44    {
45   
 
46  0 toggle @BeforeClass(alwaysRun = true)
47    public void setUpJvOptionPane()
48    {
49  0 JvOptionPane.setInteractiveMode(false);
50  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
51    }
52   
53    // TODO would prefer PaintRefresher to be a single rather than static
 
54  0 toggle @BeforeMethod(alwaysRun = true)
55    public void setUp()
56    {
57  0 PaintRefresher.components.clear();
58    }
59   
 
60  0 toggle @AfterMethod(alwaysRun = true)
61    public void tearDown()
62    {
63  0 PaintRefresher.components.clear();
64    }
65   
 
66  0 toggle @Test(groups = { "Functional" })
67    public void testRegister()
68    {
69  0 JPanel jp = new JPanel();
70  0 JPanel jp2 = new JPanel();
71  0 JPanel jp3 = new JPanel();
72  0 JPanel jp4 = new JPanel();
73  0 PaintRefresher.Register(jp, "22");
74  0 PaintRefresher.Register(jp, "22");
75  0 PaintRefresher.Register(jp2, "22");
76  0 PaintRefresher.Register(jp3, "33");
77  0 PaintRefresher.Register(jp3, "44");
78  0 PaintRefresher.Register(jp4, "44");
79   
80  0 Map<String, List<Component>> registered = PaintRefresher.components;
81  0 assertEquals(3, registered.size());
82  0 assertEquals(2, registered.get("22").size());
83  0 assertEquals(1, registered.get("33").size());
84  0 assertEquals(2, registered.get("44").size());
85  0 assertTrue(registered.get("22").contains(jp));
86  0 assertTrue(registered.get("22").contains(jp2));
87  0 assertTrue(registered.get("33").contains(jp3));
88  0 assertTrue(registered.get("44").contains(jp3));
89  0 assertTrue(registered.get("44").contains(jp4));
90    }
91   
 
92  0 toggle @Test(groups = { "Functional" })
93    public void testRemoveComponent()
94    {
95  0 Map<String, List<Component>> registered = PaintRefresher.components;
96   
97    // no error with an empty PaintRefresher
98  0 JPanel jp = new JPanel();
99  0 JPanel jp2 = new JPanel();
100  0 PaintRefresher.RemoveComponent(jp);
101  0 assertTrue(registered.isEmpty());
102   
103    /*
104    * Add then remove one item
105    */
106  0 PaintRefresher.Register(jp, "11");
107  0 PaintRefresher.RemoveComponent(jp);
108  0 assertTrue(registered.isEmpty());
109   
110    /*
111    * Add one item under two ids, then remove it. It is removed from both ids,
112    * and the now empty id is removed.
113    */
114  0 PaintRefresher.Register(jp, "11");
115  0 PaintRefresher.Register(jp, "22");
116  0 PaintRefresher.Register(jp2, "22");
117  0 PaintRefresher.RemoveComponent(jp);
118    // "11" is removed as now empty, only 22/jp2 left
119  0 assertEquals(1, registered.size());
120  0 assertEquals(1, registered.get("22").size());
121  0 assertTrue(registered.get("22").contains(jp2));
122    }
123   
 
124  0 toggle @Test(groups = { "Functional" })
125    public void testGetAssociatedPanels()
126    {
127  0 SequenceI[] seqs = new SequenceI[] { new Sequence("", "ABC") };
128  0 Alignment al = new Alignment(seqs);
129   
130    /*
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.
134    */
135  0 AlignmentViewport av = new AlignViewport(al);
136  0 AlignFrame af = new AlignFrame(al, 4, 1);
137  0 AlignmentPanel ap1 = af.alignPanel;
138  0 AlignmentPanel[] panels = PaintRefresher
139    .getAssociatedPanels(av.getSequenceSetId());
140  0 assertEquals(1, panels.length);
141  0 assertSame(ap1, panels[0]);
142   
143  0 panels = PaintRefresher.getAssociatedPanels(av.getSequenceSetId() + 1);
144  0 assertEquals(0, panels.length);
145    }
146    }