Repository navigation
Expand file tree
/
Copy pathGHIssueEventAttributeTest.java
More file actions
80 lines (68 loc) · 2.5 KB
/
Copy pathGHIssueEventAttributeTest.java
File metadata and controls
80 lines (68 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package org.kohsuke.github;
import org.junit.Test;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.StreamSupport;
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
// TODO: Auto-generated Javadoc
/**
* The Class GHIssueEventAttributeTest.
*/
public class GHIssueEventAttributeTest extends AbstractGitHubWireMockTest {
private enum Type implements Predicate<GHIssueEvent>, Consumer<GHIssueEvent> {
assignment(e -> assertThat(e.getAssignee(), notNullValue()), "assigned", "unassigned"),
label(e -> assertThat(e.getLabel(), notNullValue()), "labeled", "unlabeled"),
milestone(e -> {
assertThat(e.getMilestone(), notNullValue());
assertThat(e.getMilestone().getState(), nullValue());
}, "milestoned", "demilestoned");
private final Consumer<GHIssueEvent> assertion;
private final Set<String> subtypes;
Type(final Consumer<GHIssueEvent> assertion, final String... subtypes) {
this.assertion = assertion;
this.subtypes = new HashSet<>(asList(subtypes));
}
@Override
public void accept(final GHIssueEvent event) {
this.assertion.accept(event);
}
@Override
public boolean test(final GHIssueEvent event) {
return this.subtypes.contains(event.getEvent());
}
}
/**
* Create default GHIssueEventAttributeTest instance
*/
public GHIssueEventAttributeTest() {
}
/**
* Test event specific attributes.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Test
public void testEventSpecificAttributes() throws IOException {
for (Type type : Type.values()) {
final List<GHIssueEvent> events = listEvents(type);
assertThat(events, hasSize(2));
events.forEach(type);
}
}
private List<GHIssueEvent> listEvents(final Type type) throws IOException {
return StreamSupport
.stream(gitHub.getRepository("chids/project-milestone-test").getIssue(1).listEvents().spliterator(),
false)
.filter(type)
.collect(toList());
}
}