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
31
32
33
34
35
36
37
38
39
40
41
42
43 package org.eclipse.jgit.transport;
44
45 import static org.junit.Assert.assertEquals;
46 import static org.junit.Assert.assertTrue;
47
48 import java.util.Arrays;
49
50 import org.junit.Test;
51 import org.junit.runner.RunWith;
52 import org.junit.runners.JUnit4;
53
54 @RunWith(JUnit4.class)
55 public class ProtocolV2HookChainTest {
56
57 @Test
58 public void testDefaultIfEmpty() {
59 ProtocolV2Hook[] noHooks = {};
60 ProtocolV2Hook newChain = ProtocolV2HookChain
61 .newChain(Arrays.asList(noHooks));
62 assertEquals(newChain, ProtocolV2Hook.DEFAULT);
63 }
64
65 @Test
66 public void testFlattenChainIfOnlyOne() {
67 FakeProtocolV2Hook hook1 = new FakeProtocolV2Hook();
68 ProtocolV2Hook newChain = ProtocolV2HookChain
69 .newChain(Arrays.asList(ProtocolV2Hook.DEFAULT, hook1));
70 assertEquals(newChain, hook1);
71 }
72
73 @Test
74 public void testMultipleHooks() throws ServiceMayNotContinueException {
75 FakeProtocolV2Hook hook1 = new FakeProtocolV2Hook();
76 FakeProtocolV2Hook hook2 = new FakeProtocolV2Hook();
77
78 ProtocolV2Hook chained = ProtocolV2HookChain
79 .newChain(Arrays.asList(hook1, hook2));
80 chained.onLsRefs(LsRefsV2Request.builder().build());
81
82 assertTrue(hook1.wasInvoked());
83 assertTrue(hook2.wasInvoked());
84 }
85
86 private static final class FakeProtocolV2Hook implements ProtocolV2Hook {
87 boolean invoked;
88
89 @Override
90 public void onLsRefs(LsRefsV2Request req)
91 throws ServiceMayNotContinueException {
92 invoked = true;
93 }
94
95 @Override
96 public void onCapabilities(CapabilitiesV2Request req)
97 throws ServiceMayNotContinueException {
98 throw new UnsupportedOperationException();
99 }
100
101 @Override
102 public void onFetch(FetchV2Request req)
103 throws ServiceMayNotContinueException {
104 throw new UnsupportedOperationException();
105 }
106
107 public boolean wasInvoked() {
108 return invoked;
109 }
110 }
111 }