JAL-4313 Test and patch annots trimming
[jalview.git] / test / jalview / datamodel / AlignmentAnnotationTests.java
index 6ffbfa9..2948f83 100644 (file)
@@ -31,8 +31,7 @@ import org.testng.annotations.Test;
 import static jalview.datamodel.Annotation.EMPTY_ANNOTATION;
 import static jalview.testutils.Matchers.matchesAnnotations;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.Matchers.*;
 import static org.testng.Assert.assertNull;
 import static org.testng.AssertJUnit.assertEquals;
 
@@ -585,4 +584,53 @@ public class AlignmentAnnotationTests
         matchesAnnotations(new Annotation(1), new Annotation(2),
             new Annotation(3), new Annotation(8), new Annotation(9)));
   }
+
+  @Test(groups = "Functional")
+  public void testMakeVisibleAnnotation_TruncateNegativeStart()
+  {
+    Annotation[] annots = annotsRange(8);
+    AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
+    HiddenColumns hc = new HiddenColumns();
+    ann.makeVisibleAnnotation(-5, 1, hc);
+    assertThat(ann.annotations,
+        matchesAnnotations(new Annotation(0), new Annotation(1)));
+  }
+
+  @Test(groups = "Functional")
+  public void testMakeVisibleAnnotation_TruncateNegativeStartAndEnd()
+  {
+    Annotation[] annots = annotsRange(8);
+    AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
+    HiddenColumns hc = new HiddenColumns();
+    ann.makeVisibleAnnotation(-5, -2, hc);
+    assertThat(ann.annotations, is(emptyArray()));
+  }
+
+  @Test(groups = "Functional")
+  public void testMakeVisibleAnnotation_TruncateEndBeyondSize()
+  {
+    Annotation[] annots = annotsRange(8);
+    AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
+    HiddenColumns hc = new HiddenColumns();
+    ann.makeVisibleAnnotation(6, 10, hc);
+    assertThat(ann.annotations, matchesAnnotations(new Annotation(6), new Annotation(7)));
+  }
+
+  @Test(groups = "Functional")
+  public void testMakeVisibleAnnotation_TruncateStartAndEndBeyondSize()
+  {
+    Annotation[] annots = annotsRange(4);
+    AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
+    HiddenColumns hc = new HiddenColumns();
+    ann.makeVisibleAnnotation(6, 10, hc);
+    assertThat(ann.annotations, is(emptyArray()));
+  }
+
+  static Annotation[] annotsRange(int stop)
+  {
+    Annotation[] annotations = new Annotation[stop];
+    for (int i = 0; i < stop; i++)
+      annotations[i] = new Annotation(i);
+    return annotations;
+  }
 }