package org.kohsuke.github;

import org.junit.Test;
import org.kohsuke.github.GHTeam.Privacy;

import java.io.IOException;
import java.util.Set;

import static org.junit.Assert.assertEquals;

public class GHTeamTest extends AbstractGitHubWireMockTest {

    @Test
    public void testSetDescription() throws IOException {

        String description = "Updated by API Test";
        String teamSlug = "dummy-team";

        // Set the description.
        GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
        team.setDescription(description);

        // Check that it was set correctly.
        team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
        assertEquals(description, team.getDescription());

        description += "Modified";

        // Set the description.
        team.setDescription(description);

        // Check that it was set correctly.
        team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
        assertEquals(description, team.getDescription());
    }

    @Test
    public void testSetPrivacy() throws IOException {
        String teamSlug = "dummy-team";
        Privacy privacy = Privacy.CLOSED;

        // Set the privacy.
        GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
        team.setPrivacy(privacy);

        // Check that it was set correctly.
        team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
        assertEquals(privacy, team.getPrivacy());

        privacy = Privacy.SECRET;

        // Set the privacy.
        team.setPrivacy(privacy);

        // Check that it was set correctly.
        team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
        assertEquals(privacy, team.getPrivacy());
    }

    @Test
    public void testFetchChildTeams() throws IOException {
        String teamSlug = "dummy-team";

        GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
        GHTeam team = org.getTeamBySlug(teamSlug);
        Set<GHTeam> result = team.listChildTeams().toSet();

        assertEquals(1, result.size());
        assertEquals("child-team-for-dummy", result.toArray(new GHTeam[]{})[0].getName());
    }

    @Test
    public void testFetchEmptyChildTeams() throws IOException {
        String teamSlug = "simple-team";

        GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
        GHTeam team = org.getTeamBySlug(teamSlug);
        Set<GHTeam> result = team.listChildTeams().toSet();

        assertEquals(0, result.size());
    }

}

@@ -116,16 +116,39 @@
 eption;%0A
+import java.util.List;%0A
 import j
@@ -1081,32 +1081,908 @@
 tion());%0A    %7D%0A%0A
+    @Test%0A    public void testlistMembersAdmin() throws IOException %7B%0A        String teamSlug = %22dummy-team%22;%0A%0A        GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);%0A%0A        List%3CGHUser%3E admins = team.listMembers(%22admin%22).asList();%0A%0A        assertNotNull(admins);%0A        assertThat(%22One admin in dummy team%22, admins.size() == 1);%0A        assertThat(%22Specific user in admin team%22,%0A                admins.stream().anyMatch(ghUser -%3E ghUser.getLogin().equals(%22bitwiseman%22)));%0A    %7D%0A%0A    @Test%0A    public void testlistMembersNoMatch() throws IOException %7B%0A        String teamSlug = %22dummy-team%22;%0A%0A        GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);%0A%0A        List%3CGHUser%3E justMembers = team.listMembers(%22member%22).asList();%0A%0A        assertThat(%22No regular members in team%22, justMembers.isEmpty());%0A    %7D%0A%0A
     @Test%0A    pu

add tests