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  import java.util.Map;
32  
33  import org.junit.Assert;
34  import org.junit.Test;
35  
36  import com.aragost.javahg.Changeset;
37  import com.aragost.javahg.Repository;
38  import com.aragost.javahg.internals.Utils;
39  import com.aragost.javahg.test.AbstractTestCase;
40  
41  public class TagsCommandTest extends AbstractTestCase {
42  
43      @Test
44      public void test() throws IOException {
45          Repository repo = getTestRepository();
46          List<Changeset> changesets = createTags(repo);
47  
48          List<Tag> tags = TagsCommand.on(repo).execute();
49  
50          Collections.sort(tags);
51  
52          Assert.assertEquals(4, tags.size());
53          assertTag(changesets.get(0), "a", tags.get(0));
54          assertTag(changesets.get(2), "a , b", tags.get(1));
55          assertTag(changesets.get(1), "a b", tags.get(2));
56          assertTag(changesets.get(0), "b", tags.get(3));
57  
58          Assert.assertFalse(tags.get(0).isLocal());
59          Assert.assertFalse(tags.get(3).isLocal());
60      }
61  
62      private void assertTag(Changeset expectedChangeset, String expectedName, Tag actualTag) {
63          Assert.assertEquals(expectedChangeset, actualTag.getChangeset());
64          Assert.assertEquals(expectedName, actualTag.getName());
65      }
66      
67      private List<Changeset> createTags(Repository repo) throws IOException {
68          TagCommand cmd = TagCommand.on(repo).force().user("test");
69          createChangeset();
70          cmd.execute("a", "b", "a b");
71          cmd.execute(" a b ");
72          cmd.execute(" a , b ");
73          return LogCommand.on(repo).rev("0:tip").execute();
74          // O:tip orders the list so rev n is in position n of the
75          // list
76      }
77  
78      @Test
79      public void testReverse() throws IOException {
80          Repository repo = getTestRepository();
81          List<Changeset> changesets = createTags(repo);
82  
83          Map<Changeset, List<Tag>> map = TagsCommand.on(repo).executeReverse();
84  
85          Assert.assertEquals(3, map.size());
86          List<Tag> tags = map.get(changesets.get(0));
87          Collections.sort(tags);
88          Assert.assertEquals(2, tags.size());
89          Assert.assertEquals("a", tags.get(0).getName());
90          Assert.assertEquals("b", tags.get(1).getName());
91          Assert.assertEquals("a b", Utils.single(map.get(changesets.get(1))).getName());
92          Assert.assertEquals("a , b", Utils.single(map.get(changesets.get(2))).getName());
93      }
94  }