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
44 package org.eclipse.jgit.revwalk;
45
46 import static org.junit.Assert.assertNull;
47 import static org.junit.Assert.assertTrue;
48
49 import org.junit.Test;
50
51 public class RevWalkSortTest extends RevWalkTestCase {
52 @Test
53 public void testSort_Default() throws Exception {
54 final RevCommit a = commit();
55 final RevCommit b = commit(1, a);
56 final RevCommit c = commit(1, b);
57 final RevCommit d = commit(1, c);
58
59 markStart(d);
60 assertCommit(d, rw.next());
61 assertCommit(c, rw.next());
62 assertCommit(b, rw.next());
63 assertCommit(a, rw.next());
64 assertNull(rw.next());
65 }
66
67 @Test
68 public void testSort_COMMIT_TIME_DESC() throws Exception {
69 final RevCommit a = commit();
70 final RevCommit b = commit(a);
71 final RevCommit c = commit(b);
72 final RevCommit d = commit(c);
73
74 rw.sort(RevSort.COMMIT_TIME_DESC);
75 markStart(d);
76 assertCommit(d, rw.next());
77 assertCommit(c, rw.next());
78 assertCommit(b, rw.next());
79 assertCommit(a, rw.next());
80 assertNull(rw.next());
81 }
82
83 @Test
84 public void testSort_REVERSE() throws Exception {
85 final RevCommit a = commit();
86 final RevCommit b = commit(a);
87 final RevCommit c = commit(b);
88 final RevCommit d = commit(c);
89
90 rw.sort(RevSort.REVERSE);
91 markStart(d);
92 assertCommit(a, rw.next());
93 assertCommit(b, rw.next());
94 assertCommit(c, rw.next());
95 assertCommit(d, rw.next());
96 assertNull(rw.next());
97 }
98
99 @Test
100 public void testSort_COMMIT_TIME_DESC_OutOfOrder1() throws Exception {
101
102
103
104 final RevCommit a = commit();
105 final RevCommit b = commit(a);
106 final RevCommit c = commit(-5, b);
107 final RevCommit d = commit(10, c);
108 assertTrue(parseBody(a).getCommitTime() < parseBody(d).getCommitTime());
109 assertTrue(parseBody(c).getCommitTime() < parseBody(b).getCommitTime());
110
111 rw.sort(RevSort.COMMIT_TIME_DESC);
112 markStart(d);
113 assertCommit(d, rw.next());
114 assertCommit(c, rw.next());
115 assertCommit(b, rw.next());
116 assertCommit(a, rw.next());
117 assertNull(rw.next());
118 }
119
120 @Test
121 public void testSort_COMMIT_TIME_DESC_OutOfOrder2() throws Exception {
122
123
124 final RevCommit a = commit();
125 final RevCommit b = commit(a);
126 final RevCommit c1 = commit(-5, b);
127 final RevCommit c2 = commit(10, b);
128 final RevCommit d = commit(c1, c2);
129
130 rw.sort(RevSort.COMMIT_TIME_DESC);
131 markStart(d);
132 assertCommit(d, rw.next());
133 assertCommit(c2, rw.next());
134 assertCommit(b, rw.next());
135 assertCommit(a, rw.next());
136 assertCommit(c1, rw.next());
137 assertNull(rw.next());
138 }
139
140 @Test
141 public void testSort_TOPO() throws Exception {
142
143
144 final RevCommit a = commit();
145 final RevCommit b = commit(a);
146 final RevCommit c1 = commit(-5, b);
147 final RevCommit c2 = commit(10, b);
148 final RevCommit d = commit(c1, c2);
149
150 rw.sort(RevSort.TOPO);
151 markStart(d);
152 assertCommit(d, rw.next());
153 assertCommit(c2, rw.next());
154 assertCommit(c1, rw.next());
155 assertCommit(b, rw.next());
156 assertCommit(a, rw.next());
157 assertNull(rw.next());
158 }
159
160 @Test
161 public void testSort_TOPO_REVERSE() throws Exception {
162
163
164 final RevCommit a = commit();
165 final RevCommit b = commit(a);
166 final RevCommit c1 = commit(-5, b);
167 final RevCommit c2 = commit(10, b);
168 final RevCommit d = commit(c1, c2);
169
170 rw.sort(RevSort.TOPO);
171 rw.sort(RevSort.REVERSE, true);
172 markStart(d);
173 assertCommit(a, rw.next());
174 assertCommit(b, rw.next());
175 assertCommit(c1, rw.next());
176 assertCommit(c2, rw.next());
177 assertCommit(d, rw.next());
178 assertNull(rw.next());
179 }
180 }