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.Repo;
8   import jakarta.json.Json;
9   import jakarta.json.JsonObject;
10  import java.io.IOException;
11  import org.hamcrest.MatcherAssert;
12  import org.hamcrest.Matchers;
13  import org.junit.jupiter.api.Test;
14  
15  /**
16   * Testcase for MkTrees.
17   * @since 0.8
18   * @checkstyle MultipleStringLiterals (500 lines)
19   */
20  @SuppressWarnings("PMD.AvoidDuplicateLiterals")
21  final class MkTreesTest {
22  
23      @Test
24      void createsMkTree() throws IOException {
25          final JsonObject tree = Json.createObjectBuilder()
26              .add("base_tree", "base_tree_sha")
27              .add(
28                  "tree",
29                  Json.createArrayBuilder().add(
30                      Json.createObjectBuilder()
31                          .add("path", "dir/File.java")
32                          .add("mode", "100644")
33                          .add("type", "blob")
34                          .add("sha", "sha-test")
35                  )
36              ).build();
37          MatcherAssert.assertThat(
38              "Value is null",
39              new MkGitHub().randomRepo().git().trees().create(tree),
40              Matchers.notNullValue()
41          );
42      }
43  
44      @Test
45      void getTreeRec() throws IOException {
46          final String sha = "0abcd89jcabitest";
47          final JsonObject json = Json.createObjectBuilder().add(
48              "tree",
49              Json.createArrayBuilder().add(
50                  Json.createObjectBuilder()
51                      .add("path", "test.txt")
52                      .add("mode", "100644")
53                      .add("sha", sha).add("name", "tree rec")
54                      .add("type", "blob")
55                      .add("content", "hello")
56                      .build()
57              ).build()
58          ).build();
59          final Repo repo = new MkGitHub().randomRepo();
60          repo.git().trees().create(json);
61          MatcherAssert.assertThat(
62              "String does not contain expected value",
63              repo.git().trees().getRec(sha).json().getString("sha"),
64              Matchers.containsString(sha)
65          );
66      }
67  }