Repository navigation
Expand file tree
/
Copy pathGHInvitationTest.java
More file actions
111 lines (89 loc) · 3.36 KB
/
Copy pathGHInvitationTest.java
File metadata and controls
111 lines (89 loc) · 3.36 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package org.kohsuke.github;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
import static org.hamcrest.Matchers.*;
/**
* Tests for {@link GHInvitation}.
*
* @author Yoann Rodiere
*/
public class GHInvitationTest extends AbstractGitHubWireMockTest {
/**
* Create default GHInvitationTest instance
*/
public GHInvitationTest() {
}
/**
* Test accepting a repository invitation.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Test
public void testAcceptInvitation() throws IOException {
List<GHInvitation> invitations = gitHub.getMyInvitations();
assertThat(invitations, hasSize(1));
GHInvitation invitation = invitations.get(0);
assertThat(invitation.getId(), not(equalTo(0L)));
invitation.accept();
assertThat(gitHub.getMyInvitations(), is(empty()));
}
/**
* Test declining a repository invitation.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Test
public void testDeclineInvitation() throws IOException {
List<GHInvitation> invitations = gitHub.getMyInvitations();
assertThat(invitations, hasSize(1));
GHInvitation invitation = invitations.get(0);
assertThat(invitation.getId(), not(equalTo(0L)));
invitation.decline();
assertThat(gitHub.getMyInvitations(), is(empty()));
}
/**
* Test that listing repository invitations returns correct data for all fields.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Test
public void testListInvitations() throws IOException {
GHRepository repo = getRepository();
List<GHInvitation> invitations = repo.listInvitations().toList();
assertThat(invitations, hasSize(1));
GHInvitation invitation = invitations.get(0);
assertThat(invitation.getId(), equalTo(1L));
assertThat(invitation.getNodeId(), equalTo("MDEwOlJlcG9zaXRvcnkxMjk2MjY5"));
assertThat(invitation.getPermission(), equalTo("write"));
assertThat(invitation.isExpired(), equalTo(false));
assertThat(invitation.getHtmlUrl().toString(),
equalTo("https://github.com/hub4j-test-org/github-api/invitations"));
assertThat(invitation.getCreatedAt().toString(), equalTo("2016-06-13T14:52:50Z"));
GHUser invitee = invitation.getInvitee();
assertThat(invitee, notNullValue());
assertThat(invitee.getLogin(), equalTo("octocat-invitee"));
GHUser inviter = invitation.getInviter();
assertThat(inviter, notNullValue());
assertThat(inviter.getLogin(), equalTo("octocat"));
GHRepository invitationRepo = invitation.getRepository();
assertThat(invitationRepo, notNullValue());
assertThat(invitationRepo.getName(), equalTo("github-api"));
}
private GHRepository getRepository(GitHub gitHub) throws IOException {
return gitHub.getOrganization("hub4j-test-org").getRepository("github-api");
}
/**
* Gets the repository.
*
* @return the repository
* @throws IOException
* Signals that an I/O exception has occurred.
*/
protected GHRepository getRepository() throws IOException {
return getRepository(gitHub);
}
}