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$matchesSafely$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: 5
71%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.test.environment.util;
19:
20: import cz.cvut.kbss.jopa.test.HasUri;
21: import org.hamcrest.Description;
22: import org.hamcrest.TypeSafeMatcher;
23:
24: import java.util.Collection;
25: import java.util.Objects;
26:
27: /**
28: * Checks whether the provided collection contains the same entities as the expected one.
29: * <p>
30: * The membership check is done based on entity URIs.
31: *
32: * Item order is not significant in the comparison, but the total number of items is.
33: */
34: public class ContainsSameEntities extends TypeSafeMatcher<Collection<? extends HasUri>> {
35:
36: private final Collection<? extends HasUri> expected;
37:
38: public ContainsSameEntities(Collection<? extends HasUri> expected) {
39: this.expected = Objects.requireNonNull(expected);
40: }
41:
42: @Override
43: protected boolean matchesSafely(Collection<? extends HasUri> actual) {
44:• if (actual == null || actual.size() != expected.size()) {
45: return false;
46: }
47:• for (HasUri e : expected) {
48:• if (actual.stream().noneMatch(ee -> Objects.equals(e.getUri(), ee.getUri()))) {
49: return false;
50: }
51: }
52: return true;
53: }
54:
55: @Override
56: public void describeTo(Description description) {
57: description.appendValueList("[", ", ", "]", expected);
58: }
59:
60: public static ContainsSameEntities containsSameEntities(Collection<? extends HasUri> expected) {
61: return new ContainsSameEntities(expected);
62: }
63: }