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()); } }