X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fdatamodel%2FAnnotationTest.java;fp=test%2Fjalview%2Fdatamodel%2FAnnotationTest.java;h=a8f258d3fa6903efa2245a89fda095b5ac0ae3e9;hb=fa529a2a75da021dd95a8b13205c2a6e4c5e460f;hp=0000000000000000000000000000000000000000;hpb=5fe8a7444f60733f195cd812e75d7e873e688880;p=jalview.git 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()); + } +}