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.assertNull; |
25 |
|
|
26 |
|
import java.awt.Font; |
27 |
|
import java.awt.FontMetrics; |
28 |
|
|
29 |
|
import jalview.datamodel.Alignment; |
30 |
|
import jalview.datamodel.AlignmentAnnotation; |
31 |
|
import jalview.datamodel.Sequence; |
32 |
|
|
33 |
|
import org.mockito.Mockito; |
34 |
|
import org.testng.annotations.DataProvider; |
35 |
|
import org.testng.annotations.Test; |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (105) |
Complexity: 4 |
Complexity Density: 0.04 |
|
37 |
|
public class AnnotationLabelsTest |
38 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (40) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
39 |
1 |
@Test(groups = "Functional")... |
40 |
|
public void testGetTooltip() |
41 |
|
{ |
42 |
1 |
assertNull(AnnotationLabels.getTooltip(null)); |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
1 |
AlignmentAnnotation ann = new AlignmentAnnotation("thelabel", "thedesc", |
48 |
|
null); |
49 |
1 |
String expected = "<html>thedesc</html>"; |
50 |
1 |
assertEquals(AnnotationLabels.getTooltip(ann), expected); |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
1 |
ann.description = "TCoffee scores < 56 and > 28"; |
57 |
1 |
expected = "<html>TCoffee scores < 56 and > 28</html>"; |
58 |
1 |
assertEquals(AnnotationLabels.getTooltip(ann), expected); |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
1 |
ann.description = "<html>hello world</html>"; |
64 |
1 |
assertEquals(AnnotationLabels.getTooltip(ann), ann.description); |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
1 |
ann.description = "hello world"; |
70 |
1 |
ann.setScore(2.34d); |
71 |
1 |
expected = "<html>hello world<br/> Score: 2.34</html>"; |
72 |
1 |
assertEquals(AnnotationLabels.getTooltip(ann), expected); |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
1 |
ann.description = "<html>hello world</html>"; |
78 |
1 |
ann.setScore(2.34d); |
79 |
1 |
expected = "<html>hello world<br/> Score: 2.34</html>"; |
80 |
1 |
assertEquals(AnnotationLabels.getTooltip(ann), expected); |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
1 |
ann.description = " "; |
86 |
1 |
assertEquals(AnnotationLabels.getTooltip(ann), |
87 |
|
"<html> Score: 2.34</html>"); |
88 |
1 |
ann.description = null; |
89 |
1 |
assertEquals(AnnotationLabels.getTooltip(ann), |
90 |
|
"<html> Score: 2.34</html>"); |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
1 |
ann.description = "Count < 12"; |
96 |
1 |
ann.sequenceRef = new Sequence("Seq1", "MLRIQST"); |
97 |
1 |
ann.hasScore = false; |
98 |
1 |
ann.score = Double.NaN; |
99 |
1 |
expected = "<html>Seq1 : Count < 12</html>"; |
100 |
1 |
assertEquals(AnnotationLabels.getTooltip(ann), expected); |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
1 |
ann.description = "<html>Score < 4.8</html>"; |
106 |
1 |
ann.sequenceRef = new Sequence("Seq1", "MLRIQST"); |
107 |
1 |
ann.setScore(-2.1D); |
108 |
1 |
expected = "<html>Seq1 : Score < 4.8<br/> Score: -2.1</html>"; |
109 |
1 |
assertEquals(AnnotationLabels.getTooltip(ann), expected); |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
1 |
ann.description = null; |
115 |
1 |
ann.hasScore = false; |
116 |
1 |
ann.score = Double.NaN; |
117 |
1 |
assertNull(AnnotationLabels.getTooltip(ann)); |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
1 |
ann.description = ""; |
123 |
1 |
assertEquals(AnnotationLabels.getTooltip(ann), "<html>Seq1 :</html>"); |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
1 |
ann.sequenceRef = null; |
129 |
1 |
assertNull(AnnotationLabels.getTooltip(ann)); |
130 |
|
} |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
132 |
1 |
@Test(groups = "Functional")... |
133 |
|
public void testGetStatusMessage() |
134 |
|
{ |
135 |
1 |
assertNull(AnnotationLabels.getStatusMessage(null, null)); |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
1 |
AlignmentAnnotation aa = new AlignmentAnnotation("IUPredWS Short", |
141 |
|
"Protein disorder", null); |
142 |
1 |
assertEquals(AnnotationLabels.getStatusMessage(aa, null), |
143 |
|
"IUPredWS Short"); |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
1 |
aa.setSequenceRef(new Sequence("FER_CAPAA", "MIGRKQL")); |
149 |
1 |
assertEquals(AnnotationLabels.getStatusMessage(aa, null), |
150 |
|
"FER_CAPAA : IUPredWS Short"); |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
1 |
aa.graphGroup = 1; |
156 |
1 |
AlignmentAnnotation aa2 = new AlignmentAnnotation("IUPredWS Long", |
157 |
|
"Protein disorder", null); |
158 |
1 |
assertEquals( |
159 |
|
AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[] |
160 |
|
{ aa, aa2 }), "FER_CAPAA : IUPredWS Short"); |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
1 |
aa2.graphGroup = 1; |
167 |
1 |
assertEquals( |
168 |
|
AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[] |
169 |
|
{ aa, aa2 }), "FER_CAPAA : IUPredWS Long, IUPredWS Short"); |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
1 |
aa.sequenceRef = null; |
175 |
1 |
assertEquals( |
176 |
|
AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[] |
177 |
|
{ aa, aa2 }), "IUPredWS Long, IUPredWS Short"); |
178 |
|
} |
179 |
|
|
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
181 |
7 |
@Test(groups = "Functional", dataProvider = "TestDrawLabelsData")... |
182 |
|
public void testDrawLabels(AlignmentAnnotation[] annotations, int expectedWidth) { |
183 |
|
|
184 |
7 |
FontMetrics mockFontMetrics = Mockito.mock(FontMetrics.class); |
185 |
7 |
Mockito.when(mockFontMetrics.getHeight()).thenReturn(10); |
186 |
7 |
Mockito.when(mockFontMetrics.getDescent()).thenReturn(2); |
187 |
7 |
Mockito.when(mockFontMetrics.stringWidth(Mockito.anyString())).thenAnswer(invocation -> { |
188 |
21 |
String str = invocation.getArgument(0); |
189 |
21 |
return str.length() * 7; |
190 |
|
}); |
191 |
|
|
192 |
7 |
Font mockFont = new Font("Arial", Font.PLAIN, 12); |
193 |
7 |
Mockito.when(mockFontMetrics.getFont()).thenReturn(mockFont); |
194 |
|
|
195 |
7 |
boolean actuallyDraw = false; |
196 |
7 |
boolean clip = false; |
197 |
7 |
int width = 200; |
198 |
7 |
boolean forGUI = true; |
199 |
7 |
boolean includeHidden = true; |
200 |
|
|
201 |
7 |
AlignViewport av = Mockito.mock(AlignViewport.class); |
202 |
7 |
Alignment alignment = Mockito.mock(Alignment.class); |
203 |
7 |
Mockito.when(alignment.getAlignmentAnnotation()).thenReturn(annotations); |
204 |
7 |
Mockito.when(av.getAlignment()).thenReturn(alignment); |
205 |
7 |
Mockito.when(av.getFont()).thenReturn(new Font("Arial", Font.PLAIN, 12)); |
206 |
|
|
207 |
7 |
AnnotationLabels annotationLabels = new AnnotationLabels(av); |
208 |
|
|
209 |
7 |
int resultWidth = annotationLabels.drawLabels(null, clip, width, actuallyDraw, forGUI, mockFontMetrics, includeHidden); |
210 |
|
|
211 |
7 |
assertEquals(resultWidth, expectedWidth); |
212 |
7 |
Mockito.reset(mockFontMetrics, av, alignment); |
213 |
|
} |
214 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 1 |
Complexity Density: 0.04 |
|
215 |
1 |
@DataProvider(name = "TestDrawLabelsData")... |
216 |
|
public static Object[][] provideSecondaryStructureAnnotation() { |
217 |
|
|
218 |
|
|
219 |
1 |
Sequence s1 = new Sequence("Seq1", "MLRIQST"); |
220 |
1 |
Sequence s2 = new Sequence("Sequence2", "MLRIQST"); |
221 |
|
|
222 |
1 |
String label1 = "Label1"; |
223 |
1 |
String label2 = "Label_2"; |
224 |
1 |
String label3 = "Label_three"; |
225 |
1 |
String description1 = "Desc1"; |
226 |
1 |
String description2 = "<html><h1>Desc_2</h1></html>"; |
227 |
1 |
String description3 = "Description_three"; |
228 |
|
|
229 |
|
|
230 |
1 |
AlignmentAnnotation a1 = new AlignmentAnnotation(label1, description1, null); |
231 |
1 |
AlignmentAnnotation a2 = new AlignmentAnnotation(label2, description2, null); |
232 |
1 |
AlignmentAnnotation a3 = new AlignmentAnnotation(label3, description3, null); |
233 |
1 |
AlignmentAnnotation a4 = new AlignmentAnnotation(label3, description3, null); |
234 |
1 |
AlignmentAnnotation a5 = new AlignmentAnnotation(label1, description2, null); |
235 |
1 |
AlignmentAnnotation a6 = new AlignmentAnnotation(label1, description2, null); |
236 |
|
|
237 |
1 |
a1.sequenceRef = s1; |
238 |
1 |
a2.sequenceRef = s1; |
239 |
1 |
a3.sequenceRef = s1; |
240 |
1 |
a4.sequenceRef = s2; |
241 |
1 |
a5.sequenceRef = s1; |
242 |
1 |
a6.sequenceRef = s2; |
243 |
|
|
244 |
1 |
a1.visible = true; |
245 |
1 |
a2.visible = true; |
246 |
1 |
a3.visible = true; |
247 |
1 |
a4.visible = true; |
248 |
1 |
a5.visible = true; |
249 |
1 |
a6.visible = true; |
250 |
|
|
251 |
1 |
return new Object[][]{ |
252 |
|
|
253 |
|
{new AlignmentAnnotation[]{a2, a2, a1}, 7 * ((s1.getName()+" ").length() + label2.length()) + 3}, |
254 |
|
{new AlignmentAnnotation[]{a1, a2, a3}, 7 * (label3.length()) + 3}, |
255 |
|
{new AlignmentAnnotation[]{a1, a2, a4}, 7 * ((s2.getName()+" ").length() + label3.length()) + 3}, |
256 |
|
{new AlignmentAnnotation[]{a1, a1, a1}, 7 * ((s1.getName()+" ").length() + label1.length()) + 3}, |
257 |
|
{new AlignmentAnnotation[]{a1, a1, a2}, 7 * ((s1.getName()+" ").length() + label1.length()) + 3}, |
258 |
|
{new AlignmentAnnotation[]{a1, a5, a2}, 7 * ((s1.getName()+" ").length() + "Desc_2".length()) + 3}, |
259 |
|
{new AlignmentAnnotation[]{a1, a6, a2}, 7 * ((s2.getName()+" ").length() + "Desc_2".length()) + 3}, |
260 |
|
|
261 |
|
}; |
262 |
|
} |
263 |
|
} |