Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.testutils

File AnnotationsMatcherTest.java

 

Code metrics

28
3
12
1
174
159
26
8.67
0.25
12
2.17

Classes

Class Line # Actions
AnnotationsMatcherTest 12 3 26
0.674418667.4%
 

Contributing tests

This file is covered by 19 tests. .

Source view

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  1 toggle @DataProvider
15    public Object[][] matchingAnnotationsLists()
16    {
17  1 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    new Annotation[] { null, null, null, null },
54    new Annotation[] { null, null, null, null } } };
55    }
56   
 
57  5 toggle @Test(groups = { "Functional" }, dataProvider = "matchingAnnotationsLists")
58    public void testMatchesSafely_matchingAnnotations(Annotation[] template,
59    Annotation[] testdata)
60    {
61  5 assert new AnnotationsMatcher(Arrays.asList(template))
62    .matchesSafely(testdata);
63    }
64   
 
65  1 toggle @DataProvider
66    public Object[][] matchingAnnotations()
67    {
68  1 return new Object[][] {
69    {
70    new Annotation("A", "aaa", 'A', 0.1f),
71    new Annotation("A", "aaa", 'A', 0.1f) },
72    {
73    new Annotation("A", "abcdef", 'A', 0.1f, Color.RED),
74    new Annotation("A", "abcdef", 'A', 0.1f, Color.RED) },
75    {
76    new Annotation("", "xxxx", ' ', 0.0f),
77    new Annotation("", "xxxx", ' ', 0.0f) },
78    {
79    new Annotation("", "", ' ', 0.0f),
80    new Annotation("", "", ' ', 0.0f) },
81    {
82    new Annotation(null, null, ' ', 0.0f),
83    new Annotation(null, null, ' ', 0.0f) },
84    {
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) }, };
89    }
90   
 
91  8 toggle @Test(groups = { "Functional" }, dataProvider = "matchingAnnotations")
92    public void testAnnotationsEqual_matchingAnnotations(Annotation first,
93    Annotation second)
94    {
95  8 assert AnnotationsMatcher.annotationsEqual(first, second);
96    }
97   
 
98  1 toggle @DataProvider
99    public Object[][] mismatchingAnnotations()
100    {
101  1 return new Object[][] {
102    {
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) } };
107    }
108   
 
109  3 toggle @Test(groups = { "Functional" }, dataProvider = "mismatchingAnnotations")
110    public void testAnnotationsEqual_mismatchingAnnotations(Annotation first,
111    Annotation second)
112    {
113  3 assert !AnnotationsMatcher.annotationsEqual(first, second);
114    }
115   
 
116  1 toggle @Test(groups = { "Functional" })
117    public void testAnnotationsEqual_nullsMatch()
118    {
119  1 assert AnnotationsMatcher.annotationsEqual(null, null);
120    }
121   
 
122  1 toggle @Test(groups = { "Functional" })
123    public void testAnnotationsEqual_nullNotMatchEmpty()
124    {
125  1 assert !AnnotationsMatcher
126    .annotationsEqual(null, Annotation.EMPTY_ANNOTATION);
127  1 assert !AnnotationsMatcher
128    .annotationsEqual(Annotation.EMPTY_ANNOTATION, null);
129    }
130   
 
131  1 toggle @Test(groups = { "Functional" })
132    public void testAnnotationsEqual_compareNullDisplayCharToEmpty()
133    {
134  1 assert AnnotationsMatcher
135    .annotationsEqual(new Annotation("", "description", 'A', 0.1f),
136    new Annotation(null, "description", 'A', 0.1f));
137  1 assert AnnotationsMatcher
138    .annotationsEqual(new Annotation(null, "description", 'A', 0.1f),
139    new Annotation("", "description", 'A', 0.1f));
140    }
141   
 
142  1 toggle @Test(groups = { "Functional" })
143    public void testAnnotationsEqual_compareNullDescriptionToEmpty()
144    {
145  1 assert AnnotationsMatcher
146    .annotationsEqual(new Annotation("A", null, 'A', 0.2f),
147    new Annotation("A", "", 'A', 0.2f));
148  1 assert AnnotationsMatcher
149    .annotationsEqual(new Annotation("A", "", 'A', 0.2f),
150    new Annotation("A", null, 'A', 0.2f));
151    }
152   
 
153  1 toggle @Test(groups = { "Functional" })
154    public void testAnnotationsEqual_compareNullDisplayCharToBlank()
155    {
156  1 assert !AnnotationsMatcher
157    .annotationsEqual(new Annotation(" ", "aaa", 'A', 0.03f),
158    new Annotation(null, "aaa", 'A', 0.03f));
159  1 assert !AnnotationsMatcher
160    .annotationsEqual(new Annotation(null, "aaa", 'A', 0.04f),
161    new Annotation(" ", "aaa", 'A', 0.04f));
162    }
163   
 
164  1 toggle @Test(groups = { "Functional" })
165    public void testAnnotationsEqual_compareNullDescriptionToBlank()
166    {
167  1 assert !AnnotationsMatcher
168    .annotationsEqual(new Annotation("A", null, 'A', 0.0f),
169    new Annotation("A", " ", 'A', 0.0f));
170  1 assert !AnnotationsMatcher
171    .annotationsEqual(new Annotation("A", " ", 'A', 0.01f),
172    new Annotation("A", null, 'A', 0.01f));
173    }
174    }