View Javadoc

1   /*
2    * #%L
3    * JavaHg
4    * %%
5    * Copyright (C) 2011 aragost Trifork ag
6    * %%
7    * Permission is hereby granted, free of charge, to any person obtaining a copy
8    * of this software and associated documentation files (the "Software"), to deal
9    * in the Software without restriction, including without limitation the rights
10   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11   * copies of the Software, and to permit persons to whom the Software is
12   * furnished to do so, subject to the following conditions:
13   * 
14   * The above copyright notice and this permission notice shall be included in
15   * all copies or substantial portions of the Software.
16   * 
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23   * THE SOFTWARE.
24   * #L%
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 }