JAL-2780 JAL-2781 - patch and first test for AlignmentI.findOrCreateAnnotation
authorJim Procter <jprocter@issues.jalview.org>
Mon, 5 Feb 2018 16:34:28 +0000 (16:34 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 5 Feb 2018 16:34:44 +0000 (16:34 +0000)
src/jalview/datamodel/Alignment.java
test/jalview/datamodel/AlignmentTest.java

index f268d37..97947b6 100755 (executable)
@@ -1603,7 +1603,10 @@ public class Alignment implements AlignmentI
     AlignmentAnnotation annot = new AlignmentAnnotation(name, name,
             new Annotation[1], 0f, 0f, AlignmentAnnotation.BAR_GRAPH);
     annot.hasText = false;
-    annot.setCalcId(new String(calcId));
+    if (calcId != null)
+    {
+      annot.setCalcId(new String(calcId));
+    }
     annot.autoCalculated = autoCalc;
     if (seqRef != null)
     {
index 4b5d096..4d86bc7 100644 (file)
@@ -1321,4 +1321,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);
+  }
 }