1 package jalview.testutils;
3 import org.testng.annotations.DataProvider;
4 import org.testng.annotations.Test;
5 import jalview.datamodel.Annotation;
7 import static org.hamcrest.MatcherAssert.assertThat;
12 public class AnnotationsMatcherTest
15 public Object[][] matchingAnnotationsLists()
17 return new Object[][] {
20 new Annotation("C", "", 'C', 0.0f),
21 new Annotation("C", "", 'C', 0.1f),
22 new Annotation("B", "", 'B', 0.2f) },
24 new Annotation("C", "", 'C', 0.0f),
25 new Annotation("C", "", 'C', 0.1f),
26 new Annotation("B", "", 'B', 0.2f) } },
29 new Annotation("X", "xxx", 'X', 1.3f),
30 new Annotation("V", "vvv", 'V', 1.5f),
31 new Annotation("B", "bbb", 'B', 2.5f) },
33 new Annotation("X", "xxx", 'X', 1.3f),
34 new Annotation("V", "vvv", 'V', 1.5f),
35 new Annotation("B", "bbb", 'B', 2.5f) } },
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) },
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) } },
49 Annotation.EMPTY_ANNOTATION, Annotation.EMPTY_ANNOTATION },
51 Annotation.EMPTY_ANNOTATION, Annotation.EMPTY_ANNOTATION } },
53 new Annotation[] { null, null, null, null },
54 new Annotation[] { null, null, null, null } } };
57 @Test(groups = { "Functional" }, dataProvider = "matchingAnnotationsLists")
58 public void testMatchesSafely_matchingAnnotations(Annotation[] template,
59 Annotation[] testdata)
61 assert new AnnotationsMatcher(Arrays.asList(template))
62 .matchesSafely(testdata);
66 public Object[][] matchingAnnotations()
68 return new Object[][] {
70 new Annotation("A", "aaa", 'A', 0.1f),
71 new Annotation("A", "aaa", 'A', 0.1f) },
73 new Annotation("A", "abcdef", 'A', 0.1f, Color.RED),
74 new Annotation("A", "abcdef", 'A', 0.1f, Color.RED) },
76 new Annotation("", "xxxx", ' ', 0.0f),
77 new Annotation("", "xxxx", ' ', 0.0f) },
79 new Annotation("", "", ' ', 0.0f),
80 new Annotation("", "", ' ', 0.0f) },
82 new Annotation(null, null, ' ', 0.0f),
83 new Annotation(null, null, ' ', 0.0f) },
85 new Annotation(null, "", ' ', 0.0f),
86 new Annotation("", null, ' ', 0.0f) },
87 { new Annotation(0f), Annotation.EMPTY_ANNOTATION },
88 { new Annotation(1f), new Annotation("", "", ' ', 1f, null) }, };
91 @Test(groups = { "Functional" }, dataProvider = "matchingAnnotations")
92 public void testAnnotationsEqual_matchingAnnotations(Annotation first,
95 assert AnnotationsMatcher.annotationsEqual(first, second);
99 public Object[][] mismatchingAnnotations()
101 return new Object[][] {
103 new Annotation("A", "aaa", 'A', 1f),
104 new Annotation("A", "aaa", 'B', 1f) },
105 { new Annotation(1f), new Annotation(2f) },
106 { new Annotation(1f), new Annotation("A", "", 'A', 1f) } };
109 @Test(groups = { "Functional" }, dataProvider = "mismatchingAnnotations")
110 public void testAnnotationsEqual_mismatchingAnnotations(Annotation first,
113 assert !AnnotationsMatcher.annotationsEqual(first, second);
116 @Test(groups = { "Functional" })
117 public void testAnnotationsEqual_nullsMatch()
119 assert AnnotationsMatcher.annotationsEqual(null, null);
122 @Test(groups = { "Functional" })
123 public void testAnnotationsEqual_nullNotMatchEmpty()
125 assert !AnnotationsMatcher
126 .annotationsEqual(null, Annotation.EMPTY_ANNOTATION);
127 assert !AnnotationsMatcher
128 .annotationsEqual(Annotation.EMPTY_ANNOTATION, null);
131 @Test(groups = { "Functional" })
132 public void testAnnotationsEqual_compareNullDisplayCharToEmpty()
134 assert AnnotationsMatcher
135 .annotationsEqual(new Annotation("", "description", 'A', 0.1f),
136 new Annotation(null, "description", 'A', 0.1f));
137 assert AnnotationsMatcher
138 .annotationsEqual(new Annotation(null, "description", 'A', 0.1f),
139 new Annotation("", "description", 'A', 0.1f));
142 @Test(groups = { "Functional" })
143 public void testAnnotationsEqual_compareNullDescriptionToEmpty()
145 assert AnnotationsMatcher
146 .annotationsEqual(new Annotation("A", null, 'A', 0.2f),
147 new Annotation("A", "", 'A', 0.2f));
148 assert AnnotationsMatcher
149 .annotationsEqual(new Annotation("A", "", 'A', 0.2f),
150 new Annotation("A", null, 'A', 0.2f));
153 @Test(groups = { "Functional" })
154 public void testAnnotationsEqual_compareNullDisplayCharToBlank()
156 assert !AnnotationsMatcher
157 .annotationsEqual(new Annotation(" ", "aaa", 'A', 0.03f),
158 new Annotation(null, "aaa", 'A', 0.03f));
159 assert !AnnotationsMatcher
160 .annotationsEqual(new Annotation(null, "aaa", 'A', 0.04f),
161 new Annotation(" ", "aaa", 'A', 0.04f));
164 @Test(groups = { "Functional" })
165 public void testAnnotationsEqual_compareNullDescriptionToBlank()
167 assert !AnnotationsMatcher
168 .annotationsEqual(new Annotation("A", null, 'A', 0.0f),
169 new Annotation("A", " ", 'A', 0.0f));
170 assert !AnnotationsMatcher
171 .annotationsEqual(new Annotation("A", " ", 'A', 0.01f),
172 new Annotation("A", null, 'A', 0.01f));