1
2
3
4
5 package com.jcabi.github.mock;
6
7 import com.jcabi.github.PublicKey;
8 import com.jcabi.github.PublicKeys;
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
16
17
18 final class MkPublicKeysTest {
19
20 @Test
21 void retrievesKeys() throws IOException {
22 final PublicKeys keys = new MkGitHub().users().self().keys();
23 final PublicKey key = keys.create("key", "ssh 1AA");
24 MatcherAssert.assertThat(
25 "Collection does not contain expected item",
26 keys.iterate(),
27 Matchers.hasItem(key)
28 );
29 }
30
31 @Test
32 void canFetchSingleKey() throws IOException {
33 final PublicKeys keys = new MkGitHub().users().add("jeff").keys();
34 MatcherAssert.assertThat(
35 "Value is null",
36 keys.get(1),
37 Matchers.notNullValue()
38 );
39 }
40
41 @Test
42 void canCreatePublicKey() throws IOException {
43 final PublicKeys keys = new MkGitHub().users().add("john").keys();
44 final PublicKey key = keys.create("Title1", "PublicKey1");
45 MatcherAssert.assertThat(
46 "Values are not equal",
47 keys.get(key.number()),
48 Matchers.equalTo(key)
49 );
50 }
51
52 @Test
53 void canRemoveKey() throws IOException {
54 final PublicKeys keys = new MkGitHub().users().self().keys();
55 final PublicKey key = keys.create("rsa", "rsa sh");
56 MatcherAssert.assertThat(
57 "Collection does not contain expected item",
58 keys.iterate(),
59 Matchers.hasItem(key)
60 );
61 keys.remove(key.number());
62 MatcherAssert.assertThat(
63 "Collection does not contain expected item",
64 keys.iterate(),
65 Matchers.not(Matchers.hasItem(key))
66 );
67 }
68
69 }