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.

RevWalkUtilsCountTest.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2011, Robin Stocker <robin@nibor.org> 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.revwalk;
  11. import static org.junit.Assert.assertEquals;
  12. import org.junit.Test;
  13. public class RevWalkUtilsCountTest extends RevWalkTestCase {
  14. @Test
  15. public void shouldWorkForNormalCase() throws Exception {
  16. final RevCommit a = commit();
  17. final RevCommit b = commit(a);
  18. assertEquals(1, count(b, a));
  19. }
  20. @Test
  21. public void shouldReturnZeroOnSameCommit() throws Exception {
  22. final RevCommit c1 = commit(commit(commit()));
  23. assertEquals(0, count(c1, c1));
  24. }
  25. @Test
  26. public void shouldReturnZeroWhenMergedInto() throws Exception {
  27. final RevCommit a = commit();
  28. final RevCommit b = commit(a);
  29. assertEquals(0, count(a, b));
  30. }
  31. @Test
  32. public void shouldWorkWithMerges() throws Exception {
  33. final RevCommit a = commit();
  34. final RevCommit b1 = commit(a);
  35. final RevCommit b2 = commit(a);
  36. final RevCommit c = commit(b1, b2);
  37. assertEquals(3, count(c, a));
  38. }
  39. @Test
  40. public void shouldWorkWithoutCommonAncestor() throws Exception {
  41. final RevCommit a1 = commit();
  42. final RevCommit a2 = commit();
  43. final RevCommit b = commit(a1);
  44. assertEquals(2, count(b, a2));
  45. }
  46. @Test
  47. public void shouldWorkWithZeroAsEnd() throws Exception {
  48. final RevCommit c = commit(commit());
  49. assertEquals(2, count(c, null));
  50. }
  51. private int count(RevCommit start, RevCommit end) throws Exception {
  52. return RevWalkUtils.count(rw, start, end);
  53. }
  54. }