From: Jim Procter Date: Thu, 27 Apr 2017 15:13:25 +0000 (+0100) Subject: JAL-2494 test to cover AnnotatedCollectionI.findAnnotations
 X-Git-Tag: Release_2_10_2~3^2~123^2~9 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=33ea5042df2f15bab1b21770dfc93f28b8bf950e;p=jalview.git JAL-2494 test to cover AnnotatedCollectionI.findAnnotations
 --- diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index c5d09c1..660a69c 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -620,6 +620,67 @@ public class AlignmentTest assertFalse(iter.hasNext()); } + /** + * Test method that returns annotations that match on reference sequence, + * label, or calcId. + */ + @Test(groups = { "Functional" }) + public void testFindAnnotations_bySeqLabelandorCalcId() + { + // TODO: finish testFindAnnotations_bySeqLabelandorCalcId test + /* Note - this is an incomplete test - need to check null or + * non-null [ matches, not matches ] behaviour for each of the three + * parameters..*/ + + // search for a single, unique calcId with wildcards on other params + Iterable anns = al.findAnnotations(null, + "CalcIdForD.melanogaster.2", null); + Iterator iter = anns.iterator(); + assertTrue(iter.hasNext()); + AlignmentAnnotation ann = iter.next(); + assertEquals("D.melanogaster.2", ann.sequenceRef.getName()); + assertFalse(iter.hasNext()); + + // save reference to test sequence reference parameter + SequenceI rseq = ann.sequenceRef; + + // search for annotation associated with a single sequence + anns = al.findAnnotations(rseq, null, null); + iter = anns.iterator(); + assertTrue(iter.hasNext()); + ann = iter.next(); + assertEquals("D.melanogaster.2", ann.sequenceRef.getName()); + assertFalse(iter.hasNext()); + + // search for annotation with a non-existant calcId + anns = al.findAnnotations(null, "CalcIdForD.melanogaster.?", null); + iter = anns.iterator(); + assertFalse(iter.hasNext()); + + // search for annotation with a particular label - expect three + anns = al.findAnnotations(null, null, "secondary structure"); + iter = anns.iterator(); + assertTrue(iter.hasNext()); + iter.next(); + assertTrue(iter.hasNext()); + iter.next(); + assertTrue(iter.hasNext()); + iter.next(); + // third found.. so + assertFalse(iter.hasNext()); + + // null on all parameters == find all annotations + anns = al.findAnnotations(null, null, null); + iter = anns.iterator(); + int n = al.getAlignmentAnnotation().length; + while (iter.hasNext()) + { + n--; + iter.next(); + } + assertTrue("Found " + n + " fewer annotations from search.", n == 0); + } + @Test(groups = { "Functional" }) public void testDeleteAllAnnotations_includingAutocalculated() {