View Javadoc

1   /*
2    * Created by IntelliJ IDEA.
3    * User: Mike
4    * Date: Jul 29, 2004
5    * Time: 3:28:26 PM
6    */
7   package com.atlassian.plugin;
8   
9   import org.junit.Test;
10  
11  import java.util.HashMap;
12  import java.util.Map;
13  
14  import static org.junit.Assert.assertEquals;
15  import static org.junit.Assert.assertFalse;
16  import static org.junit.Assert.assertTrue;
17  
18  public class TestModuleCompleteKey
19  {
20      @Test
21      public void spacesAreStrippedFromKeys()
22      {
23          String pluginKey = "    com.acme  ";
24          String moduleKey = "   tools  ";
25  
26          ModuleCompleteKey moduleCompleteKey = new ModuleCompleteKey(pluginKey, moduleKey);
27  
28          assertEquals(pluginKey.trim(), moduleCompleteKey.getPluginKey());
29          assertEquals(moduleKey.trim(), moduleCompleteKey.getModuleKey());
30      }
31  
32      @Test
33      public void spacesAreStrippedFromKeys2()
34      {
35          String moduleCompleteKeyString = "    com.acme  :         tools       ";
36  
37          ModuleCompleteKey moduleCompleteKey = new ModuleCompleteKey(moduleCompleteKeyString);
38  
39          assertEquals("com.acme", moduleCompleteKey.getPluginKey());
40          assertEquals("tools", moduleCompleteKey.getModuleKey());
41      }
42  
43      @Test
44      public void pluginKeyAndModuleKeyConstructor()
45      {
46          String pluginKey = "com.acme";
47          String moduleKey = "tools";
48  
49          ModuleCompleteKey moduleCompleteKey = new ModuleCompleteKey(pluginKey, moduleKey);
50  
51          assertEquals(pluginKey, moduleCompleteKey.getPluginKey());
52          assertEquals(moduleKey, moduleCompleteKey.getModuleKey());
53      }
54  
55      @Test
56      public void moduleCompleteKeyCanBeUsedAsMapKey()
57      {
58          Map<ModuleCompleteKey, String> map = new HashMap<ModuleCompleteKey, String>();
59          String expected = "bananas";
60  
61          map.put(new ModuleCompleteKey("foo", "bar"), expected);
62  
63          assertEquals(expected, map.get(new ModuleCompleteKey("foo", "bar")));
64      }
65  
66      @Test
67      public void equals()
68      {
69          assertTrue(new ModuleCompleteKey("foo", "bar").equals(new ModuleCompleteKey("foo", "bar")));
70          assertFalse(new ModuleCompleteKey("foo", "bar").equals(new ModuleCompleteKey("foo", "baz")));
71          assertFalse(new ModuleCompleteKey("fon", "bar").equals(new ModuleCompleteKey("foo", "baz")));
72      }
73  
74      @Test
75      public void testToString()
76      {
77          ModuleCompleteKey moduleCompleteKey = new ModuleCompleteKey("foo", "bar");
78  
79          assertEquals(moduleCompleteKey.getCompleteKey(), moduleCompleteKey.toString());
80      }
81  
82      @Test
83      public void workingKey()
84      {
85          ModuleCompleteKey key = new ModuleCompleteKey("foo:bar");
86  
87          assertEquals("foo", key.getPluginKey());
88          assertEquals("bar", key.getModuleKey());
89          assertEquals("foo:bar", key.getCompleteKey());
90      }
91  
92      @Test(expected = IllegalArgumentException.class)
93      public void colonInPluginKey()
94      {
95          new ModuleCompleteKey("foo:", "bar");
96      }
97  
98      @Test(expected = IllegalArgumentException.class)
99      public void colonInModuleKey()
100     {
101         new ModuleCompleteKey("foo", ":bar");
102     }
103 
104     @Test(expected = IllegalArgumentException.class)
105     public void badKey1()
106     {
107         new ModuleCompleteKey("foo");
108     }
109 
110     @Test(expected = IllegalArgumentException.class)
111     public void badKey2()
112     {
113         new ModuleCompleteKey("foo:");
114     }
115 
116     @Test(expected = IllegalArgumentException.class)
117     public void badKey3()
118     {
119         new ModuleCompleteKey(":foo");
120     }
121 
122     @Test(expected = IllegalArgumentException.class)
123     public void badKey4()
124     {
125         new ModuleCompleteKey("");
126     }
127 
128     @Test(expected = IllegalArgumentException.class)
129     public void badKey5()
130     {
131         new ModuleCompleteKey(null);
132     }
133 
134     @Test(expected = IllegalArgumentException.class)
135     public void nullPluginKey()
136     {
137         new ModuleCompleteKey(null, "foo");
138     }
139 
140     @Test(expected = IllegalArgumentException.class)
141     public void nullModuleKey()
142     {
143         new ModuleCompleteKey("foo", null);
144     }
145 
146     @Test(expected = IllegalArgumentException.class)
147     public void nullPluginKeyAndNullModuleKey()
148     {
149         new ModuleCompleteKey(null, null);
150     }
151 
152     @Test(expected = IllegalArgumentException.class)
153     public void emptyPluginKey() throws Exception
154     {
155         new ModuleCompleteKey("", "foo");
156     }
157 
158     @Test(expected = IllegalArgumentException.class)
159     public void emptyModuleKey() throws Exception
160     {
161         new ModuleCompleteKey("foo", "");
162     }
163 
164     @Test(expected = IllegalArgumentException.class)
165     public void emptyPluginKeyAndEmptyModuleKey() throws Exception
166     {
167         new ModuleCompleteKey("", "");
168     }
169 
170     @Test(expected = IllegalArgumentException.class)
171     public void pluginKeyOfSpaces() throws Exception
172     {
173         new ModuleCompleteKey("      ", "foo");
174     }
175 
176     @Test(expected = IllegalArgumentException.class)
177     public void moduleKeyOfSpaces() throws Exception
178     {
179         new ModuleCompleteKey("foo", "      ");
180     }
181 
182     @Test(expected = IllegalArgumentException.class)
183     public void pluginKeyAndModuleKeyOfSpaces() throws Exception
184     {
185         new ModuleCompleteKey("       ", "      ");
186     }
187 
188 }