1
2
3
4
5
6
7
8
9
10
11
12 package org.eclipse.jgit.revwalk;
13
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import java.io.IOException;
18 import java.util.concurrent.atomic.AtomicBoolean;
19
20 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
21 import org.eclipse.jgit.errors.MissingObjectException;
22 import org.eclipse.jgit.errors.StopWalkException;
23 import org.eclipse.jgit.revwalk.filter.RevFilter;
24 import org.junit.Test;
25
26 public class RevWalkResetTest extends RevWalkTestCase {
27
28 @Test
29 public void testRevFilterReceivesParsedCommits() throws Exception {
30 final RevCommit a = commit();
31 final RevCommit b = commit(a);
32 final RevCommit c = commit(b);
33
34 final AtomicBoolean filterRan = new AtomicBoolean();
35 RevFilter testFilter = new RevFilter() {
36
37 @Override
38 public boolean include(RevWalk walker, RevCommit cmit)
39 throws StopWalkException, MissingObjectException,
40 IncorrectObjectTypeException, IOException {
41 assertNotNull("commit is parsed", cmit.getRawBuffer());
42 filterRan.set(true);
43 return true;
44 }
45
46 @Override
47 public RevFilter clone() {
48 return this;
49 }
50
51 @Override
52 public boolean requiresCommitBody() {
53 return true;
54 }
55 };
56
57
58 filterRan.set(false);
59 rw.setRevFilter(testFilter);
60 markStart(c);
61 rw.markUninteresting(b);
62 for (RevCommit cmit = rw.next(); cmit != null; cmit = rw.next()) {
63
64
65 }
66 assertTrue("filter ran", filterRan.get());
67
68
69 filterRan.set(false);
70 rw.reset();
71 markStart(c);
72 for (RevCommit cmit = rw.next(); cmit != null; cmit = rw.next()) {
73 cmit.disposeBody();
74 }
75 assertTrue("filter ran", filterRan.get());
76
77
78
79 filterRan.set(false);
80 rw.reset();
81 markStart(c);
82 for (RevCommit cmit = rw.next(); cmit != null; cmit = rw.next()) {
83
84 }
85 assertTrue("filter ran", filterRan.get());
86
87 }
88 }