View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github.mock;
6   
7   import com.jcabi.github.Collaborators;
8   import java.io.IOException;
9   import org.hamcrest.MatcherAssert;
10  import org.hamcrest.Matchers;
11  import org.junit.jupiter.api.Test;
12  
13  /**
14   * Test case for {@link MkCollaborators}.
15   * @since 0.7
16   */
17  final class MkCollaboratorsTest {
18  
19      /**
20       * MkCollaborators can add, remove and iterate collaborators.
21       * @throws Exception If some problem inside
22       */
23      @Test
24      void addAndRemove() throws Exception {
25          final Collaborators collabs = MkCollaboratorsTest.collaborators();
26          final String login = "some_user";
27          collabs.add(login);
28          MatcherAssert.assertThat(
29              "Collection size is incorrect",
30              collabs.iterate(),
31              Matchers.iterableWithSize(1)
32          );
33          MatcherAssert.assertThat(
34              "Values are not equal",
35              collabs.iterate().iterator().next().login(),
36              Matchers.equalTo(login)
37          );
38          collabs.remove(login);
39          MatcherAssert.assertThat(
40              "Collection size is incorrect",
41              collabs.iterate(),
42              Matchers.iterableWithSize(0)
43          );
44      }
45  
46      /**
47       * MkCollaborators can check whether  user is collaborator or not.
48       * @throws Exception If some problem inside
49       */
50      @Test
51      void isCollaborator() throws Exception {
52          final Collaborators collabs = MkCollaboratorsTest.collaborators();
53          final String collaborator = "collaborator";
54          collabs.add(collaborator);
55          MatcherAssert.assertThat(
56              "Values are not equal",
57              collabs.isCollaborator(collaborator),
58              Matchers.equalTo(true)
59          );
60          final String stranger = "stranger";
61          MatcherAssert.assertThat(
62              "Values are not equal",
63              collabs.isCollaborator(stranger),
64              Matchers.equalTo(false)
65          );
66      }
67  
68      /**
69       * Create a collaborators to work with.
70       * @return Collaborators just created
71       */
72      private static Collaborators collaborators() throws IOException {
73          return new MkGitHub().randomRepo().collaborators();
74      }
75  }