選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ProtocolV2HookChainTest.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2019, Google LLC. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.transport;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertTrue;
  13. import java.util.Arrays;
  14. import org.junit.Test;
  15. import org.junit.runner.RunWith;
  16. import org.junit.runners.JUnit4;
  17. @RunWith(JUnit4.class)
  18. public class ProtocolV2HookChainTest {
  19. @Test
  20. public void testDefaultIfEmpty() {
  21. ProtocolV2Hook[] noHooks = {};
  22. ProtocolV2Hook newChain = ProtocolV2HookChain
  23. .newChain(Arrays.asList(noHooks));
  24. assertEquals(newChain, ProtocolV2Hook.DEFAULT);
  25. }
  26. @Test
  27. public void testFlattenChainIfOnlyOne() {
  28. FakeProtocolV2Hook hook1 = new FakeProtocolV2Hook();
  29. ProtocolV2Hook newChain = ProtocolV2HookChain
  30. .newChain(Arrays.asList(ProtocolV2Hook.DEFAULT, hook1));
  31. assertEquals(newChain, hook1);
  32. }
  33. @Test
  34. public void testMultipleHooks() throws ServiceMayNotContinueException {
  35. FakeProtocolV2Hook hook1 = new FakeProtocolV2Hook();
  36. FakeProtocolV2Hook hook2 = new FakeProtocolV2Hook();
  37. ProtocolV2Hook chained = ProtocolV2HookChain
  38. .newChain(Arrays.asList(hook1, hook2));
  39. chained.onLsRefs(LsRefsV2Request.builder().build());
  40. assertTrue(hook1.wasInvoked());
  41. assertTrue(hook2.wasInvoked());
  42. }
  43. private static final class FakeProtocolV2Hook implements ProtocolV2Hook {
  44. boolean invoked;
  45. @Override
  46. public void onLsRefs(LsRefsV2Request req)
  47. throws ServiceMayNotContinueException {
  48. invoked = true;
  49. }
  50. @Override
  51. public void onCapabilities(CapabilitiesV2Request req)
  52. throws ServiceMayNotContinueException {
  53. throw new UnsupportedOperationException();
  54. }
  55. @Override
  56. public void onFetch(FetchV2Request req)
  57. throws ServiceMayNotContinueException {
  58. throw new UnsupportedOperationException();
  59. }
  60. public boolean wasInvoked() {
  61. return invoked;
  62. }
  63. }
  64. }