1
2
3
4
5 package com.jcabi.github.mock;
6
7 import com.jcabi.github.PublicKey;
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
17
18
19 final class MkPublicKeyTest {
20
21
22
23
24 public static final String KEY = "key";
25
26 @Test
27 void canRetrieveAsJson() throws IOException {
28 final String title = "Title1";
29 final String key = "PublicKey1";
30 final JsonObject json = new MkGitHub().users().add("john").keys()
31 .create(title, key).json();
32 MatcherAssert.assertThat(
33 "Values are not equal",
34 json.getString("id"),
35 Matchers.equalTo("1")
36 );
37 MatcherAssert.assertThat(
38 "Values are not equal",
39 json.getString("title"),
40 Matchers.equalTo(title)
41 );
42 MatcherAssert.assertThat(
43 "Values are not equal",
44 json.getString(MkPublicKeyTest.KEY),
45 Matchers.equalTo(key)
46 );
47 }
48
49 @Test
50 void canBePatched() throws IOException {
51 final String original = "PublicKey2";
52 final PublicKey key = new MkGitHub().users().add("jeff")
53 .keys().create("Title2", original);
54 final String patched = String.format("%s_patch", original);
55 key.patch(
56 Json.createObjectBuilder().add(MkPublicKeyTest.KEY, patched).build()
57 );
58 MatcherAssert.assertThat(
59 "Values are not equal",
60 key.json().getString(MkPublicKeyTest.KEY),
61 Matchers.equalTo(patched)
62 );
63 }
64
65 }