Package: ContainsSameEntities
ContainsSameEntities
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ContainsSameEntities(Collection) |
|
|
|
|
|
||||||||||||||||||||
containsSameEntities(Collection) |
|
|
|
|
|
||||||||||||||||||||
describeTo(Description) |
|
|
|
|
|
||||||||||||||||||||
lambda$0(HasUri, HasUri) |
|
|
|
|
|
||||||||||||||||||||
matchesSafely(Collection) |
|
|
|
|
|
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: }