From: Mateusz Warowny Date: Fri, 27 Oct 2023 13:15:51 +0000 (+0200) Subject: JAL-4313 Create Annotation tests X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a95bd4060394f1f54bc9d17560cc5cf192127fa9;p=jalview.git JAL-4313 Create Annotation tests --- diff --git a/test/jalview/datamodel/AnnotationTest.java b/test/jalview/datamodel/AnnotationTest.java new file mode 100644 index 0000000..a8f258d --- /dev/null +++ b/test/jalview/datamodel/AnnotationTest.java @@ -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", "", '\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()); + } +}