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  
21      @Test
22      public void spacesAreStrippedFromKeys()
23      {
24          String pluginKey = "    com.acme  ";
25          String moduleKey = "   tools  ";
26  
27          ModuleCompleteKey moduleCompleteKey = new ModuleCompleteKey(pluginKey, moduleKey);
28  
29          assertEquals(pluginKey.trim(), moduleCompleteKey.getPluginKey());
30          assertEquals(moduleKey.trim(), moduleCompleteKey.getModuleKey());
31      }
32  
33      @Test
34      public void spacesAreStrippedFromKeys2()
35      {
36          String moduleCompleteKeyString = "    com.acme  :         tools       ";
37  
38          ModuleCompleteKey moduleCompleteKey = new ModuleCompleteKey(moduleCompleteKeyString);
39  
40          assertEquals("com.acme", moduleCompleteKey.getPluginKey());
41          assertEquals("tools", moduleCompleteKey.getModuleKey());
42      }
43  
44      @Test
45      public void pluginKeyAndModuleKeyConstructor()
46      {
47          String pluginKey = "com.acme";
48          String moduleKey = "tools";
49  
50          ModuleCompleteKey moduleCompleteKey = new ModuleCompleteKey(pluginKey, moduleKey);
51  
52          assertEquals(pluginKey, moduleCompleteKey.getPluginKey());
53          assertEquals(moduleKey, moduleCompleteKey.getModuleKey());
54      }
55  
56      @Test
57      public void moduleCompleteKeyCanBeUsedAsMapKey()
58      {
59          Map<ModuleCompleteKey, String> map = new HashMap<ModuleCompleteKey, String>();
60          String expected = "bananas";
61  
62          map.put(new ModuleCompleteKey("foo", "bar"), expected);
63  
64          assertEquals(expected, map.get(new ModuleCompleteKey("foo", "bar")));
65      }
66  
67      @Test
68      public void equals()
69      {
70          assertTrue(new ModuleCompleteKey("foo", "bar").equals(new ModuleCompleteKey("foo", "bar")));
71          assertFalse(new ModuleCompleteKey("foo", "bar").equals(new ModuleCompleteKey("foo", "baz")));
72          assertFalse(new ModuleCompleteKey("fon", "bar").equals(new ModuleCompleteKey("foo", "baz")));
73      }
74  
75      @Test
76      public void testToString()
77      {
78          ModuleCompleteKey moduleCompleteKey = new ModuleCompleteKey("foo", "bar");
79  
80          assertEquals(moduleCompleteKey.getCompleteKey(), moduleCompleteKey.toString());
81      }
82  
83      @Test
84      public void workingKey()
85      {
86          ModuleCompleteKey key = new ModuleCompleteKey("foo:bar");
87  
88          assertEquals("foo", key.getPluginKey());
89          assertEquals("bar", key.getModuleKey());
90          assertEquals("foo:bar", key.getCompleteKey());
91      }
92  
93      @Test(expected = IllegalArgumentException.class)
94      public void colonInPluginKey()
95      {
96          new ModuleCompleteKey("foo:", "bar");
97      }
98  
99      @Test
100     public void colonInModuleKeyDoesNotThrowException()
101     {
102         final ModuleCompleteKey completeKey = new ModuleCompleteKey("foo", ":bar");
103         assertEquals("foo", completeKey.getPluginKey());
104         assertEquals(":bar", completeKey.getModuleKey());
105     }
106 
107     @Test(expected = IllegalArgumentException.class)
108     public void badKey1()
109     {
110         new ModuleCompleteKey("foo");
111     }
112 
113     @Test(expected = IllegalArgumentException.class)
114     public void badKey2()
115     {
116         new ModuleCompleteKey("foo:");
117     }
118 
119     @Test(expected = IllegalArgumentException.class)
120     public void badKey3()
121     {
122         new ModuleCompleteKey(":foo");
123     }
124 
125     @Test(expected = IllegalArgumentException.class)
126     public void badKey4()
127     {
128         new ModuleCompleteKey("");
129     }
130 
131     @Test(expected = IllegalArgumentException.class)
132     public void badKey5()
133     {
134         new ModuleCompleteKey(null);
135     }
136 
137     @Test(expected = IllegalArgumentException.class)
138     public void nullPluginKey()
139     {
140         new ModuleCompleteKey(null, "foo");
141     }
142 
143     @Test(expected = IllegalArgumentException.class)
144     public void nullModuleKey()
145     {
146         new ModuleCompleteKey("foo", null);
147     }
148 
149     @Test(expected = IllegalArgumentException.class)
150     public void nullPluginKeyAndNullModuleKey()
151     {
152         new ModuleCompleteKey(null, null);
153     }
154 
155     @Test(expected = IllegalArgumentException.class)
156     public void emptyPluginKey() throws Exception
157     {
158         new ModuleCompleteKey("", "foo");
159     }
160 
161     @Test(expected = IllegalArgumentException.class)
162     public void emptyModuleKey() throws Exception
163     {
164         new ModuleCompleteKey("foo", "");
165     }
166 
167     @Test(expected = IllegalArgumentException.class)
168     public void emptyPluginKeyAndEmptyModuleKey() throws Exception
169     {
170         new ModuleCompleteKey("", "");
171     }
172 
173     @Test(expected = IllegalArgumentException.class)
174     public void pluginKeyOfSpaces() throws Exception
175     {
176         new ModuleCompleteKey("      ", "foo");
177     }
178 
179     @Test(expected = IllegalArgumentException.class)
180     public void moduleKeyOfSpaces() throws Exception
181     {
182         new ModuleCompleteKey("foo", "      ");
183     }
184 
185     @Test(expected = IllegalArgumentException.class)
186     public void pluginKeyAndModuleKeyOfSpaces() throws Exception
187     {
188         new ModuleCompleteKey("       ", "      ");
189     }
190 
191     @Test
192     public void pluginModuleKeyCanHaveAColonPresent()
193     {
194         String pluginKey = "com.acme";
195         String moduleKey = "tools:foo";
196         String completeKey = "com.acme:tools:foo";
197 
198         ModuleCompleteKey moduleCompleteKey = new ModuleCompleteKey(completeKey);
199 
200         assertEquals(pluginKey, moduleCompleteKey.getPluginKey());
201         assertEquals(moduleKey, moduleCompleteKey.getModuleKey());
202     }
203 
204 
205 }