1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.lib;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.fail;
15
16 import java.io.IOException;
17 import java.nio.file.Files;
18 import java.nio.file.Path;
19 import java.nio.file.Paths;
20 import java.util.Arrays;
21 import java.util.List;
22
23 import org.eclipse.jgit.junit.RepositoryTestCase;
24 import org.junit.Test;
25
26 public class RebaseTodoFileTest extends RepositoryTestCase {
27
28 private static final String TEST_TODO = "test.todo";
29
30 private void createTodoList(String... lines) throws IOException {
31 Path p = Paths.get(db.getDirectory().getAbsolutePath(), TEST_TODO);
32 Files.write(p, Arrays.asList(lines));
33 }
34
35 @Test
36 public void testReadTodoFile() throws Exception {
37 String[] expected = { "reword " + ObjectId.zeroId().name() + " Foo",
38 "# A comment in the todo list",
39 "pick " + ObjectId.zeroId().name() + " Foo fie",
40 "squash " + ObjectId.zeroId().name() + " F",
41 "fixup " + ObjectId.zeroId().name(),
42 "edit " + ObjectId.zeroId().name() + " f",
43 "edit " + ObjectId.zeroId().name() + ' ' };
44 createTodoList(expected);
45 RebaseTodoFile todo = new RebaseTodoFile(db);
46 List<RebaseTodoLine> lines = todo.readRebaseTodo(TEST_TODO, true);
47 assertEquals("Expected 7 lines", 7, lines.size());
48 int i = 0;
49 for (RebaseTodoLine line : lines) {
50 switch (i) {
51 case 0:
52 assertEquals("Expected REWORD", RebaseTodoLine.Action.REWORD,
53 line.getAction());
54 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
55 line.getCommit());
56 assertEquals("Unexpected Message", "Foo",
57 line.getShortMessage());
58 break;
59 case 1:
60 assertEquals("Expected COMMENT", RebaseTodoLine.Action.COMMENT,
61 line.getAction());
62 assertEquals("Unexpected Message",
63 "# A comment in the todo list",
64 line.getComment());
65 break;
66 case 2:
67 assertEquals("Expected PICK", RebaseTodoLine.Action.PICK,
68 line.getAction());
69 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
70 line.getCommit());
71 assertEquals("Unexpected Message", "Foo fie",
72 line.getShortMessage());
73 break;
74 case 3:
75 assertEquals("Expected SQUASH", RebaseTodoLine.Action.SQUASH,
76 line.getAction());
77 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
78 line.getCommit());
79 assertEquals("Unexpected Message", "F", line.getShortMessage());
80 break;
81 case 4:
82 assertEquals("Expected FIXUP", RebaseTodoLine.Action.FIXUP,
83 line.getAction());
84 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
85 line.getCommit());
86 assertEquals("Unexpected Message", "", line.getShortMessage());
87 break;
88 case 5:
89 assertEquals("Expected EDIT", RebaseTodoLine.Action.EDIT,
90 line.getAction());
91 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
92 line.getCommit());
93 assertEquals("Unexpected Message", "f", line.getShortMessage());
94 break;
95 case 6:
96 assertEquals("Expected EDIT", RebaseTodoLine.Action.EDIT,
97 line.getAction());
98 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
99 line.getCommit());
100 assertEquals("Unexpected Message", "", line.getShortMessage());
101 break;
102 default:
103 fail("Too many lines");
104 return;
105 }
106 i++;
107 }
108 }
109 }