1
2
3
4
5 package com.jcabi.github;
6
7 import jakarta.json.Json;
8 import java.io.IOException;
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.junit.jupiter.api.Test;
12 import org.mockito.Mockito;
13
14
15
16
17
18
19 final class PublicKeyTest {
20
21 @Test
22 void fetchesKey() throws IOException {
23 final PublicKey key = Mockito.mock(PublicKey.class);
24 final String value = "sha-rsa AAA...";
25 Mockito.doReturn(
26 Json.createObjectBuilder().add("key", value).build()
27 ).when(key).json();
28 MatcherAssert.assertThat(
29 "Values are not equal",
30 new PublicKey.Smart(key).key(),
31 Matchers.is(value)
32 );
33 }
34
35 @Test
36 void updatesKey() throws IOException {
37 final PublicKey key = Mockito.mock(PublicKey.class);
38 final String value = "sha-rsa BBB...";
39 new PublicKey.Smart(key).key(value);
40 Mockito.verify(key).patch(
41 Json.createObjectBuilder().add("key", value).build()
42 );
43 }
44
45 @Test
46 void fetchesUrl() throws IOException {
47 final PublicKey key = Mockito.mock(PublicKey.class);
48 final String prop = "https://api.github.com/user/keys/1";
49 Mockito.doReturn(
50 Json.createObjectBuilder().add("url", prop).build()
51 ).when(key).json();
52 MatcherAssert.assertThat(
53 "Values are not equal",
54 new PublicKey.Smart(key).url().toString(),
55 Matchers.is(prop)
56 );
57 }
58
59 @Test
60 void fetchesTitle() throws IOException {
61 final PublicKey key = Mockito.mock(PublicKey.class);
62 final String prop = "octocat@octomac";
63 Mockito.doReturn(
64 Json.createObjectBuilder().add("title", prop).build()
65 ).when(key).json();
66 MatcherAssert.assertThat(
67 "Values are not equal",
68 new PublicKey.Smart(key).title(),
69 Matchers.is(prop)
70 );
71 }
72
73 @Test
74 void updatesTitle() throws IOException {
75 final PublicKey key = Mockito.mock(PublicKey.class);
76 final String prop = "octocat@octomac";
77 new PublicKey.Smart(key).title(prop);
78 Mockito.verify(key).patch(
79 Json.createObjectBuilder().add("title", prop).build()
80 );
81 }
82
83 }