JAL-4313 Create Annotation tests
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 27 Oct 2023 13:15:51 +0000 (15:15 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 30 Oct 2023 14:35:18 +0000 (15:35 +0100)
test/jalview/datamodel/AnnotationTest.java [new file with mode: 0644]

diff --git a/test/jalview/datamodel/AnnotationTest.java b/test/jalview/datamodel/AnnotationTest.java
new file mode 100644 (file)
index 0000000..a8f258d
--- /dev/null
@@ -0,0 +1,82 @@
+package jalview.datamodel;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+
+import java.awt.Color;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+public class AnnotationTest
+{
+  @Test(groups = "Functional")
+  public void testConstructor_ValueOnly()
+  {
+    var annotation = new Annotation(0.5f);
+    assertThat(annotation.displayCharacter, nullValue());
+    assertThat(annotation.description, nullValue());
+    assertThat(annotation.secondaryStructure, is(' '));
+    assertThat(annotation.value, is(0.5f));
+    assertThat(annotation.colour, is(nullValue()));
+  }
+
+  @Test(groups = "Functional")
+  public void testCopyConstructor_NullValue_EmptyAnnotationCreated()
+  {
+    var annotation = new Annotation((Annotation) null);
+    assertThat(annotation.displayCharacter, equalTo(""));
+    assertThat(annotation.description, equalTo(""));
+    assertThat(annotation.secondaryStructure, is(' '));
+    assertThat(annotation.value, is(0.0f));
+    assertThat(annotation.colour, is(nullValue()));
+  }
+
+  @DataProvider
+  public Object[] emptyAnnotations()
+  {
+    return new Object[] {
+        Annotation.EMPTY_ANNOTATION, new Annotation(0.0f),
+        new Annotation((Annotation) null),
+        new Annotation(Annotation.EMPTY_ANNOTATION),
+        new Annotation("", "", ' ', 0.0f),
+        new Annotation(null, null, ' ', 0.0f),
+        new Annotation("", "", '\0', 0.0f), new Annotation("", null, ' ', 0.0f),
+        new Annotation(null, "", ' ', 0.0f), new Annotation(" ", "", ' ', 0.0f),
+        new Annotation(" .", "", ' ', 0.0f), new Annotation("", " ", ' ', 0.0f),
+        new Annotation("", "", ' ', 0.0f, null),
+        new Annotation("", " ", ' ', 0.0f),
+        new Annotation("", "\n", ' ', 0.0f), };
+  }
+
+  @Test(groups = "Functional", dataProvider = "emptyAnnotations")
+  public void testIsWhitespace_EmptyAnnotations(Annotation annot)
+  {
+    assertThat("Annotation " + annot + " is not whitespace, but should be",
+        annot.isWhitespace());
+  }
+
+  @DataProvider
+  public Object[] nonEmptyAnnotations()
+  {
+    return new Object[] {
+        new Annotation(0.4f),
+        new Annotation(new Annotation(0.1f)),
+        new Annotation("A", "", ' ', 0.0f),
+        new Annotation("", "", ' ', 0.0f, Color.WHITE),
+        new Annotation(null, null, ' ', -0.1f),
+        new Annotation(null, null, 'A', 0.0f),
+        new Annotation(null, "desc", ' ', 0.0f),
+        new Annotation("0", "<nil>", '\0', 0.0f),
+    };
+  }
+  
+  @Test(groups = "Functional", dataProvider = "nonEmptyAnnotations")
+  public void testIsWhitespace_NonEmptyAnnotation(Annotation annot)
+  {
+    assertThat("Annotation " + annot + " is whitespace, but should not be",
+        !annot.isWhitespace());
+  }
+}