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.Tree;
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 MkTree.
17   * @since 0.8
18   * @checkstyle MultipleStringLiterals (500 lines)
19   */
20  final class MkTreeTest {
21  
22      /**
23       * MkTree should return its json.
24       * @throws Exception If something goes wrong.
25       */
26      @Test
27      void fetchesContent() throws Exception {
28          MatcherAssert.assertThat(
29              "Values are not equal",
30              MkTreeTest.tree().json().getString("message"),
31              Matchers.is("\"test tree\"")
32          );
33      }
34  
35      /**
36       * Return a Tree for testing.
37       * @return Tree
38       */
39      private static Tree tree() throws IOException {
40          final JsonObject json = Json.createObjectBuilder().add(
41              "tree",
42              Json.createArrayBuilder().add(
43                  Json.createObjectBuilder()
44                      .add("sha", "abcsha12").add("message", "test tree")
45                      .add("name", "v.0.1").build()
46              )
47          ).build();
48          return new MkGitHub().randomRepo().git().trees().create(json);
49      }
50  
51  }