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.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 }