JAL-2780 JAL-2781 test AlignmentI.findAnnotations locates sequence associated annotat...
[jalview.git] / test / jalview / datamodel / AlignmentTest.java
index 2adefc9..74ac146 100644 (file)
@@ -37,7 +37,6 @@ import jalview.io.FormatAdapter;
 import jalview.util.MapList;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
@@ -669,6 +668,17 @@ public class AlignmentTest
     // third found.. so
     assertFalse(iter.hasNext());
 
+    // search for annotation on one sequence with a particular label - expect
+    // one
+    SequenceI sqfound;
+    anns = al.findAnnotations(sqfound = al.getSequenceAt(1), null,
+            "Secondary Structure");
+    iter = anns.iterator();
+    assertTrue(iter.hasNext());
+    // expect reference to sequence 1 in the alignment
+    assertTrue(sqfound == iter.next().sequenceRef);
+    assertFalse(iter.hasNext());
+
     // null on all parameters == find all annotations
     anns = al.findAnnotations(null, null, null);
     iter = anns.iterator();
@@ -1107,35 +1117,6 @@ public class AlignmentTest
             "addSequence broke dataset reference integrity");
   }
 
-  @Test(groups = "Functional")
-  public void getVisibleStartAndEndIndexTest()
-  {
-    Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
-    AlignmentI align = new Alignment(new SequenceI[] { seq });
-    ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
-
-    int[] startEnd = align.getVisibleStartAndEndIndex(hiddenCols);
-    assertEquals(0, startEnd[0]);
-    assertEquals(25, startEnd[1]);
-
-    hiddenCols.add(new int[] { 0, 0 });
-    startEnd = align.getVisibleStartAndEndIndex(hiddenCols);
-    assertEquals(1, startEnd[0]);
-    assertEquals(25, startEnd[1]);
-
-    hiddenCols.add(new int[] { 6, 9 });
-    hiddenCols.add(new int[] { 11, 12 });
-    startEnd = align.getVisibleStartAndEndIndex(hiddenCols);
-    assertEquals(1, startEnd[0]);
-    assertEquals(25, startEnd[1]);
-
-    hiddenCols.add(new int[] { 24, 25 });
-    startEnd = align.getVisibleStartAndEndIndex(hiddenCols);
-    System.out.println(startEnd[0] + " : " + startEnd[1]);
-    assertEquals(1, startEnd[0]);
-    assertEquals(23, startEnd[1]);
-  }
-
   /**
    * Tests that dbrefs with mappings to sequence get updated if the sequence
    * acquires a dataset sequence
@@ -1351,4 +1332,22 @@ public class AlignmentTest
     // todo test coverage for annotations, mappings, groups,
     // hidden sequences, properties
   }
+
+  /**
+   * test that calcId == null on findOrCreate doesn't raise an NPE, and yields
+   * an annotation with a null calcId
+   * 
+   */
+  @Test(groups = "Functional")
+  public void testFindOrCreateForNullCalcId()
+  {
+    SequenceI seq = new Sequence("seq1", "FRMLPSRT-A--L-");
+    AlignmentI alignment = new Alignment(new SequenceI[] { seq });
+
+    AlignmentAnnotation ala = alignment.findOrCreateAnnotation(
+            "Temperature Factor", null, false, seq, null);
+    assertNotNull(ala);
+    assertEquals(seq, ala.sequenceRef);
+    assertEquals("", ala.calcId);
+  }
 }