1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.transport;
11
12 import java.util.Collection;
13 import java.util.Set;
14 import java.util.stream.Collectors;
15
16 import org.eclipse.jgit.lib.ObjectId;
17 import org.eclipse.jgit.lib.Sets;
18 import org.hamcrest.Description;
19 import org.hamcrest.Matcher;
20 import org.hamcrest.TypeSafeMatcher;
21
22
23
24
25
26
27
28
29 class ObjectIdMatcher extends TypeSafeMatcher<Collection<ObjectId>> {
30
31 private final Set<ObjectId> expectedOids;
32
33 private ObjectIdMatcher(Set<String> oids) {
34 this.expectedOids = oids.stream().map(ObjectId::fromString)
35 .collect(Collectors.toSet());
36 }
37
38 @Override
39 public void describeTo(Description desc) {
40 desc.appendText("Object ids:");
41 desc.appendValueList("<", ",", ">", expectedOids);
42 }
43
44 @Override
45 protected boolean matchesSafely(Collection<ObjectId> resultOids) {
46 return resultOids.containsAll(expectedOids)
47 && expectedOids.containsAll(resultOids);
48 }
49
50
51
52
53
54
55
56
57
58
59
60
61 static Matcher<Collection<ObjectId>> hasOnlyObjectIds(
62 String... oids) {
63 return new ObjectIdMatcher(Sets.of(oids));
64 }
65 }