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.DeployKey;
8   import com.jcabi.github.DeployKeys;
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 MkDeployKeys}.
16   * @since 0.8
17   */
18  final class MkDeployKeysTest {
19      @Test
20      void canFetchEmptyListOfDeployKeys() throws IOException {
21          final DeployKeys keys = new MkGitHub().randomRepo().keys();
22          MatcherAssert.assertThat(
23              "Collection is not empty",
24              keys.iterate(),
25              Matchers.emptyIterable()
26          );
27      }
28  
29      @Test
30      void canFetchSingleDeployKey() throws IOException {
31          final DeployKeys keys = new MkGitHub().randomRepo().keys();
32          final DeployKey key = keys.create("Title", "Key");
33          MatcherAssert.assertThat(
34              "Values are not equal",
35              keys.get(key.number()),
36              Matchers.equalTo(key)
37          );
38      }
39  
40      @Test
41      void canCreateDeployKey() throws IOException {
42          final DeployKeys keys = new MkGitHub().randomRepo().keys();
43          final DeployKey key = keys.create("Title1", "Key1");
44          MatcherAssert.assertThat(
45              "Values are not equal",
46              key,
47              Matchers.equalTo(keys.get(key.number()))
48          );
49      }
50  
51      /**
52       * MkDeployKeys can create distinct deploy keys.
53       * Reproduces bug described in issue #346.
54       */
55      @Test
56      void canCreateDistinctDeployKeys() throws IOException {
57          final DeployKeys keys = new MkGitHub().randomRepo().keys();
58          final DeployKey first = keys.create("Title2", "Key2");
59          final DeployKey second = keys.create("Title3", "Key3");
60          MatcherAssert.assertThat(
61              "Values are not equal",
62              first,
63              Matchers.not(Matchers.is(second))
64          );
65          MatcherAssert.assertThat(
66              "Values are not equal",
67              first.number(),
68              Matchers.not(Matchers.is(second.number()))
69          );
70      }
71  
72      /**
73       * MkDeployKeys can be represented in JSON format.
74       * Reproduces bug described in issue #346.
75       */
76      @Test
77      void canRepresentAsJson() throws IOException {
78          final DeployKeys keys = new MkGitHub().randomRepo().keys();
79          final DeployKey first = keys.create("Title4", "Key4");
80          MatcherAssert.assertThat(
81              "String does not contain expected value",
82              first.json().toString(),
83              Matchers.allOf(
84                  Matchers.containsString("\"title\":\"Title4\""),
85                  Matchers.containsString("\"key\":\"Key4\"")
86              )
87          );
88      }
89  }