Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 15:14:12 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
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

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  1 toggle @BeforeClass(alwaysRun = true)
47    public void setUpJvOptionPane()
48    {
49  1 JvOptionPane.setInteractiveMode(false);
50  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
51    }
52   
53    // TODO would prefer PaintRefresher to be a single rather than static
 
54  3 toggle @BeforeMethod(alwaysRun = true)
55    public void setUp()
56    {
57  3 PaintRefresher.components.clear();
58    }
59   
 
60  3 toggle @AfterMethod(alwaysRun = true)
61    public void tearDown()
62    {
63  3 PaintRefresher.components.clear();
64    }
65   
 
66  1 toggle @Test(groups = { "Functional" })
67    public void testRegister()
68    {
69  1 JPanel jp = new JPanel();
70  1 JPanel jp2 = new JPanel();
71  1 JPanel jp3 = new JPanel();
72  1 JPanel jp4 = new JPanel();
73  1 PaintRefresher.Register(jp, "22");
74  1 PaintRefresher.Register(jp, "22");
75  1 PaintRefresher.Register(jp2, "22");
76  1 PaintRefresher.Register(jp3, "33");
77  1 PaintRefresher.Register(jp3, "44");
78  1 PaintRefresher.Register(jp4, "44");
79   
80  1 Map<String, List<Component>> registered = PaintRefresher.components;
81  1 assertEquals(3, registered.size());
82  1 assertEquals(2, registered.get("22").size());
83  1 assertEquals(1, registered.get("33").size());
84  1 assertEquals(2, registered.get("44").size());
85  1 assertTrue(registered.get("22").contains(jp));
86  1 assertTrue(registered.get("22").contains(jp2));
87  1 assertTrue(registered.get("33").contains(jp3));
88  1 assertTrue(registered.get("44").contains(jp3));
89  1 assertTrue(registered.get("44").contains(jp4));
90    }
91   
 
92  1 toggle @Test(groups = { "Functional" })
93    public void testRemoveComponent()
94    {
95  1 Map<String, List<Component>> registered = PaintRefresher.components;
96   
97    // no error with an empty PaintRefresher
98  1 JPanel jp = new JPanel();
99  1 JPanel jp2 = new JPanel();
100  1 PaintRefresher.RemoveComponent(jp);
101  1 assertTrue(registered.isEmpty());
102   
103    /*
104    * Add then remove one item
105    */
106  1 PaintRefresher.Register(jp, "11");
107  1 PaintRefresher.RemoveComponent(jp);
108  1 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  1 PaintRefresher.Register(jp, "11");
115  1 PaintRefresher.Register(jp, "22");
116  1 PaintRefresher.Register(jp2, "22");
117  1 PaintRefresher.RemoveComponent(jp);
118    // "11" is removed as now empty, only 22/jp2 left
119  1 assertEquals(1, registered.size());
120  1 assertEquals(1, registered.get("22").size());
121  1 assertTrue(registered.get("22").contains(jp2));
122    }
123   
 
124  1 toggle @Test(groups = { "Functional" })
125    public void testGetAssociatedPanels()
126    {
127  1 SequenceI[] seqs = new SequenceI[] { new Sequence("", "ABC") };
128  1 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  1 AlignmentViewport av = new AlignViewport(al);
136  1 AlignFrame af = new AlignFrame(al, 4, 1);
137  1 AlignmentPanel ap1 = af.alignPanel;
138  1 AlignmentPanel[] panels = PaintRefresher
139    .getAssociatedPanels(av.getSequenceSetId());
140  1 assertEquals(1, panels.length);
141  1 assertSame(ap1, panels[0]);
142   
143  1 panels = PaintRefresher.getAssociatedPanels(av.getSequenceSetId() + 1);
144  1 assertEquals(0, panels.length);
145    }
146    }