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 {
63 q = create();
64 q.add(a);
65 q.add(b);
66
67 assertCommit(a, q.next());
68 assertCommit(b, q.next());
69 assertNull(q.next());
70 }
71 {
72 q = create();
73 q.add(b);
74 q.add(a);
75
76 assertCommit(b, q.next());
77 assertCommit(a, q.next());
78 assertNull(q.next());
79 }
80 }
81
82 @Test
83 public void testCloneFIFO() throws Exception {
84 final RevCommit a = parseBody(commit());
85 final RevCommit b = parseBody(commit(200, a));
86 final RevCommit c = parseBody(commit(200, b));
87
88 final FIFORevQueue src = new FIFORevQueue();
89 src.add(a);
90 src.add(b);
91 src.add(c);
92
93 q = new DateRevQueue(src);
94 assertFalse(q.everbodyHasFlag(RevWalk.UNINTERESTING));
95 assertFalse(q.anybodyHasFlag(RevWalk.UNINTERESTING));
96 assertCommit(c, q.peek());
97 assertCommit(c, q.peek());
98
99 assertCommit(c, q.next());
100 assertCommit(b, q.next());
101 assertCommit(a, q.next());
102 assertNull(q.next());
103 }
104 }