JAL-4313 Create Annotation tests
[jalview.git] / test / jalview / datamodel / AnnotationTest.java
1 package jalview.datamodel;
2
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.equalTo;
5 import static org.hamcrest.Matchers.is;
6 import static org.hamcrest.Matchers.nullValue;
7
8 import java.awt.Color;
9
10 import org.testng.annotations.DataProvider;
11 import org.testng.annotations.Test;
12
13 public class AnnotationTest
14 {
15   @Test(groups = "Functional")
16   public void testConstructor_ValueOnly()
17   {
18     var annotation = new Annotation(0.5f);
19     assertThat(annotation.displayCharacter, nullValue());
20     assertThat(annotation.description, nullValue());
21     assertThat(annotation.secondaryStructure, is(' '));
22     assertThat(annotation.value, is(0.5f));
23     assertThat(annotation.colour, is(nullValue()));
24   }
25
26   @Test(groups = "Functional")
27   public void testCopyConstructor_NullValue_EmptyAnnotationCreated()
28   {
29     var annotation = new Annotation((Annotation) null);
30     assertThat(annotation.displayCharacter, equalTo(""));
31     assertThat(annotation.description, equalTo(""));
32     assertThat(annotation.secondaryStructure, is(' '));
33     assertThat(annotation.value, is(0.0f));
34     assertThat(annotation.colour, is(nullValue()));
35   }
36
37   @DataProvider
38   public Object[] emptyAnnotations()
39   {
40     return new Object[] {
41         Annotation.EMPTY_ANNOTATION, new Annotation(0.0f),
42         new Annotation((Annotation) null),
43         new Annotation(Annotation.EMPTY_ANNOTATION),
44         new Annotation("", "", ' ', 0.0f),
45         new Annotation(null, null, ' ', 0.0f),
46         new Annotation("", "", '\0', 0.0f), new Annotation("", null, ' ', 0.0f),
47         new Annotation(null, "", ' ', 0.0f), new Annotation(" ", "", ' ', 0.0f),
48         new Annotation(" .", "", ' ', 0.0f), new Annotation("", " ", ' ', 0.0f),
49         new Annotation("", "", ' ', 0.0f, null),
50         new Annotation("", " ", ' ', 0.0f),
51         new Annotation("", "\n", ' ', 0.0f), };
52   }
53
54   @Test(groups = "Functional", dataProvider = "emptyAnnotations")
55   public void testIsWhitespace_EmptyAnnotations(Annotation annot)
56   {
57     assertThat("Annotation " + annot + " is not whitespace, but should be",
58         annot.isWhitespace());
59   }
60
61   @DataProvider
62   public Object[] nonEmptyAnnotations()
63   {
64     return new Object[] {
65         new Annotation(0.4f),
66         new Annotation(new Annotation(0.1f)),
67         new Annotation("A", "", ' ', 0.0f),
68         new Annotation("", "", ' ', 0.0f, Color.WHITE),
69         new Annotation(null, null, ' ', -0.1f),
70         new Annotation(null, null, 'A', 0.0f),
71         new Annotation(null, "desc", ' ', 0.0f),
72         new Annotation("0", "<nil>", '\0', 0.0f),
73     };
74   }
75   
76   @Test(groups = "Functional", dataProvider = "nonEmptyAnnotations")
77   public void testIsWhitespace_NonEmptyAnnotation(Annotation annot)
78   {
79     assertThat("Annotation " + annot + " is whitespace, but should not be",
80         !annot.isWhitespace());
81   }
82 }