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 Git git = new Git(db);
61 for (int i = 0; i < count; i++)
62 git.commit().setCommitter(committer).setAuthor(author)
63 .setMessage("commit " + i).call();
64 list = new RevCommitList<RevCommit>();
65 RevWalk w = new RevWalk(db);
66 w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
67 list.source(w);
68 }
69
70 @Test
71 public void testFillToHighMark2() throws Exception {
72 setup(3);
73 list.fillTo(1);
74 assertEquals(2, list.size());
75 assertEquals("commit 2", list.get(0).getFullMessage());
76 assertEquals("commit 1", list.get(1).getFullMessage());
77 assertNull("commit 0 shouldn't be loaded", list.get(2));
78 }
79
80 @Test
81 public void testFillToHighMarkAll() throws Exception {
82 setup(3);
83 list.fillTo(2);
84 assertEquals(3, list.size());
85 assertEquals("commit 2", list.get(0).getFullMessage());
86 assertEquals("commit 0", list.get(2).getFullMessage());
87 }
88
89 @Test
90 public void testFillToHighMark4() throws Exception {
91 setup(3);
92 list.fillTo(3);
93 assertEquals(3, list.size());
94 assertEquals("commit 2", list.get(0).getFullMessage());
95 assertEquals("commit 0", list.get(2).getFullMessage());
96 assertNull("commit 3 can't be loaded", list.get(3));
97 }
98
99 @Test
100 public void testFillToHighMarkMulitpleBlocks() throws Exception {
101 setup(258);
102 list.fillTo(257);
103 assertEquals(258, list.size());
104 }
105
106 @Test
107 public void testFillToCommit() throws Exception {
108 setup(3);
109
110 RevWalk w = new RevWalk(db);
111 w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
112
113 w.next();
114 RevCommit c = w.next();
115 assertNotNull("should have found 2. commit", c);
116
117 list.fillTo(c, 5);
118 assertEquals(2, list.size());
119 assertEquals("commit 1", list.get(1).getFullMessage());
120 assertNull(list.get(3));
121 }
122
123 @Test
124 public void testFillToUnknownCommit() throws Exception {
125 setup(258);
126 RevCommit c = new RevCommit(
127 ObjectId.fromString("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
128
129 list.fillTo(c, 300);
130 assertEquals("loading to unknown commit should load all commits", 258,
131 list.size());
132 }
133
134 @Test
135 public void testFillToNullCommit() throws Exception {
136 setup(3);
137 list.fillTo(null, 1);
138 assertNull(list.get(0));
139 }
140 }