1
2
3
4
5 package com.jcabi.github.mock;
6
7 import com.jcabi.github.Hook;
8 import com.jcabi.github.Hooks;
9 import java.io.IOException;
10 import java.util.Collections;
11 import org.hamcrest.MatcherAssert;
12 import org.hamcrest.Matchers;
13 import org.junit.jupiter.api.Test;
14
15
16
17
18
19 @SuppressWarnings("PMD.AvoidDuplicateLiterals")
20 final class MkHooksTest {
21
22
23
24 private static final String HOOK_TYPE = "web";
25
26
27
28
29
30 @Test
31 void canFetchEmptyListOfHooks() throws Exception {
32 final Hooks hooks = MkHooksTest.newHooks();
33 MatcherAssert.assertThat(
34 "Collection is not empty",
35 hooks.iterate(),
36 Matchers.emptyIterable()
37 );
38 }
39
40
41
42
43
44 @Test
45 void canDeleteSingleHook() throws Exception {
46 final Hooks hooks = MkHooksTest.newHooks();
47 final Hook hook = hooks.create(
48 MkHooksTest.HOOK_TYPE,
49 Collections.emptyMap(),
50 Collections.emptyList(),
51 true
52 );
53 MatcherAssert.assertThat(
54 "Collection size is incorrect",
55 hooks.iterate(),
56 Matchers.iterableWithSize(1)
57 );
58 hooks.remove(hook.number());
59 MatcherAssert.assertThat(
60 "Collection is not empty",
61 hooks.iterate(),
62 Matchers.emptyIterable()
63 );
64 }
65
66
67
68
69
70 @Test
71 void canFetchSingleHook() throws Exception {
72 final Hooks hooks = MkHooksTest.newHooks();
73 final Hook hook = hooks.create(
74 MkHooksTest.HOOK_TYPE,
75 Collections.emptyMap(),
76 Collections.emptyList(),
77 true
78 );
79 MatcherAssert.assertThat(
80 "Value is null",
81 hooks.get(hook.number()),
82 Matchers.notNullValue()
83 );
84 }
85
86
87
88
89
90 @Test
91 void canFetchNonEmptyListOfHooks() throws Exception {
92 final Hooks hooks = MkHooksTest.newHooks();
93 hooks.create(
94 MkHooksTest.HOOK_TYPE,
95 Collections.emptyMap(),
96 Collections.emptyList(),
97 true
98 );
99 hooks.create(
100 MkHooksTest.HOOK_TYPE,
101 Collections.emptyMap(),
102 Collections.emptyList(),
103 true
104 );
105 MatcherAssert.assertThat(
106 "Collection size is incorrect",
107 hooks.iterate(),
108 Matchers.iterableWithSize(2)
109 );
110 }
111
112
113
114
115
116 @Test
117 void canCreateHook() throws Exception {
118 final Hooks hooks = MkHooksTest.newHooks();
119 final Hook hook = hooks.create(
120 MkHooksTest.HOOK_TYPE,
121 Collections.emptyMap(),
122 Collections.emptyList(),
123 true
124 );
125 MatcherAssert.assertThat(
126 "Values are not equal",
127 hooks.iterate().iterator().next().number(),
128 Matchers.equalTo(hook.number())
129 );
130 }
131
132
133
134
135
136 private static Hooks newHooks() throws IOException {
137 return new MkGitHub().randomRepo().hooks();
138 }
139 }