View Javadoc

1   package com.atlassian.marketplace.client.api;
2   
3   import org.junit.Test;
4   
5   import static org.hamcrest.MatcherAssert.assertThat;
6   import static org.hamcrest.Matchers.equalTo;
7   import static org.hamcrest.Matchers.not;
8   import static org.hamcrest.Matchers.sameInstance;
9   
10  public class ApplicationKeyTest
11  {
12      @Test(expected=NullPointerException.class)
13      public void cannotConstructWithNullKey()
14      {
15          ApplicationKey.valueOf(null);
16      }
17      
18      @Test(expected=NullPointerException.class)
19      public void cannotConstructWithEmptyString()
20      {
21          ApplicationKey.valueOf("");
22      }
23      
24      @Test(expected=NullPointerException.class)
25      public void cannotConstructWithWhitespaceString()
26      {
27          ApplicationKey.valueOf(" \t ");
28      }
29      
30      @Test
31      public void keyContainsString()
32      {
33          assertThat(ApplicationKey.valueOf("key").getKey(), equalTo("key"));
34      }
35      
36      @Test
37      public void equivalentKeysAreEqual()
38      {
39          assertThat(ApplicationKey.valueOf("key"), equalTo(ApplicationKey.valueOf("key")));
40      }
41      
42      @Test
43      public void nonEquivalentKeysAreNotEqual()
44      {
45          assertThat(ApplicationKey.valueOf("key"), not(equalTo(ApplicationKey.valueOf("other"))));
46      }
47      
48      @Test
49      public void equivalentKeysHaveSameHashCode()
50      {
51          assertThat(ApplicationKey.valueOf("key").hashCode(), equalTo(ApplicationKey.valueOf("key").hashCode()));
52      }
53      
54      @Test
55      public void predefinedKeyReusesStaticInstanceCaseInsensitively()
56      {
57          assertThat(ApplicationKey.valueOf("Bamboo"), sameInstance(ApplicationKey.BAMBOO));
58      }
59  }