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;
31  
32  import com.jcabi.github.mock.MkGithub;
33  import java.io.IOException;
34  import javax.json.Json;
35  import org.hamcrest.MatcherAssert;
36  import org.hamcrest.Matchers;
37  import org.junit.Test;
38  
39  /**
40   * Test case for {@link RtStatus}.
41   * @author Chris Rebert (github@chrisrebert.com)
42   * @version $Id: 4050bb16dfe6b9fa9cdd0b533283ae2cc29ab715 $
43   * @since 0.24
44   */
45  public final class RtStatusTest {
46      /**
47       * RtStatus can fetch its ID number.
48       * @throws IOException If there is an I/O problem.
49       */
50      @Test
51      public void fetchesId() throws IOException {
52          final int ident = 666;
53          MatcherAssert.assertThat(
54              new RtStatus(
55                  RtStatusTest.commit(),
56                  Json.createObjectBuilder().add("id", ident).build()
57              ).identifier(),
58              Matchers.equalTo(ident)
59          );
60      }
61  
62      /**
63       * RtStatus can fetch its URL.
64       * @throws IOException If there is an I/O problem.
65       */
66      @Test
67      public void fetchesUrl() throws IOException {
68          final String url = "http://api.jcabi-github.invalid/whatever";
69          MatcherAssert.assertThat(
70              new RtStatus(
71                  RtStatusTest.commit(),
72                  Json.createObjectBuilder().add("url", url).build()
73              ).url(),
74              Matchers.equalTo(url)
75          );
76      }
77  
78      /**
79       * RtStatus can fetch its associated commit.
80       * @throws IOException If there is an I/O problem.
81       */
82      @Test
83      public void fetchesCommit() throws IOException {
84          final Commit cmmt = RtStatusTest.commit();
85          MatcherAssert.assertThat(
86              new RtStatus(cmmt, Json.createObjectBuilder().build()).commit(),
87              Matchers.equalTo(cmmt)
88          );
89      }
90  
91      /**
92       * Returns a test commit to work with.
93       * @return Commit
94       * @throws IOException If there is an I/O problem.
95       */
96      private static Commit commit() throws IOException {
97          return new MkGithub().randomRepo().git().commits()
98              .get("d288364af5028c72e2a2c91c29343bae11fffcbe");
99      }
100 }