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 com.jcabi.github.mock.MkGitHub;
8   import jakarta.json.Json;
9   import java.io.IOException;
10  import org.hamcrest.MatcherAssert;
11  import org.hamcrest.Matchers;
12  import org.junit.jupiter.api.Test;
13  
14  /**
15   * Test case for {@link RtStatus}.
16   * @since 0.24
17   */
18  final class RtStatusTest {
19      /**
20       * RtStatus can fetch its ID number.
21       * @throws IOException If there is an I/O problem.
22       */
23      @Test
24      void fetchesId() throws IOException {
25          final int ident = 666;
26          MatcherAssert.assertThat(
27              "Values are not equal",
28              new RtStatus(
29                  RtStatusTest.commit(),
30                  Json.createObjectBuilder().add("id", ident).build()
31              ).identifier(),
32              Matchers.equalTo(ident)
33          );
34      }
35  
36      /**
37       * RtStatus can fetch its URL.
38       * @throws IOException If there is an I/O problem.
39       */
40      @Test
41      void fetchesUrl() throws IOException {
42          final String url = "http://api.jcabi-github.invalid/whatever";
43          MatcherAssert.assertThat(
44              "Values are not equal",
45              new RtStatus(
46                  RtStatusTest.commit(),
47                  Json.createObjectBuilder().add("url", url).build()
48              ).url(),
49              Matchers.equalTo(url)
50          );
51      }
52  
53      /**
54       * RtStatus can fetch its associated commit.
55       * @throws IOException If there is an I/O problem.
56       */
57      @Test
58      void fetchesCommit() throws IOException {
59          final Commit cmmt = RtStatusTest.commit();
60          MatcherAssert.assertThat(
61              "Values are not equal",
62              new RtStatus(cmmt, Json.createObjectBuilder().build()).commit(),
63              Matchers.equalTo(cmmt)
64          );
65      }
66  
67      /**
68       * Returns a test commit to work with.
69       * @return Commit
70       * @throws IOException If there is an I/O problem.
71       */
72      private static Commit commit() throws IOException {
73          return new MkGitHub().randomRepo().git().commits()
74              .get("d288364af5028c72e2a2c91c29343bae11fffcbe");
75      }
76  }