您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PreUploadHookChainTest.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 java.util.Collection;
  15. import org.eclipse.jgit.lib.ObjectId;
  16. import org.junit.Test;
  17. import org.junit.runner.RunWith;
  18. import org.junit.runners.JUnit4;
  19. @RunWith(JUnit4.class)
  20. public class PreUploadHookChainTest {
  21. @Test
  22. public void testDefaultIfEmpty() {
  23. PreUploadHook[] noHooks = {};
  24. PreUploadHook newChain = PreUploadHookChain
  25. .newChain(Arrays.asList(noHooks));
  26. assertEquals(newChain, PreUploadHook.NULL);
  27. }
  28. @Test
  29. public void testFlattenChainIfOnlyOne() {
  30. FakePreUploadHook hook1 = new FakePreUploadHook();
  31. PreUploadHook newChain = PreUploadHookChain
  32. .newChain(Arrays.asList(PreUploadHook.NULL, hook1));
  33. assertEquals(newChain, hook1);
  34. }
  35. @Test
  36. public void testMultipleHooks() throws ServiceMayNotContinueException {
  37. FakePreUploadHook hook1 = new FakePreUploadHook();
  38. FakePreUploadHook hook2 = new FakePreUploadHook();
  39. PreUploadHook chained = PreUploadHookChain
  40. .newChain(Arrays.asList(hook1, hook2));
  41. chained.onBeginNegotiateRound(null, null, 0);
  42. assertTrue(hook1.wasInvoked());
  43. assertTrue(hook2.wasInvoked());
  44. }
  45. private static final class FakePreUploadHook implements PreUploadHook {
  46. boolean invoked;
  47. @Override
  48. public void onBeginNegotiateRound(UploadPack up,
  49. Collection<? extends ObjectId> wants, int cntOffered)
  50. throws ServiceMayNotContinueException {
  51. invoked = true;
  52. }
  53. @Override
  54. public void onEndNegotiateRound(UploadPack up,
  55. Collection<? extends ObjectId> wants, int cntCommon,
  56. int cntNotFound, boolean ready)
  57. throws ServiceMayNotContinueException {
  58. throw new UnsupportedOperationException();
  59. }
  60. @Override
  61. public void onSendPack(UploadPack up,
  62. Collection<? extends ObjectId> wants,
  63. Collection<? extends ObjectId> haves)
  64. throws ServiceMayNotContinueException {
  65. throw new UnsupportedOperationException();
  66. }
  67. public boolean wasInvoked() {
  68. return invoked;
  69. }
  70. }
  71. }