1 package jalview.datamodel;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNull;
5 import static org.junit.Assert.assertSame;
6 import static org.junit.Assert.assertTrue;
10 import org.junit.Before;
11 import org.junit.Test;
13 public class SequenceTest
20 seq = new Sequence("FER1", "AKPNGVL");
23 public void testGetAnnotation()
25 // initial state returns null not an empty array
26 assertNull(seq.getAnnotation());
27 AlignmentAnnotation ann = addAnnotation("label1", "desc1", "calcId1",
29 AlignmentAnnotation[] anns = seq.getAnnotation();
30 assertEquals(1, anns.length);
31 assertSame(ann, anns[0]);
33 // removing all annotations reverts array to null
34 seq.removeAlignmentAnnotation(ann);
35 assertNull(seq.getAnnotation());
39 public void testGetAnnotation_forLabel()
41 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1", 1f);
42 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2", 1f);
43 AlignmentAnnotation ann3 = addAnnotation("label1", "desc3", "calcId3", 1f);
44 AlignmentAnnotation[] anns = seq.getAnnotation("label1");
45 assertEquals(2, anns.length);
46 assertSame(ann1, anns[0]);
47 assertSame(ann3, anns[1]);
50 private AlignmentAnnotation addAnnotation(String label,
51 String description, String calcId,
54 final AlignmentAnnotation annotation = new AlignmentAnnotation(label, description,
56 annotation.setCalcId(calcId);
57 seq.addAlignmentAnnotation(annotation);
62 public void testGetAlignmentAnnotations_forCalcIdAndLabel()
64 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
66 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
68 AlignmentAnnotation ann3 = addAnnotation("label2", "desc3", "calcId3",
70 AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2",
72 AlignmentAnnotation ann5 = addAnnotation("label5", "desc3", null,
74 AlignmentAnnotation ann6 = addAnnotation(null, "desc3", "calcId3",
76 List<AlignmentAnnotation> anns = seq.getAlignmentAnnotations("calcId2",
78 assertEquals(2, anns.size());
79 assertSame(ann2, anns.get(0));
80 assertSame(ann4, anns.get(1));
82 assertTrue(seq.getAlignmentAnnotations("calcId2", "label3").isEmpty());
83 assertTrue(seq.getAlignmentAnnotations("calcId3", "label5").isEmpty());
84 assertTrue(seq.getAlignmentAnnotations("calcId2", null).isEmpty());
85 assertTrue(seq.getAlignmentAnnotations(null, "label3").isEmpty());
86 assertTrue(seq.getAlignmentAnnotations(null, null).isEmpty());
90 * Tests for addAlignmentAnnotation. Note this method has the side-effect of
91 * setting the sequenceRef on the annotation.
94 public void testAddAlignmentAnnotation()
96 assertNull(seq.annotation);
97 final AlignmentAnnotation annotation = new AlignmentAnnotation("a",
99 assertNull(annotation.sequenceRef);
100 seq.addAlignmentAnnotation(annotation);
101 assertSame(seq, annotation.sequenceRef);
102 AlignmentAnnotation[] anns = seq.getAnnotation();
103 assertEquals(1, anns.length);
104 assertSame(annotation, anns[0]);