X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fgui%2FAnnotationLabelsTest.java;fp=test%2Fjalview%2Fgui%2FAnnotationLabelsTest.java;h=616a1a6263a8ffff5ab1c9eb5deb3b255518a1e9;hb=ca8504cf9d10874dce9f07cf7a9d933853fe0dd0;hp=0000000000000000000000000000000000000000;hpb=775e7bc104584e88dddcea73fbf02c66f5200c16;p=jalview.git
diff --git a/test/jalview/gui/AnnotationLabelsTest.java b/test/jalview/gui/AnnotationLabelsTest.java
new file mode 100644
index 0000000..616a1a6
--- /dev/null
+++ b/test/jalview/gui/AnnotationLabelsTest.java
@@ -0,0 +1,153 @@
+package jalview.gui;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.Sequence;
+
+import org.testng.annotations.Test;
+
+public class AnnotationLabelsTest
+{
+ @Test(groups = "Functional")
+ public void testGetTooltip()
+ {
+ assertNull(AnnotationLabels.getTooltip(null));
+
+ /*
+ * simple description only
+ */
+ AlignmentAnnotation ann = new AlignmentAnnotation("thelabel", "thedesc",
+ null);
+ String expected = "thedesc";
+ assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+ /*
+ * description needing html encoding
+ * (no idea why '<' is encoded but '>' is not)
+ */
+ ann.description = "TCoffee scores < 56 and > 28";
+ expected = "TCoffee scores < 56 and > 28";
+ assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+ /*
+ * description already html formatted
+ */
+ ann.description = "hello world";
+ assertEquals(AnnotationLabels.getTooltip(ann), ann.description);
+
+ /*
+ * simple description and score
+ */
+ ann.description = "hello world";
+ ann.setScore(2.34d);
+ expected = "hello world
Score: 2.34";
+ assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+ /*
+ * html description and score
+ */
+ ann.description = "hello world";
+ ann.setScore(2.34d);
+ expected = "hello world
Score: 2.34";
+ assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+ /*
+ * score, no description
+ */
+ ann.description = " ";
+ assertEquals(AnnotationLabels.getTooltip(ann),
+ " Score: 2.34");
+ ann.description = null;
+ assertEquals(AnnotationLabels.getTooltip(ann),
+ " Score: 2.34");
+
+ /*
+ * sequenceref, simple description
+ */
+ ann.description = "Count < 12";
+ ann.sequenceRef = new Sequence("Seq1", "MLRIQST");
+ ann.hasScore = false;
+ ann.score = Double.NaN;
+ expected = "Seq1 : Count < 12";
+ assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+ /*
+ * sequenceref, html description, score
+ */
+ ann.description = "Score < 4.8";
+ ann.sequenceRef = new Sequence("Seq1", "MLRIQST");
+ ann.setScore(-2.1D);
+ expected = "Seq1 : Score < 4.8
Score: -2.1";
+ assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+ /*
+ * no score, null description
+ */
+ ann.description = null;
+ ann.hasScore = false;
+ ann.score = Double.NaN;
+ assertNull(AnnotationLabels.getTooltip(ann));
+
+ /*
+ * no score, empty description, sequenceRef
+ */
+ ann.description = "";
+ assertEquals(AnnotationLabels.getTooltip(ann), "Seq1 :");
+
+ /*
+ * no score, empty description, no sequenceRef
+ */
+ ann.sequenceRef = null;
+ assertNull(AnnotationLabels.getTooltip(ann));
+ }
+
+ @Test(groups = "Functional")
+ public void testGetStatusMessage()
+ {
+ assertNull(AnnotationLabels.getStatusMessage(null, null));
+
+ /*
+ * simple label
+ */
+ AlignmentAnnotation aa = new AlignmentAnnotation("IUPredWS Short",
+ "Protein disorder", null);
+ assertEquals(AnnotationLabels.getStatusMessage(aa, null),
+ "IUPredWS Short");
+
+ /*
+ * with sequence ref
+ */
+ aa.setSequenceRef(new Sequence("FER_CAPAA", "MIGRKQL"));
+ assertEquals(AnnotationLabels.getStatusMessage(aa, null),
+ "FER_CAPAA : IUPredWS Short");
+
+ /*
+ * with graph group (degenerate, one annotation only)
+ */
+ aa.graphGroup = 1;
+ AlignmentAnnotation aa2 = new AlignmentAnnotation("IUPredWS Long",
+ "Protein disorder", null);
+ assertEquals(
+ AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
+ { aa, aa2 }), "FER_CAPAA : IUPredWS Short");
+
+ /*
+ * graph group with two members; note labels are appended in
+ * reverse order (matching rendering order on screen)
+ */
+ aa2.graphGroup = 1;
+ assertEquals(
+ AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
+ { aa, aa2 }), "FER_CAPAA : IUPredWS Long, IUPredWS Short");
+
+ /*
+ * graph group with no sequence ref
+ */
+ aa.sequenceRef = null;
+ assertEquals(
+ AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
+ { aa, aa2 }), "IUPredWS Long, IUPredWS Short");
+ }
+}