You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PostUploadHookChainTest.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.eclipse.jgit.storage.pack.PackStatistics;
  15. import org.junit.Test;
  16. import org.junit.runner.RunWith;
  17. import org.junit.runners.JUnit4;
  18. @RunWith(JUnit4.class)
  19. public class PostUploadHookChainTest {
  20. @Test
  21. public void testDefaultIfEmpty() {
  22. PostUploadHook[] noHooks = {};
  23. PostUploadHook newChain = PostUploadHookChain
  24. .newChain(Arrays.asList(noHooks));
  25. assertEquals(newChain, PostUploadHook.NULL);
  26. }
  27. @Test
  28. public void testFlattenChainIfOnlyOne() {
  29. FakePostUploadHook hook1 = new FakePostUploadHook();
  30. PostUploadHook newChain = PostUploadHookChain
  31. .newChain(Arrays.asList(PostUploadHook.NULL, hook1));
  32. assertEquals(newChain, hook1);
  33. }
  34. @Test
  35. public void testMultipleHooks() {
  36. FakePostUploadHook hook1 = new FakePostUploadHook();
  37. FakePostUploadHook hook2 = new FakePostUploadHook();
  38. PostUploadHook chained = PostUploadHookChain
  39. .newChain(Arrays.asList(hook1, hook2));
  40. chained.onPostUpload(null);
  41. assertTrue(hook1.wasInvoked());
  42. assertTrue(hook2.wasInvoked());
  43. }
  44. private static final class FakePostUploadHook implements PostUploadHook {
  45. boolean invoked;
  46. public boolean wasInvoked() {
  47. return invoked;
  48. }
  49. @Override
  50. public void onPostUpload(PackStatistics stats) {
  51. invoked = true;
  52. }
  53. }
  54. }