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.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();
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 }