View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github;
6   
7   import java.io.IOException;
8   import org.hamcrest.MatcherAssert;
9   import org.hamcrest.Matchers;
10  import org.junit.jupiter.api.AfterAll;
11  import org.junit.jupiter.api.BeforeAll;
12  import org.junit.jupiter.api.Test;
13  
14  /**
15   * Integration case for {@link IssueLabels}.
16   * @since 0.6
17   * @checkstyle ClassDataAbstractionCoupling (500 lines)
18   */
19  @OAuthScope(OAuthScope.Scope.REPO)
20  final class RtIssueLabelsITCase {
21      /**
22       * Test repos.
23       */
24      private static Repos repos;
25  
26      /**
27       * Test repo.
28       */
29      private static Repo repo;
30  
31      /**
32       * Set up test fixtures.
33       */
34      @BeforeAll
35      static void setUp() throws IOException {
36          final GitHub github = GitHubIT.connect();
37          RtIssueLabelsITCase.repos = github.repos();
38          RtIssueLabelsITCase.repo = new RepoRule().repo(RtIssueLabelsITCase.repos);
39      }
40  
41      /**
42       * Tear down test fixtures.
43       */
44      @AfterAll
45      static void tearDown() throws IOException {
46          if (RtIssueLabelsITCase.repos != null && RtIssueLabelsITCase.repo != null) {
47              RtIssueLabelsITCase.repos.remove(RtIssueLabelsITCase.repo.coordinates());
48          }
49      }
50  
51      /**
52       * RtIssueLabels can list all labels in an issue.
53       * @throws Exception If some problem inside
54       */
55      @Test
56      void listsLabels() throws Exception {
57          final IssueLabels.Smart labels = new IssueLabels.Smart(
58              RtIssueLabelsITCase.issue().labels()
59          );
60          final String name = "test-label";
61          final String color = "cfcfcf";
62          labels.addIfAbsent(name, color);
63          MatcherAssert.assertThat(
64              "Values are not equal",
65              new Label.Smart(labels.get(name)).color(),
66              Matchers.equalTo(color)
67          );
68          labels.remove(name);
69      }
70  
71      /**
72       * Create and return issue to test.
73       * @return Issue
74       */
75      private static Issue issue() throws IOException {
76          return RtIssueLabelsITCase.repo.issues().create("test issue title", "test issue body");
77      }
78  
79  }