|
3 | 3 | import java.io.IOException; |
4 | 4 | import java.net.URL; |
5 | 5 | import java.util.ArrayList; |
6 | | -import java.util.Collection; |
| 6 | +import java.util.Date; |
7 | 7 | import java.util.List; |
8 | 8 | import java.util.Map; |
| 9 | +import java.util.Map.Entry; |
9 | 10 | import java.util.Set; |
10 | 11 | import java.util.UUID; |
11 | 12 |
|
12 | | -import static org.junit.Assert.assertEquals; |
13 | | -import static org.junit.Assert.assertFalse; |
14 | | -import static org.junit.Assert.assertNotNull; |
15 | | -import static org.junit.Assert.assertSame; |
16 | | -import static org.junit.Assert.assertTrue; |
17 | | -import static org.junit.Assert.fail; |
18 | | - |
19 | 13 | import org.junit.Assume; |
20 | 14 | import org.junit.Test; |
21 | 15 | import org.kohsuke.github.GHCommit.File; |
|
24 | 18 | import com.google.common.base.Predicate; |
25 | 19 | import com.google.common.collect.Iterables; |
26 | 20 |
|
27 | | -import java.util.Date; |
28 | | - |
29 | 21 | /** |
30 | 22 | * Unit test for simple App. |
31 | 23 | */ |
@@ -170,6 +162,35 @@ public void testMyOrganizations() throws IOException { |
170 | 162 | System.out.println(org); |
171 | 163 | } |
172 | 164 |
|
| 165 | + @Test |
| 166 | + public void testMyTeamsContainsAllMyOrganizations() throws IOException { |
| 167 | + Map<String, Set<GHTeam>> teams = gitHub.getMyTeams(); |
| 168 | + Map<String, GHOrganization> myOrganizations = gitHub.getMyOrganizations(); |
| 169 | + assertEquals(teams.keySet(), myOrganizations.keySet()); |
| 170 | + } |
| 171 | + |
| 172 | + @Test |
| 173 | + public void testMyTeamsShouldIncludeMyself() throws IOException { |
| 174 | + Map<String, Set<GHTeam>> teams = gitHub.getMyTeams(); |
| 175 | + for (Entry<String, Set<GHTeam>> teamsPerOrg : teams.entrySet()) { |
| 176 | + String organizationName = teamsPerOrg.getKey(); |
| 177 | + for (GHTeam team : teamsPerOrg.getValue()) { |
| 178 | + String teamName = team.getName(); |
| 179 | + assertTrue("Team " + teamName + " in organization " + organizationName |
| 180 | + + " does not contain myself", |
| 181 | + shouldBelongToTeam(organizationName, teamName)); |
| 182 | + } |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + private boolean shouldBelongToTeam(String organizationName, String teamName) throws IOException { |
| 187 | + GHOrganization org = gitHub.getOrganization(organizationName); |
| 188 | + assertNotNull(org); |
| 189 | + GHTeam team = org.getTeamByName(teamName); |
| 190 | + assertNotNull(team); |
| 191 | + return team.hasMember(gitHub.getMyself()); |
| 192 | + } |
| 193 | + |
173 | 194 | @Test |
174 | 195 | public void testFetchPullRequest() throws Exception { |
175 | 196 | GHRepository r = gitHub.getOrganization("jenkinsci").getRepository("jenkins"); |
|
0 commit comments