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.PullComment;
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 MkPullComment}.
16   * @since 0.1
17   */
18  final class MkPullCommentTest {
19      /**
20       * MkPullComment can be represented as JSON.
21       * @throws Exception If a problem occurs.
22       */
23      @Test
24      void retrieveAsJson() throws Exception {
25          final PullComment comment = MkPullCommentTest.comment();
26          MatcherAssert.assertThat(
27              "String does not start with expected value",
28              comment.json().getString("url"),
29              Matchers.startsWith("http://")
30          );
31      }
32  
33      /**
34       * MkPullComment can accept a PATCH request.
35       * @throws Exception If a problem occurs.
36       */
37      @Test
38      void executePatchRequest() throws Exception {
39          final String path = "/path/to/file.txt";
40          final PullComment comment = MkPullCommentTest.comment();
41          comment.patch(Json.createObjectBuilder().add("path", path).build());
42          MatcherAssert.assertThat(
43              "String does not contain expected value",
44              comment.json().toString(),
45              Matchers.containsString(path)
46          );
47      }
48  
49      /**
50       * Create and return pull comment to test.
51       * @return PullComment
52       */
53      private static PullComment comment() throws IOException {
54          return new MkGitHub()
55              .randomRepo()
56              .pulls()
57              .create("hello", "head", "base")
58              .comments()
59              .post("comment", "commit", "/", 1);
60      }
61  }