a4fc1a1ab64c2d2478ae00986e619791a2074bf4
[jalview.git] / test / jalview / gui / AnnotationLabelsTest.java
1 package jalview.gui;
2
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertNull;
5
6 import jalview.datamodel.AlignmentAnnotation;
7 import jalview.datamodel.Sequence;
8
9 import org.testng.annotations.Test;
10
11 public class AnnotationLabelsTest
12 {
13   @Test(groups = "Functional")
14   public void testGetTooltip()
15   {
16     assertNull(AnnotationLabels.getTooltip(null));
17
18     /*
19      * simple description only
20      */
21     AlignmentAnnotation ann = new AlignmentAnnotation("thelabel", "thedesc",
22             null);
23     String expected = "<html>thedesc</html>";
24     assertEquals(AnnotationLabels.getTooltip(ann), expected);
25
26     /*
27      * description needing html encoding
28      * (no idea why '<' is encoded but '>' is not)
29      */
30     ann.description = "TCoffee scores < 56 and > 28";
31     expected = "<html>TCoffee scores &lt; 56 and > 28</html>";
32     assertEquals(AnnotationLabels.getTooltip(ann), expected);
33
34     /*
35      * description already html formatted
36      */
37     ann.description = "<html>hello world</html>";
38     assertEquals(AnnotationLabels.getTooltip(ann), ann.description);
39
40     /*
41      * simple description and score
42      */
43     ann.description = "hello world";
44     ann.setScore(2.34d);
45     expected = "<html>hello world<br/> Score: 2.34</html>";
46     assertEquals(AnnotationLabels.getTooltip(ann), expected);
47
48     /*
49      * html description and score
50      */
51     ann.description = "<html>hello world</html>";
52     ann.setScore(2.34d);
53     expected = "<html>hello world<br/> Score: 2.34</html>";
54     assertEquals(AnnotationLabels.getTooltip(ann), expected);
55
56     /*
57      * score, no description
58      */
59     ann.description = " ";
60     assertEquals(AnnotationLabels.getTooltip(ann),
61             "<html> Score: 2.34</html>");
62     ann.description = null;
63     assertEquals(AnnotationLabels.getTooltip(ann),
64             "<html> Score: 2.34</html>");
65
66     /*
67      * sequenceref, simple description
68      */
69     ann.description = "Count < 12";
70     ann.sequenceRef = new Sequence("Seq1", "MLRIQST");
71     ann.hasScore = false;
72     ann.score = Double.NaN;
73     expected = "<html>Seq1 : Count &lt; 12</html>";
74     assertEquals(AnnotationLabels.getTooltip(ann), expected);
75
76     /*
77      * sequenceref, html description, score
78      */
79     ann.description = "<html>Score < 4.8</html>";
80     ann.sequenceRef = new Sequence("Seq1", "MLRIQST");
81     ann.setScore(-2.1D);
82     expected = "<html>Seq1 : Score < 4.8<br/> Score: -2.1</html>";
83     assertEquals(AnnotationLabels.getTooltip(ann), expected);
84
85     /*
86      * no score, null description
87      */
88     ann.description = null;
89     ann.hasScore = false;
90     ann.score = Double.NaN;
91     assertNull(AnnotationLabels.getTooltip(ann));
92
93     /*
94      * no score, empty description, sequenceRef
95      */
96     ann.description = "";
97     assertEquals(AnnotationLabels.getTooltip(ann), "<html>Seq1 :</html>");
98
99     /*
100      * no score, empty description, no sequenceRef
101      */
102     ann.sequenceRef = null;
103     assertNull(AnnotationLabels.getTooltip(ann));
104   }
105
106   @Test(groups = "Functional")
107   public void testGetStatusMessage()
108   {
109     assertNull(AnnotationLabels.getStatusMessage(null, null));
110
111     /*
112      * simple label
113      */
114     AlignmentAnnotation aa = new AlignmentAnnotation("IUPredWS Short",
115             "Protein disorder", null);
116     assertEquals(AnnotationLabels.getStatusMessage(aa, null),
117             "IUPredWS Short");
118
119     /*
120      * with sequence ref
121      */
122     aa.setSequenceRef(new Sequence("FER_CAPAA", "MIGRKQL"));
123     assertEquals(AnnotationLabels.getStatusMessage(aa, null),
124             "FER_CAPAA : IUPredWS Short");
125
126     /*
127      * with graph group (degenerate, one annotation only)
128      */
129     aa.graphGroup = 1;
130     AlignmentAnnotation aa2 = new AlignmentAnnotation("IUPredWS Long",
131             "Protein disorder", null);
132     assertEquals(
133             AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
134             { aa, aa2 }), "FER_CAPAA : IUPredWS Short");
135
136     /*
137      * graph group with two members; note labels are appended in
138      * reverse order (matching rendering order on screen)
139      */
140     aa2.graphGroup = 1;
141     assertEquals(
142             AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
143             { aa, aa2 }), "FER_CAPAA : IUPredWS Long, IUPredWS Short");
144
145     /*
146      * graph group with no sequence ref
147      */
148     aa.sequenceRef = null;
149     assertEquals(
150             AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
151             { aa, aa2 }), "IUPredWS Long, IUPredWS Short");
152   }
153 }