1
2
3
4
5 package com.jcabi.github.mock;
6
7 import com.jcabi.github.Organization;
8 import com.jcabi.github.PublicMembers;
9 import com.jcabi.github.User;
10 import java.io.IOException;
11 import org.apache.commons.lang3.RandomStringUtils;
12 import org.hamcrest.MatcherAssert;
13 import org.hamcrest.Matchers;
14 import org.junit.jupiter.api.Test;
15
16
17
18
19
20 final class MkPublicMembersTest {
21 @Test
22 void fetchesOrg() throws IOException {
23 final Organization org = MkPublicMembersTest.organization();
24 MatcherAssert.assertThat(
25 "Values are not equal",
26 org.publicMembers().org().login(),
27 Matchers.equalTo(org.login())
28 );
29 }
30
31
32
33
34 @Test
35 void changesPublicityOfMembershipOfUsers() throws IOException {
36 final MkOrganization org = MkPublicMembersTest.organization();
37 final PublicMembers members = org.publicMembers();
38 final User user = org.github().users().get("johnny5");
39 org.addMember(user);
40 MatcherAssert.assertThat(
41 "Newly-added user is not a public member",
42 !members.contains(user),
43 Matchers.is(true)
44 );
45 members.publicize(user);
46 MatcherAssert.assertThat(
47 "User has been made a public member",
48 members.contains(user),
49 Matchers.is(true)
50 );
51 members.conceal(user);
52 MatcherAssert.assertThat(
53 "Concealed user is not a public member",
54 !members.contains(user),
55 Matchers.is(true)
56 );
57 members.publicize(user);
58 MatcherAssert.assertThat(
59 "User has been made a public member again",
60 members.contains(user),
61 Matchers.is(true)
62 );
63 }
64
65 @Test
66 void checkPublicMembership() throws IOException {
67 final MkOrganization org = MkPublicMembersTest.organization();
68 final PublicMembers members = org.publicMembers();
69 final User user = org.github().users().get("agent99");
70 MatcherAssert.assertThat(
71 "Collection is not empty",
72 members.iterate(),
73 Matchers.emptyIterableOf(User.class)
74 );
75 org.addMember(user);
76 MatcherAssert.assertThat(
77 "The newly-added user is not a public member",
78 !members.contains(user),
79 Matchers.is(true)
80 );
81 members.publicize(user);
82 MatcherAssert.assertThat(
83 "The user has been made a public member",
84 members.contains(user),
85 Matchers.is(true)
86 );
87 MatcherAssert.assertThat(
88 "Collection does not contain expected item",
89 members.iterate(),
90 Matchers.hasItem(user)
91 );
92 members.conceal(user);
93 MatcherAssert.assertThat(
94 "The concealed user is not a public member",
95 !members.contains(user),
96 Matchers.is(true)
97 );
98 }
99
100 @Test
101 void iteratesPublicMembers() throws IOException {
102 final MkOrganization org = MkPublicMembersTest.organization();
103 final PublicMembers members = org.publicMembers();
104 final User user = org.github().users().get("jasmine");
105 MatcherAssert.assertThat(
106 "Collection is not empty",
107 members.iterate(),
108 Matchers.emptyIterableOf(User.class)
109 );
110 org.addMember(user);
111 MatcherAssert.assertThat(
112 "Collection is not empty",
113 members.iterate(),
114 Matchers.emptyIterableOf(User.class)
115 );
116 members.publicize(user);
117 MatcherAssert.assertThat(
118 "Collection size is incorrect",
119 members.iterate(),
120 Matchers.iterableWithSize(1)
121 );
122 MatcherAssert.assertThat(
123 "Collection does not contain expected item",
124 members.iterate(),
125 Matchers.hasItem(user)
126 );
127 members.conceal(user);
128 MatcherAssert.assertThat(
129 "Collection is not empty",
130 members.iterate(),
131 Matchers.emptyIterableOf(User.class)
132 );
133 }
134
135
136
137
138
139
140 private static MkOrganization organization() throws IOException {
141 return (MkOrganization) new MkOrganizations(
142 new MkStorage.InFile()
143 ).get(RandomStringUtils.secure().nextAlphanumeric(20));
144 }
145 }