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