Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 10:11:34 GMT
  2. Package jalview.gui

File AnnotationLabelsTest.java

 

Code metrics

0
52
2
1
173
82
2
0.04
26
2
1

Classes

Class Line # Actions
AnnotationLabelsTest 31 52 2
1.0100%
 

Contributing tests

This file is covered by 2 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.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  1 toggle @Test(groups = "Functional")
34    public void testGetTooltip()
35    {
36  1 assertNull(AnnotationLabels.getTooltip(null));
37   
38    /*
39    * simple description only
40    */
41  1 AlignmentAnnotation ann = new AlignmentAnnotation("thelabel", "thedesc",
42    null);
43  1 String expected = "<html>thedesc</html>";
44  1 assertEquals(AnnotationLabels.getTooltip(ann), expected);
45   
46    /*
47    * description needing html encoding
48    * (no idea why '<' is encoded but '>' is not)
49    */
50  1 ann.description = "TCoffee scores < 56 and > 28";
51  1 expected = "<html>TCoffee scores &lt; 56 and > 28</html>";
52  1 assertEquals(AnnotationLabels.getTooltip(ann), expected);
53   
54    /*
55    * description already html formatted
56    */
57  1 ann.description = "<html>hello world</html>";
58  1 assertEquals(AnnotationLabels.getTooltip(ann), ann.description);
59   
60    /*
61    * simple description and score
62    */
63  1 ann.description = "hello world";
64  1 ann.setScore(2.34d);
65  1 expected = "<html>hello world<br/> Score: 2.34</html>";
66  1 assertEquals(AnnotationLabels.getTooltip(ann), expected);
67   
68    /*
69    * html description and score
70    */
71  1 ann.description = "<html>hello world</html>";
72  1 ann.setScore(2.34d);
73  1 expected = "<html>hello world<br/> Score: 2.34</html>";
74  1 assertEquals(AnnotationLabels.getTooltip(ann), expected);
75   
76    /*
77    * score, no description
78    */
79  1 ann.description = " ";
80  1 assertEquals(AnnotationLabels.getTooltip(ann),
81    "<html> Score: 2.34</html>");
82  1 ann.description = null;
83  1 assertEquals(AnnotationLabels.getTooltip(ann),
84    "<html> Score: 2.34</html>");
85   
86    /*
87    * sequenceref, simple description
88    */
89  1 ann.description = "Count < 12";
90  1 ann.sequenceRef = new Sequence("Seq1", "MLRIQST");
91  1 ann.hasScore = false;
92  1 ann.score = Double.NaN;
93  1 expected = "<html>Seq1 : Count &lt; 12</html>";
94  1 assertEquals(AnnotationLabels.getTooltip(ann), expected);
95   
96    /*
97    * sequenceref, html description, score
98    */
99  1 ann.description = "<html>Score < 4.8</html>";
100  1 ann.sequenceRef = new Sequence("Seq1", "MLRIQST");
101  1 ann.setScore(-2.1D);
102  1 expected = "<html>Seq1 : Score < 4.8<br/> Score: -2.1</html>";
103  1 assertEquals(AnnotationLabels.getTooltip(ann), expected);
104   
105    /*
106    * no score, null description
107    */
108  1 ann.description = null;
109  1 ann.hasScore = false;
110  1 ann.score = Double.NaN;
111  1 assertNull(AnnotationLabels.getTooltip(ann));
112   
113    /*
114    * no score, empty description, sequenceRef
115    */
116  1 ann.description = "";
117  1 assertEquals(AnnotationLabels.getTooltip(ann), "<html>Seq1 :</html>");
118   
119    /*
120    * no score, empty description, no sequenceRef
121    */
122  1 ann.sequenceRef = null;
123  1 assertNull(AnnotationLabels.getTooltip(ann));
124    }
125   
 
126  1 toggle @Test(groups = "Functional")
127    public void testGetStatusMessage()
128    {
129  1 assertNull(AnnotationLabels.getStatusMessage(null, null));
130   
131    /*
132    * simple label
133    */
134  1 AlignmentAnnotation aa = new AlignmentAnnotation("IUPredWS Short",
135    "Protein disorder", null);
136  1 assertEquals(AnnotationLabels.getStatusMessage(aa, null),
137    "IUPredWS Short");
138   
139    /*
140    * with sequence ref
141    */
142  1 aa.setSequenceRef(new Sequence("FER_CAPAA", "MIGRKQL"));
143  1 assertEquals(AnnotationLabels.getStatusMessage(aa, null),
144    "FER_CAPAA : IUPredWS Short");
145   
146    /*
147    * with graph group (degenerate, one annotation only)
148    */
149  1 aa.graphGroup = 1;
150  1 AlignmentAnnotation aa2 = new AlignmentAnnotation("IUPredWS Long",
151    "Protein disorder", null);
152  1 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  1 aa2.graphGroup = 1;
161  1 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  1 aa.sequenceRef = null;
169  1 assertEquals(
170    AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
171    { aa, aa2 }), "IUPredWS Long, IUPredWS Short");
172    }
173    }