1 package jalview.testutils;
4 import java.util.Objects;
5 import static java.util.Objects.requireNonNullElse;
7 import org.hamcrest.Description;
8 import org.hamcrest.TypeSafeMatcher;
10 import jalview.datamodel.Annotation;
12 public class AnnotationsMatcher extends TypeSafeMatcher<Annotation[]>
14 final List<Annotation> annotations;
16 public AnnotationsMatcher(List<Annotation> annotations)
18 this.annotations = annotations;
22 public boolean matchesSafely(Annotation[] items)
24 if (annotations.size() != items.length)
26 for (int i = 0; i < annotations.size(); i++)
28 var actual = items[i];
29 var expected = annotations.get(i);
30 if (!annotationsEqual(actual, expected))
36 static boolean annotationsEqual(Annotation a, Annotation b)
38 return a.secondaryStructure == b.secondaryStructure && a.value == b.value
39 && Objects.equals(a.colour, b.colour)
41 .equals(requireNonNullElse(a.displayCharacter, ""),
42 requireNonNullElse(b.displayCharacter, ""))
44 .equals(requireNonNullElse(a.description, ""),
45 requireNonNullElse(b.description, ""));
49 public void describeTo(Description description)
51 description.appendText("annotations ").appendValue(annotations);
55 public void describeMismatchSafely(Annotation[] items,
56 Description description)
58 if (annotations.size() != items.length)
60 description.appendText("but had length ").appendValue(items.length);
64 for (int i = 0; i < annotations.size(); i++)
66 var actual = items[i];
67 var expected = annotations.get(i);
68 if (!annotationsEqual(actual, expected))
71 .appendText(first ? "but " : ", ")
72 .appendText("element [" + i + "] was ")
73 .appendValue(items[i]);