Clover icon

Coverage Report

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

File AnnotationsMatcher.java

 

Coverage histogram

../../img/srcFileCovDistChart5.png
43% of files have more coverage

Code metrics

18
25
5
1
82
73
15
0.6
5
5
3

Classes

Class Line # Actions
AnnotationsMatcher 12 25 15
0.4791666647.9%
 

Contributing tests

This file is covered by 35 tests. .

Source view

1    package jalview.testutils;
2   
3    import java.util.List;
4    import java.util.Objects;
5    import static java.util.Objects.requireNonNullElse;
6   
7    import org.hamcrest.Description;
8    import org.hamcrest.TypeSafeMatcher;
9   
10    import jalview.datamodel.Annotation;
11   
 
12    public class AnnotationsMatcher extends TypeSafeMatcher<Annotation[]>
13    {
14    final List<Annotation> annotations;
15   
 
16  37 toggle public AnnotationsMatcher(List<Annotation> annotations)
17    {
18  37 this.annotations = annotations;
19    }
20   
 
21  37 toggle @Override
22    public boolean matchesSafely(Annotation[] items)
23    {
24  37 if (annotations.size() != items.length)
25  0 return false;
26  503 for (int i = 0; i < annotations.size(); i++)
27    {
28  466 var actual = items[i];
29  466 var expected = annotations.get(i);
30  466 if (!annotationsEqual(actual, expected))
31  0 return false;
32    }
33  37 return true;
34    }
35   
 
36  488 toggle static boolean annotationsEqual(Annotation a, Annotation b)
37    {
38  488 if (a == null && b == null)
39  9 return true;
40  479 if ((a == null) != (b == null)) // if one is null but the other is not
41  2 return false;
42  477 return a.secondaryStructure == b.secondaryStructure && a.value == b.value
43    && Objects.equals(a.colour, b.colour)
44    && Objects
45    .equals(requireNonNullElse(a.displayCharacter, ""),
46    requireNonNullElse(b.displayCharacter, ""))
47    && Objects
48    .equals(requireNonNullElse(a.description, ""),
49    requireNonNullElse(b.description, ""));
50    }
51   
 
52  0 toggle @Override
53    public void describeTo(Description description)
54    {
55  0 description.appendText("annotations ").appendValue(annotations);
56    }
57   
 
58  0 toggle @Override
59    public void describeMismatchSafely(Annotation[] items,
60    Description description)
61    {
62  0 if (annotations.size() != items.length)
63    {
64  0 description.appendText("but had length ").appendValue(items.length);
65  0 return;
66    }
67  0 boolean first = true;
68  0 for (int i = 0; i < annotations.size(); i++)
69    {
70  0 var actual = items[i];
71  0 var expected = annotations.get(i);
72  0 if (!annotationsEqual(actual, expected))
73    {
74  0 description
75  0 .appendText(first ? "but " : ", ")
76    .appendText("element [" + i + "] was ")
77    .appendValue(items[i]);
78  0 first = false;
79    }
80    }
81    }
82    }