1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.revwalk;
12
13 import static org.junit.Assert.assertEquals;
14
15 import org.junit.Test;
16
17 public class RevWalkUtilsCountTest extends RevWalkTestCase {
18
19 @Test
20 public void shouldWorkForNormalCase() throws Exception {
21 final RevCommit a = commit();
22 final RevCommit b = commit(a);
23
24 assertEquals(1, count(b, a));
25 }
26
27 @Test
28 public void shouldReturnZeroOnSameCommit() throws Exception {
29 final RevCommit c1 = commit(commit(commit()));
30 assertEquals(0, count(c1, c1));
31 }
32
33 @Test
34 public void shouldReturnZeroWhenMergedInto() throws Exception {
35 final RevCommit a = commit();
36 final RevCommit b = commit(a);
37
38 assertEquals(0, count(a, b));
39 }
40
41 @Test
42 public void shouldWorkWithMerges() throws Exception {
43 final RevCommit a = commit();
44 final RevCommit b1 = commit(a);
45 final RevCommit b2 = commit(a);
46 final RevCommit c = commit(b1, b2);
47
48 assertEquals(3, count(c, a));
49 }
50
51 @Test
52 public void shouldWorkWithoutCommonAncestor() throws Exception {
53 final RevCommit a1 = commit();
54 final RevCommit a2 = commit();
55 final RevCommit b = commit(a1);
56
57 assertEquals(2, count(b, a2));
58 }
59
60 @Test
61 public void shouldWorkWithZeroAsEnd() throws Exception {
62 final RevCommit c = commit(commit());
63
64 assertEquals(2, count(c, null));
65 }
66
67 private int count(RevCommit start, RevCommit end) throws Exception {
68 return RevWalkUtils.count(rw, start, end);
69 }
70 }