View Javadoc

1   package com.atlassian.plugin.elements;
2   
3   import java.util.Collections;
4   import java.util.HashMap;
5   import java.util.Map;
6   
7   import com.google.common.collect.ImmutableMap;
8   
9   import org.junit.Test;
10  
11  import static org.junit.Assert.assertEquals;
12  import static org.junit.Assert.assertNull;
13  
14  public class ResourceLocationTest
15  {
16      @Test
17      public void paramsAreCopied()
18      {
19          Map<String, String> params = new HashMap<String, String>();
20          params.put("a", "original");
21  
22          ResourceLocation rl = new ResourceLocation("", "", "", "", "", params);
23          params.put("a", "modified");
24  
25          assertEquals("original", rl.getParams().get("a"));
26      }
27  
28      @Test
29      public void paramsAreImmutable()
30      {
31          Map<String, String> params = new HashMap<String, String>();
32          params.put("a", "original");
33  
34          ResourceLocation rl = new ResourceLocation("", "", "", "", "", params);
35  
36          try
37          {
38              rl.getParams().put("a", "modified");
39          }
40          catch (UnsupportedOperationException e)
41          {
42              // Okay
43          }
44  
45          assertEquals("original", rl.getParams().get("a"));
46      }
47  
48      @Test(expected = NullPointerException.class)
49      public void constructionWithNullParamsFails()
50      {
51          new ResourceLocation("", "", "", "", "", null);
52      }
53  
54      @Test
55      public void constructionWithNullValuesSucceeds()
56      {
57          Map<String, String> params = Collections.<String, String>singletonMap("key", null);
58  
59          ResourceLocation rl = new ResourceLocation("", "", "", "", "", params);
60          assertNull(rl.getParameter("key"));
61      }
62  
63      @Test
64      public void constructionWithNullValuesOmitsParam()
65      {
66          Map<String, String> params = Collections.<String, String>singletonMap("key", null);
67  
68          ResourceLocation rl = new ResourceLocation("", "", "", "", "", params);
69          assertEquals(Collections.emptyMap(), rl.getParams());
70      }
71  
72      @Test
73      public void constructionWithMixedValuesIncludesNonNullParam()
74      {
75          Map<String, String> params = new HashMap<String, String>();
76          params.put("null", null);
77          params.put("notnull", "value");
78  
79          ResourceLocation rl = new ResourceLocation("", "", "", "", "", params);
80          assertEquals(ImmutableMap.of("notnull", "value"), rl.getParams());
81      }
82  
83      @Test
84      public void constructionWithNullKeyOmitsParam()
85      {
86          Map<String, String> params = Collections.<String, String>singletonMap(null, "value");
87  
88          ResourceLocation rl = new ResourceLocation("", "", "", "", "", params);
89          assertEquals(Collections.emptyMap(), rl.getParams());
90      }
91  }