View Javadoc
1   /**
2    * Copyright (c) 2013-2022, jcabi.com
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met: 1) Redistributions of source code must retain the above
8    * copyright notice, this list of conditions and the following
9    * disclaimer. 2) Redistributions in binary form must reproduce the above
10   * copyright notice, this list of conditions and the following
11   * disclaimer in the documentation and/or other materials provided
12   * with the distribution. 3) Neither the name of the jcabi.com nor
13   * the names of its contributors may be used to endorse or promote
14   * products derived from this software without specific prior written
15   * permission.
16   *
17   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21   * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28   * OF THE POSSIBILITY OF SUCH DAMAGE.
29   */
30  package com.jcabi.github.mock;
31  
32  import com.jcabi.github.Issue;
33  import com.jcabi.github.Label;
34  import com.jcabi.github.Labels;
35  import com.jcabi.github.Repo;
36  import java.util.Collections;
37  import org.hamcrest.MatcherAssert;
38  import org.hamcrest.Matchers;
39  import org.junit.Test;
40  
41  /**
42   * Test case for {@link MkLabels}.
43   * @author Yegor Bugayenko (yegor256@gmail.com)
44   * @version $Id: fc55b38b4bfd65491c43a8acb5efe0da11107342 $
45   */
46  public final class MkLabelsTest {
47  
48      /**
49       * MkLabels can list labels.
50       * @throws Exception If some problem inside
51       */
52      @Test
53      public void iteratesLabels() throws Exception {
54          final Repo repo = new MkGithub().randomRepo();
55          repo.labels().create("bug", "e0e0e0");
56          MatcherAssert.assertThat(
57              repo.labels().iterate(),
58              Matchers.<Label>iterableWithSize(1)
59          );
60      }
61  
62      /**
63       * MkLabels can delete labels.
64       * @throws Exception If some problem inside
65       */
66      @Test
67      public void deletesLabels() throws Exception {
68          final Repo repo = new MkGithub().randomRepo();
69          final Labels labels = repo.labels();
70          final String name = "label-0";
71          labels.create(name, "e1e1e1");
72          final Issue issue = repo.issues().create("hey, you!", "");
73          issue.labels().add(Collections.singletonList(name));
74          labels.delete(name);
75          MatcherAssert.assertThat(
76              repo.labels().iterate(),
77              Matchers.emptyIterable()
78          );
79          MatcherAssert.assertThat(
80              issue.labels().iterate(),
81              Matchers.emptyIterable()
82          );
83      }
84  
85      /**
86       * MkLabels can set label color.
87       * @throws Exception If some problem inside
88       */
89      @Test
90      public void setsLabelColor() throws Exception {
91          final Repo repo = new MkGithub().randomRepo();
92          final String color = "f0f0f0";
93          final String name = "task";
94          repo.labels().create(name, color);
95          MatcherAssert.assertThat(
96              new Label.Smart(repo.labels().get(name)).color(),
97              Matchers.equalTo(color)
98          );
99      }
100 }