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 import static org.junit.Assert.assertFalse;
15 import static org.junit.Assert.assertNull;
16
17 import org.junit.Test;
18
19 public class DateRevQueueTest extends RevQueueTestCase<DateRevQueue> {
20 @Override
21 protected DateRevQueue create() {
22 return new DateRevQueue();
23 }
24
25 @Override
26 @Test
27 public void testEmpty() throws Exception {
28 super.testEmpty();
29 assertNull(q.peek());
30 assertEquals(Generator.SORT_COMMIT_TIME_DESC, q.outputType());
31 }
32
33 @Test
34 public void testCloneEmpty() throws Exception {
35 q = new DateRevQueue(AbstractRevQueue.EMPTY_QUEUE);
36 assertNull(q.next());
37 }
38
39 @Test
40 public void testInsertOutOfOrder() throws Exception {
41 final RevCommit a = parseBody(commit());
42 final RevCommit b = parseBody(commit(10, a));
43 final RevCommit c1 = parseBody(commit(5, b));
44 final RevCommit c2 = parseBody(commit(-50, b));
45
46 q.add(c2);
47 q.add(a);
48 q.add(b);
49 q.add(c1);
50
51 assertCommit(c1, q.next());
52 assertCommit(b, q.next());
53 assertCommit(a, q.next());
54 assertCommit(c2, q.next());
55 assertNull(q.next());
56 }
57
58 @Test
59 public void testInsertTie() throws Exception {
60 final RevCommit a = parseBody(commit());
61 final RevCommit b = parseBody(commit(0, a));
62 final RevCommit c = parseBody(commit(0, b));
63
64 {
65 q = create();
66 q.add(a);
67 q.add(b);
68 q.add(c);
69
70 assertCommit(a, q.next());
71 assertCommit(b, q.next());
72 assertCommit(c, q.next());
73 assertNull(q.next());
74 }
75 {
76 q = create();
77 q.add(c);
78 q.add(b);
79 q.add(a);
80
81 assertCommit(c, q.next());
82 assertCommit(b, q.next());
83 assertCommit(a, q.next());
84 assertNull(q.next());
85 }
86 }
87
88 @Test
89 public void testCloneFIFO() throws Exception {
90 final RevCommit a = parseBody(commit());
91 final RevCommit b = parseBody(commit(200, a));
92 final RevCommit c = parseBody(commit(200, b));
93
94 final FIFORevQueue src = new FIFORevQueue();
95 src.add(a);
96 src.add(b);
97 src.add(c);
98
99 q = new DateRevQueue(src);
100 assertFalse(q.everbodyHasFlag(RevWalk.UNINTERESTING));
101 assertFalse(q.anybodyHasFlag(RevWalk.UNINTERESTING));
102 assertCommit(c, q.peek());
103 assertCommit(c, q.peek());
104
105 assertCommit(c, q.next());
106 assertCommit(b, q.next());
107 assertCommit(a, q.next());
108 assertNull(q.next());
109 }
110 }