Skip to content

Package: ContainsSameEntities

ContainsSameEntities

nameinstructionbranchcomplexitylinemethod
ContainsSameEntities(Collection)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
containsSameEntities(Collection)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
describeTo(Description)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
lambda$0(HasUri, HasUri)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
matchesSafely(Collection)
M: 4 C: 28
88%
M: 3 C: 5
63%
M: 3 C: 2
40%
M: 2 C: 4
67%
M: 0 C: 1
100%

Coverage

1: package cz.cvut.kbss.jopa.test.environment.util;
2:
3: import cz.cvut.kbss.jopa.test.HasUri;
4: import org.hamcrest.Description;
5: import org.hamcrest.TypeSafeMatcher;
6:
7: import java.util.Collection;
8: import java.util.Objects;
9:
10: /**
11: * Checks whether the provided collection contains the same entities as the expected one.
12: * <p>
13: * The membership check is done based on entity URIs.
14: *
15: * Item order is not significant in the comparison, but the total number of items is.
16: */
17: public class ContainsSameEntities extends TypeSafeMatcher<Collection<? extends HasUri>> {
18:
19: private final Collection<? extends HasUri> expected;
20:
21: public ContainsSameEntities(Collection<? extends HasUri> expected) {
22: this.expected = Objects.requireNonNull(expected);
23: }
24:
25: @Override
26: protected boolean matchesSafely(Collection<? extends HasUri> actual) {
27:• if (actual == null || actual.size() != expected.size()) {
28: return false;
29: }
30:• for (HasUri e : expected) {
31:• if (actual.stream().noneMatch(ee -> Objects.equals(e.getUri(), ee.getUri()))) {
32: return false;
33: }
34: }
35: return true;
36: }
37:
38: @Override
39: public void describeTo(Description description) {
40: description.appendValueList("[", ", ", "]", expected);
41: }
42:
43: public static ContainsSameEntities containsSameEntities(Collection<? extends HasUri> expected) {
44: return new ContainsSameEntities(expected);
45: }
46: }