732329bbe0c2c3c6492efbd9ca6b3791e12812de
[jalview.git] / test / jalview / testutils / AnnotationsMatcherTest.java
1 package jalview.testutils;
2
3 import org.testng.annotations.DataProvider;
4 import org.testng.annotations.Test;
5 import jalview.datamodel.Annotation;
6
7 import static org.hamcrest.MatcherAssert.assertThat;
8
9 import java.awt.Color;
10 import java.util.*;
11
12 public class AnnotationsMatcherTest
13 {
14   @DataProvider
15   public Object[][] matchingAnnotationsLists()
16   {
17     return new Object[][] {
18         {
19             new Annotation[] {
20                 new Annotation("C", "", 'C', 0.0f),
21                 new Annotation("C", "", 'C', 0.1f),
22                 new Annotation("B", "", 'B', 0.2f) },
23             new Annotation[] {
24                 new Annotation("C", "", 'C', 0.0f),
25                 new Annotation("C", "", 'C', 0.1f),
26                 new Annotation("B", "", 'B', 0.2f) } },
27         {
28             new Annotation[] {
29                 new Annotation("X", "xxx", 'X', 1.3f),
30                 new Annotation("V", "vvv", 'V', 1.5f),
31                 new Annotation("B", "bbb", 'B', 2.5f) },
32             new Annotation[] {
33                 new Annotation("X", "xxx", 'X', 1.3f),
34                 new Annotation("V", "vvv", 'V', 1.5f),
35                 new Annotation("B", "bbb", 'B', 2.5f) } },
36         {
37             new Annotation[] {
38                 new Annotation("A", "", 'A', 0.2f, Color.RED),
39                 new Annotation("A", "", 'A', 0.3f, Color.GREEN),
40                 new Annotation("C", "", 'C', 0.4f, Color.YELLOW),
41                 new Annotation("C", "", 'C', 0.5f) },
42             new Annotation[] {
43                 new Annotation("A", "", 'A', 0.2f, Color.RED),
44                 new Annotation("A", "", 'A', 0.3f, Color.GREEN),
45                 new Annotation("C", "", 'C', 0.4f, Color.YELLOW),
46                 new Annotation("C", "", 'C', 0.5f) } },
47         {
48             new Annotation[] {
49                 Annotation.EMPTY_ANNOTATION, Annotation.EMPTY_ANNOTATION },
50             new Annotation[] {
51                 Annotation.EMPTY_ANNOTATION, Annotation.EMPTY_ANNOTATION } } };
52   }
53
54   @Test(groups = { "Functional" }, dataProvider = "matchingAnnotationsLists")
55   public void testMatchesSafely_matchingAnnotations(Annotation[] template,
56       Annotation[] testdata)
57   {
58     assert new AnnotationsMatcher(Arrays.asList(template))
59         .matchesSafely(testdata);
60   }
61
62   @DataProvider
63   public Object[][] matchingAnnotations()
64   {
65     return new Object[][] {
66         {
67             new Annotation("A", "aaa", 'A', 0.1f),
68             new Annotation("A", "aaa", 'A', 0.1f) },
69         {
70             new Annotation("A", "abcdef", 'A', 0.1f, Color.RED),
71             new Annotation("A", "abcdef", 'A', 0.1f, Color.RED) },
72         {
73             new Annotation("", "xxxx", ' ', 0.0f),
74             new Annotation("", "xxxx", ' ', 0.0f) },
75         {
76             new Annotation("", "", ' ', 0.0f),
77             new Annotation("", "", ' ', 0.0f) },
78         {
79             new Annotation(null, null, ' ', 0.0f),
80             new Annotation(null, null, ' ', 0.0f) },
81         {
82             new Annotation(null, "", ' ', 0.0f),
83             new Annotation("", null, ' ', 0.0f) } };
84   }
85
86   @Test(groups = { "Functional" }, dataProvider = "matchingAnnotations")
87   public void testAnnotationsEqual_matchingAnnotations(Annotation first,
88       Annotation second)
89   {
90     assert AnnotationsMatcher.annotationsEqual(first, second);
91   }
92
93   @Test(groups = { "Functional" })
94   public void testAnnotationsEqual_compareNullDisplayCharToEmpty()
95   {
96     assert AnnotationsMatcher
97         .annotationsEqual(new Annotation("", "description", 'A', 0.1f),
98             new Annotation(null, "description", 'A', 0.1f));
99     assert AnnotationsMatcher
100         .annotationsEqual(new Annotation(null, "description", 'A', 0.1f),
101             new Annotation("", "description", 'A', 0.1f));
102   }
103
104   @Test(groups = { "Functional" })
105   public void testAnnotationsEqual_compareNullDescriptionToEmpty()
106   {
107     assert AnnotationsMatcher
108         .annotationsEqual(new Annotation("A", null, 'A', 0.2f),
109             new Annotation("A", "", 'A', 0.2f));
110     assert AnnotationsMatcher
111         .annotationsEqual(new Annotation("A", "", 'A', 0.2f),
112             new Annotation("A", null, 'A', 0.2f));
113   }
114
115   @Test(groups = { "Functional" })
116   public void testAnnotationsEqual_compareNullDisplayCharToBlank()
117   {
118     assert !AnnotationsMatcher
119         .annotationsEqual(new Annotation(" ", "aaa", 'A', 0.03f),
120             new Annotation(null, "aaa", 'A', 0.03f));
121     assert !AnnotationsMatcher
122         .annotationsEqual(new Annotation(null, "aaa", 'A', 0.04f),
123             new Annotation(" ", "aaa", 'A', 0.04f));
124   }
125
126   @Test(groups = { "Functional" })
127   public void testAnnotationsEqual_compareNullDescriptionToBlank()
128   {
129     assert !AnnotationsMatcher
130         .annotationsEqual(new Annotation("A", null, 'A', 0.0f),
131             new Annotation("A", " ", 'A', 0.0f));
132     assert !AnnotationsMatcher
133         .annotationsEqual(new Annotation("A", " ", 'A', 0.01f),
134             new Annotation("A", null, 'A', 0.01f));
135   }
136 }