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