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.Issue;
8   import com.jcabi.github.Label;
9   import com.jcabi.github.Labels;
10  import com.jcabi.github.Repo;
11  import java.io.IOException;
12  import java.util.Collections;
13  import org.hamcrest.MatcherAssert;
14  import org.hamcrest.Matchers;
15  import org.junit.jupiter.api.Test;
16  
17  /**
18   * Test case for {@link MkLabels}.
19   * @since 0.6
20   */
21  final class MkLabelsTest {
22  
23      @Test
24      void iteratesLabels() throws IOException {
25          final Repo repo = new MkGitHub().randomRepo();
26          repo.labels().create("bug", "e0e0e0");
27          MatcherAssert.assertThat(
28              "Collection size is incorrect",
29              repo.labels().iterate(),
30              Matchers.iterableWithSize(1)
31          );
32      }
33  
34      @Test
35      void deletesLabels() throws IOException {
36          final Repo repo = new MkGitHub().randomRepo();
37          final Labels labels = repo.labels();
38          final String name = "label-0";
39          labels.create(name, "e1e1e1");
40          final Issue issue = repo.issues().create("hey, you!", "");
41          issue.labels().add(Collections.singletonList(name));
42          labels.delete(name);
43          MatcherAssert.assertThat(
44              "Collection is not empty",
45              repo.labels().iterate(),
46              Matchers.emptyIterable()
47          );
48          MatcherAssert.assertThat(
49              "Collection is not empty",
50              issue.labels().iterate(),
51              Matchers.emptyIterable()
52          );
53      }
54  
55      @Test
56      void setsLabelColor() throws IOException {
57          final Repo repo = new MkGitHub().randomRepo();
58          final String color = "f0f0f0";
59          final String name = "task";
60          repo.labels().create(name, color);
61          MatcherAssert.assertThat(
62              "Values are not equal",
63              new Label.Smart(repo.labels().get(name)).color(),
64              Matchers.equalTo(color)
65          );
66      }
67  }