1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 package org.eclipse.jgit.revwalk;
44
45 import static org.junit.Assert.assertEquals;
46 import static org.junit.Assert.assertNotNull;
47 import static org.junit.Assert.assertNull;
48
49 import org.eclipse.jgit.api.Git;
50 import org.eclipse.jgit.junit.RepositoryTestCase;
51 import org.eclipse.jgit.lib.Constants;
52 import org.eclipse.jgit.lib.ObjectId;
53 import org.junit.Test;
54
55 public class RevCommitListTest extends RepositoryTestCase {
56
57 private RevCommitList<RevCommit> list;
58
59 public void setup(int count) throws Exception {
60 try (Git git = new Git(db);
61 RevWalk w = new RevWalk(db);) {
62 for (int i = 0; i < count; i++)
63 git.commit().setCommitter(committer).setAuthor(author)
64 .setMessage("commit " + i).call();
65 list = new RevCommitList<>();
66 w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
67 list.source(w);
68 }
69 }
70
71 @Test
72 public void testFillToHighMark2() throws Exception {
73 setup(3);
74 list.fillTo(1);
75 assertEquals(2, list.size());
76 assertEquals("commit 2", list.get(0).getFullMessage());
77 assertEquals("commit 1", list.get(1).getFullMessage());
78 assertNull("commit 0 shouldn't be loaded", list.get(2));
79 }
80
81 @Test
82 public void testFillToHighMarkAll() throws Exception {
83 setup(3);
84 list.fillTo(2);
85 assertEquals(3, list.size());
86 assertEquals("commit 2", list.get(0).getFullMessage());
87 assertEquals("commit 0", list.get(2).getFullMessage());
88 }
89
90 @Test
91 public void testFillToHighMark4() throws Exception {
92 setup(3);
93 list.fillTo(3);
94 assertEquals(3, list.size());
95 assertEquals("commit 2", list.get(0).getFullMessage());
96 assertEquals("commit 0", list.get(2).getFullMessage());
97 assertNull("commit 3 can't be loaded", list.get(3));
98 }
99
100 @Test
101 public void testFillToHighMarkMulitpleBlocks() throws Exception {
102 setup(258);
103 list.fillTo(257);
104 assertEquals(258, list.size());
105 }
106
107 @Test
108 public void testFillToCommit() throws Exception {
109 setup(3);
110
111 try (RevWalk w = new RevWalk(db)) {
112 w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
113
114 w.next();
115 RevCommit c = w.next();
116 assertNotNull("should have found 2. commit", c);
117
118 list.fillTo(c, 5);
119 assertEquals(2, list.size());
120 assertEquals("commit 1", list.get(1).getFullMessage());
121 assertNull(list.get(3));
122 }
123 }
124
125 @Test
126 public void testFillToUnknownCommit() throws Exception {
127 setup(258);
128 RevCommit c = new RevCommit(
129 ObjectId.fromString("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
130
131 list.fillTo(c, 300);
132 assertEquals("loading to unknown commit should load all commits", 258,
133 list.size());
134 }
135
136 @Test
137 public void testFillToNullCommit() throws Exception {
138 setup(3);
139 list.fillTo(null, 1);
140 assertNull(list.get(0));
141 }
142 }