| 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 |
|
|
| |
|
| 47.9% |
Uncovered Elements: 25 (48) |
Complexity: 15 |
Complexity Density: 0.6 |
|
| 12 |
|
public class AnnotationsMatcher extends TypeSafeMatcher<Annotation[]> |
| 13 |
|
{ |
| 14 |
|
final List<Annotation> annotations; |
| 15 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 16 |
37 |
public AnnotationsMatcher(List<Annotation> annotations)... |
| 17 |
|
{ |
| 18 |
37 |
this.annotations = annotations; |
| 19 |
|
} |
| 20 |
|
|
| |
|
| 71.4% |
Uncovered Elements: 4 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 21 |
37 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 36 |
488 |
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)) |
| 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 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
0 |
@Override... |
| 53 |
|
public void describeTo(Description description) |
| 54 |
|
{ |
| 55 |
0 |
description.appendText("annotations ").appendValue(annotations); |
| 56 |
|
} |
| 57 |
|
|
| |
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
| 58 |
0 |
@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 |
|
} |