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 package com.aragost.javahg.commands;
27
28 import java.io.IOException;
29 import java.util.List;
30
31 import org.junit.Assert;
32 import org.junit.Assume;
33 import org.junit.Test;
34
35 import com.aragost.javahg.Changeset;
36 import com.aragost.javahg.HgVersion;
37 import com.aragost.javahg.Repository;
38 import com.aragost.javahg.test.AbstractTestCase;
39
40 public class CommitCommandTest extends AbstractTestCase {
41
42 @Test
43 public void test() throws IOException {
44 Repository repo = getTestRepository();
45 writeFile("x", "abc");
46
47 CommitCommand commit = CommitCommand.on(repo);
48 StatusCommand status = StatusCommand.on(repo);
49
50 List<StatusLine> statusLines = status.lines();
51 Assert.assertEquals(1, statusLines.size());
52 Assert.assertEquals(StatusLine.Type.UNKNOWN, statusLines.get(0).getType());
53
54 AddCommand.on(repo).execute();
55 statusLines = status.lines();
56 Assert.assertEquals(1, statusLines.size());
57 Assert.assertEquals(StatusLine.Type.ADDED, statusLines.get(0).getType());
58
59 commit.message("unit test").user("unit test");
60 Changeset cset = commit.execute();
61 Assert.assertEquals("unit test", cset.getUser());
62 statusLines = status.lines();
63 Assert.assertEquals(0, statusLines.size());
64
65 Assert.assertNull(commit.execute());
66
67 }
68
69 @Test(expected = IllegalStateException.class)
70 public void testNoMessage() throws IOException {
71 Repository repo = getTestRepository();
72 CommitCommand.on(repo).execute();
73 }
74
75 @Test(expected = NullPointerException.class)
76 public void testSetNullMessage() throws IOException {
77 Repository repo = getTestRepository();
78 CommitCommand.on(repo).message(null);
79 }
80
81 @Test(expected = NullPointerException.class)
82 public void testSetNullDate() throws IOException {
83 Repository repo = getTestRepository();
84 CommitCommand.on(repo).date(null);
85 }
86
87 @Test
88 public void testAmend() throws IOException {
89 Repository repo = getTestRepository();
90 Assume.assumeTrue(HgVersion.fromString("2.2").isBefore(repo.getHgVersion()));
91
92 writeFile("x", "abc");
93
94 CommitCommand commit = CommitCommand.on(repo);
95 StatusCommand status = StatusCommand.on(repo);
96
97 List<StatusLine> statusLines = status.lines();
98 Assert.assertEquals(1, statusLines.size());
99 Assert.assertEquals(StatusLine.Type.UNKNOWN, statusLines.get(0)
100 .getType());
101
102 AddCommand.on(repo).execute();
103
104 commit.message("unit test").user("unit test");
105 Changeset cset = commit.execute();
106 Assert.assertEquals("unit test", cset.getUser());
107
108 cset = commit.amend().message("unit test amended").execute();
109 Assert.assertEquals("unit test amended", cset.getMessage());
110
111 Assert.assertEquals(1, LogCommand.on(repo).execute().size());
112 }
113 }