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.Test;
33
34 import com.aragost.javahg.Bookmark;
35 import com.aragost.javahg.Changeset;
36 import com.aragost.javahg.Repository;
37 import com.aragost.javahg.internals.Utils;
38 import com.aragost.javahg.test.AbstractTestCase;
39
40 public class BookmarksCommandTest extends AbstractTestCase {
41
42 @Test
43 public void testNoBookmarks() {
44 Repository repo = getTestRepository();
45 Assert.assertTrue(BookmarksCommand.on(repo).list().isEmpty());
46 }
47
48 @Test
49 public void testDelete() throws IOException {
50 Repository repo = getTestRepository();
51 createChangeset();
52 BookmarksCommand.on(repo).create("a");
53 Assert.assertEquals(1, BookmarksCommand.on(repo).list().size());
54 BookmarksCommand.on(repo).delete("a");
55 Assert.assertEquals(0, BookmarksCommand.on(repo).list().size());
56 }
57
58 @Test
59 public void testRename() throws IOException {
60 Repository repo = getTestRepository();
61 createChangeset();
62 BookmarksCommand.on(repo).create("a");
63 Assert.assertEquals(1, BookmarksCommand.on(repo).list().size());
64 BookmarksCommand.on(repo).rename("a", "b");
65 List<Bookmark> list = BookmarksCommand.on(repo).list();
66 Assert.assertEquals(1, list.size());
67 Bookmark bm = list.get(0);
68 Assert.assertEquals("b", bm.getName());
69 Assert.assertTrue("b", bm.isActive());
70 }
71
72 @Test
73 public void testActive() throws IOException {
74 Repository repo = getTestRepository();
75 createChangeset();
76 BookmarksCommand.on(repo).create("a");
77 Bookmark bm = Utils.single(BookmarksCommand.on(repo).list());
78 Assert.assertTrue(bm.isActive());
79
80 Changeset cs2 = createChangeset();
81 bm = Utils.single(BookmarksCommand.on(repo).list());
82 Assert.assertSame(cs2, bm.getChangeset());
83 Assert.assertTrue(bm.isActive());
84 }
85
86 @Test
87 public void test() throws IOException {
88 Repository repo = getTestRepository();
89
90 Assert.assertTrue(BookmarksCommand.on(repo).list().isEmpty());
91
92 BookmarksCommand.on(repo).inactive().create("null");
93 createChangeset();
94 BookmarksCommand.on(repo).create("a");
95 Changeset cs = createChangeset();
96
97 List<Bookmark> list = BookmarksCommand.on(repo).list();
98 Assert.assertEquals(2, list.size());
99 Bookmark bm = list.get(0);
100 Assert.assertEquals("a", bm.getName());
101 Assert.assertEquals(cs, bm.getChangeset());
102 Assert.assertTrue(bm.isActive());
103 bm = list.get(1);
104 Assert.assertEquals("null", bm.getName());
105 Assert.assertNull(bm.getChangeset());
106 Assert.assertFalse(bm.isActive());
107 }
108
109 }