View Javadoc

1   /*
2    * #%L
3    * JavaHg parent POM
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.Collections;
30  import java.util.List;
31  
32  import org.junit.Assert;
33  import org.junit.Test;
34  
35  import com.aragost.javahg.Changeset;
36  import com.aragost.javahg.Repository;
37  import com.aragost.javahg.test.AbstractTestCase;
38  
39  public class BranchesTest extends AbstractTestCase {
40  
41      @Test
42      public void testBranches() throws IOException {
43          Repository repo = getTestRepository();
44          writeFile("default");
45          Changeset defaultBranch = commit();
46          BranchCommand.on(repo).set(" branch A ");
47          commit();
48          update(defaultBranch);
49          BranchCommand.on(repo).set(" branch B ");
50          Changeset branchB = commit(); // B is inactive
51          BranchCommand.on(repo).force().set(" branch A ");
52          Changeset branchATip = commit();
53          BranchCommand.on(repo).set("branch C");
54          commit();
55          Changeset branchC = CommitCommand.on(repo).message("test").user("user").closeBranch().execute();
56  
57          List<Branch> branches = BranchesCommand.on(repo).closed().execute();
58          Collections.sort(branches);
59  
60          Assert.assertEquals(4, branches.size());
61  
62          Branch bA = branches.get(0);
63          Branch bB = branches.get(1);
64          Branch bC = branches.get(2);
65          Branch bDefault = branches.get(3);
66  
67          Assert.assertEquals("branch A", bA.getName());
68          Assert.assertEquals(branchATip, bA.getBranchTip());
69          Assert.assertFalse(bA.isClosed());
70  
71          Assert.assertEquals("branch B", bB.getName());
72          Assert.assertEquals(branchB, bB.getBranchTip());
73          Assert.assertFalse(bB.isClosed());
74  
75          Assert.assertEquals("branch C", bC.getName());
76          Assert.assertEquals(branchC, bC.getBranchTip());
77          Assert.assertTrue(bC.isClosed());
78  
79          Assert.assertEquals("default", bDefault.getName());
80          Assert.assertEquals(defaultBranch, bDefault.getBranchTip());
81          Assert.assertFalse(bDefault.isClosed());
82      }
83  
84      @Test
85      public void testCloseBranch() throws IOException {
86          Repository repo = getTestRepository();
87          BranchCommand.on(repo).set(" x");
88          commit();
89          CommitCommand.on(repo).message("test").user("user").closeBranch().execute();
90  
91          List<Branch> branches = BranchesCommand.on(repo).closed().execute();
92          Assert.assertEquals(1, branches.size());
93      }
94  
95  }