1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertEquals; |
24 |
|
import static org.testng.Assert.assertFalse; |
25 |
|
import static org.testng.Assert.assertSame; |
26 |
|
import static org.testng.Assert.assertTrue; |
27 |
|
|
28 |
|
import jalview.bin.Cache; |
29 |
|
import jalview.datamodel.Alignment; |
30 |
|
import jalview.datamodel.AlignmentI; |
31 |
|
import jalview.datamodel.Sequence; |
32 |
|
import jalview.datamodel.SequenceI; |
33 |
|
import jalview.schemes.ClustalxColourScheme; |
34 |
|
import jalview.schemes.ColourSchemeI; |
35 |
|
import jalview.schemes.ColourSchemes; |
36 |
|
import jalview.schemes.NucleotideColourScheme; |
37 |
|
import jalview.schemes.PIDColourScheme; |
38 |
|
import jalview.schemes.ResidueColourScheme; |
39 |
|
import jalview.util.MessageManager; |
40 |
|
|
41 |
|
import java.util.Enumeration; |
42 |
|
import java.util.Iterator; |
43 |
|
|
44 |
|
import javax.swing.AbstractButton; |
45 |
|
import javax.swing.ButtonGroup; |
46 |
|
import javax.swing.JMenu; |
47 |
|
import javax.swing.JMenuItem; |
48 |
|
|
49 |
|
import org.testng.annotations.BeforeClass; |
50 |
|
import org.testng.annotations.Test; |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (129) |
Complexity: 16 |
Complexity Density: 0.16 |
|
52 |
|
public class ColourMenuHelperTest |
53 |
|
{ |
54 |
|
|
55 |
|
|
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
1 |
@BeforeClass(alwaysRun = true)... |
58 |
|
public void setUp() |
59 |
|
{ |
60 |
1 |
Cache.loadProperties("test/jalview/io/testProps.jvprops"); |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (39) |
Complexity: 5 |
Complexity Density: 0.16 |
1PASS
|
|
63 |
1 |
@Test(groups = "Functional")... |
64 |
|
public void testAddMenuItems_peptide() |
65 |
|
{ |
66 |
1 |
SequenceI s1 = new Sequence("s1", "KFRQSILM"); |
67 |
1 |
AlignmentI al = new Alignment(new SequenceI[] { s1 }); |
68 |
1 |
JMenu menu = new JMenu(); |
69 |
|
|
70 |
1 |
ButtonGroup bg = ColourMenuHelper.addMenuItems(menu, null, al, false); |
71 |
1 |
Enumeration<AbstractButton> bgElements = bg.getElements(); |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
1 |
JMenuItem item = menu.getItem(0); |
77 |
1 |
assertEquals(item.getName(), ResidueColourScheme.NONE); |
78 |
1 |
assertEquals(item.getText(), MessageManager.getString("label.none")); |
79 |
1 |
AbstractButton bgItem = bgElements.nextElement(); |
80 |
1 |
assertSame(bgItem, item); |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
1 |
Iterator<ColourSchemeI> colourSchemes = ColourSchemes.getInstance() |
88 |
|
.getColourSchemes().iterator(); |
89 |
1 |
final int items = menu.getItemCount(); |
90 |
21 |
for (int i = 1; i < items; i++) |
91 |
|
{ |
92 |
20 |
item = menu.getItem(i); |
93 |
20 |
bgItem = bgElements.nextElement(); |
94 |
20 |
assertSame(bgItem, item); |
95 |
20 |
ColourSchemeI cs = colourSchemes.next(); |
96 |
20 |
String name = cs.getSchemeName(); |
97 |
20 |
assertEquals(item.getName(), name); |
98 |
20 |
boolean enabled = item.isEnabled(); |
99 |
20 |
assertEquals(enabled, cs.isApplicableTo(al)); |
100 |
20 |
if (cs instanceof NucleotideColourScheme) |
101 |
|
{ |
102 |
1 |
assertFalse(enabled); |
103 |
|
} |
104 |
20 |
if (cs instanceof ClustalxColourScheme) |
105 |
|
{ |
106 |
1 |
assertTrue(enabled); |
107 |
|
} |
108 |
20 |
if (cs instanceof PIDColourScheme) |
109 |
|
{ |
110 |
1 |
assertTrue(enabled); |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
20 |
String label = MessageManager.getStringOrReturn("label.colourScheme_", |
117 |
|
name); |
118 |
20 |
assertEquals(item.getText(), label); |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
1 |
assertFalse(colourSchemes.hasNext()); |
125 |
1 |
assertFalse(bgElements.hasMoreElements()); |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 5 |
Complexity Density: 0.15 |
1PASS
|
|
128 |
1 |
@Test(groups = "Functional")... |
129 |
|
public void testAddMenuItems_nucleotide() |
130 |
|
{ |
131 |
1 |
SequenceI s1 = new Sequence("s1", "GAATAATCCATAACAG"); |
132 |
1 |
AlignmentI al = new Alignment(new SequenceI[] { s1 }); |
133 |
1 |
JMenu menu = new JMenu(); |
134 |
1 |
AlignFrame af = new AlignFrame(al, 500, 500); |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
1 |
PopupMenu popup = new PopupMenu(af.alignPanel, s1, null); |
140 |
1 |
ButtonGroup bg = ColourMenuHelper.addMenuItems(menu, popup, al, false); |
141 |
1 |
Enumeration<AbstractButton> bgElements = bg.getElements(); |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
1 |
JMenuItem item = menu.getItem(0); |
147 |
1 |
assertEquals(item.getName(), ResidueColourScheme.NONE); |
148 |
1 |
assertEquals(item.getText(), MessageManager.getString("label.none")); |
149 |
1 |
AbstractButton bgItem = bgElements.nextElement(); |
150 |
1 |
assertSame(bgItem, item); |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
1 |
Iterator<ColourSchemeI> colourSchemes = ColourSchemes.getInstance() |
158 |
|
.getColourSchemes().iterator(); |
159 |
1 |
final int items = menu.getItemCount(); |
160 |
21 |
for (int i = 1; i < items; i++) |
161 |
|
{ |
162 |
20 |
item = menu.getItem(i); |
163 |
20 |
bgItem = bgElements.nextElement(); |
164 |
20 |
assertSame(bgItem, item); |
165 |
20 |
ColourSchemeI cs = colourSchemes.next(); |
166 |
20 |
String name = cs.getSchemeName(); |
167 |
20 |
assertEquals(item.getName(), name); |
168 |
20 |
boolean enabled = item.isEnabled(); |
169 |
20 |
assertEquals(enabled, cs.isApplicableTo(al)); |
170 |
20 |
if (cs instanceof NucleotideColourScheme) |
171 |
|
{ |
172 |
1 |
assertTrue(enabled); |
173 |
|
} |
174 |
20 |
if (cs instanceof ClustalxColourScheme) |
175 |
|
{ |
176 |
1 |
assertFalse(enabled); |
177 |
|
} |
178 |
20 |
if (cs instanceof PIDColourScheme) |
179 |
|
{ |
180 |
1 |
assertTrue(enabled); |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
20 |
String label = MessageManager.getStringOrReturn("label.colourScheme_", |
187 |
|
name); |
188 |
20 |
assertEquals(item.getText(), label); |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
1 |
assertFalse(colourSchemes.hasNext()); |
195 |
1 |
assertFalse(bgElements.hasMoreElements()); |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 3 |
Complexity Density: 0.19 |
1PASS
|
|
205 |
1 |
@Test(groups = "Functional")... |
206 |
|
public void testAddMenuItems_simpleOnly() |
207 |
|
{ |
208 |
1 |
SequenceI s1 = new Sequence("s1", "KFRQSILM"); |
209 |
1 |
AlignmentI al = new Alignment(new SequenceI[] { s1 }); |
210 |
1 |
JMenu menu = new JMenu(); |
211 |
|
|
212 |
1 |
ButtonGroup bg = ColourMenuHelper.addMenuItems(menu, null, al, true); |
213 |
1 |
Enumeration<AbstractButton> bgElements = bg.getElements(); |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
1 |
Iterator<ColourSchemeI> colourSchemes = ColourSchemes.getInstance() |
219 |
|
.getColourSchemes().iterator(); |
220 |
1 |
int i = 0; |
221 |
21 |
while (colourSchemes.hasNext()) |
222 |
|
{ |
223 |
20 |
ColourSchemeI cs = colourSchemes.next(); |
224 |
20 |
if (!cs.isSimple()) |
225 |
|
{ |
226 |
6 |
continue; |
227 |
|
} |
228 |
14 |
JMenuItem item = menu.getItem(i++); |
229 |
14 |
AbstractButton bgItem = bgElements.nextElement(); |
230 |
14 |
assertSame(bgItem, item); |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
1 |
assertEquals(i, menu.getItemCount()); |
237 |
1 |
assertFalse(bgElements.hasMoreElements()); |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 2 |
Complexity Density: 0.1 |
1PASS
|
|
243 |
1 |
@Test(groups = "Functional")... |
244 |
|
public void testAddMenuItems_forAlignFrame() |
245 |
|
{ |
246 |
1 |
SequenceI s1 = new Sequence("s1", "KFRQSILM"); |
247 |
1 |
AlignmentI al = new Alignment(new SequenceI[] { s1 }); |
248 |
1 |
AlignFrame af = new AlignFrame(al, 500, 500); |
249 |
1 |
JMenu menu = new JMenu(); |
250 |
|
|
251 |
1 |
ButtonGroup bg = ColourMenuHelper.addMenuItems(menu, af, al, false); |
252 |
1 |
Enumeration<AbstractButton> bgElements = bg.getElements(); |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
1 |
bgElements.nextElement(); |
260 |
1 |
Iterator<ColourSchemeI> colourSchemes = ColourSchemes.getInstance() |
261 |
|
.getColourSchemes().iterator(); |
262 |
1 |
final int items = menu.getItemCount(); |
263 |
21 |
for (int i = 1; i < items - 1; i++) |
264 |
|
{ |
265 |
20 |
JMenuItem item = menu.getItem(i); |
266 |
20 |
AbstractButton bgItem = bgElements.nextElement(); |
267 |
20 |
assertSame(bgItem, item); |
268 |
20 |
ColourSchemeI cs = colourSchemes.next(); |
269 |
20 |
assertEquals(item.getName(), cs.getSchemeName()); |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
1 |
assertFalse(colourSchemes.hasNext()); |
276 |
1 |
JMenuItem item = menu.getItem(items - 1); |
277 |
1 |
AbstractButton bgItem = bgElements.nextElement(); |
278 |
1 |
assertSame(bgItem, item); |
279 |
1 |
assertEquals(item.getName(), ResidueColourScheme.USER_DEFINED_MENU); |
280 |
1 |
assertEquals(item.getText(), |
281 |
|
MessageManager.getString("action.user_defined")); |
282 |
|
} |
283 |
|
} |