JAL-2494 test to cover AnnotatedCollectionI.findAnnotations

authorJim Procter <jprocter@issues.jalview.org>
Thu, 27 Apr 2017 15:13:25 +0000 (16:13 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 27 Apr 2017 15:24:34 +0000 (16:24 +0100)
test/jalview/datamodel/AlignmentTest.java

index c5d09c1..660a69c 100644 (file)
@@ -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<AlignmentAnnotation> anns = al.findAnnotations(null,
+            "CalcIdForD.melanogaster.2", null);
+    Iterator<AlignmentAnnotation> 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()
   {