View Javadoc
1   package com.atlassian.sal.api.features;
2   
3   import org.junit.Test;
4   
5   import static org.hamcrest.Matchers.is;
6   import static org.junit.Assert.assertFalse;
7   import static org.junit.Assert.assertThat;
8   import static org.junit.Assert.assertTrue;
9   
10  public class TestValidFeatureKeyPredicate {
11      @Test
12      public void invalidNullKey() throws Exception {
13          assertFalse(ValidFeatureKeyPredicate.isValidFeatureKey(null));
14      }
15  
16      @Test
17      public void invalidEmptyString() throws Exception {
18          assertFalse(ValidFeatureKeyPredicate.isValidFeatureKey(""));
19      }
20  
21      @Test
22      public void invalidSpaces() throws Exception {
23          assertFalse(ValidFeatureKeyPredicate.isValidFeatureKey(" "));
24      }
25  
26      @Test
27      public void invalidComma() throws Exception {
28          assertFalse(ValidFeatureKeyPredicate.isValidFeatureKey(","));
29      }
30  
31      @Test
32      public void validWithDots() throws Exception {
33          assertTrue(ValidFeatureKeyPredicate.isValidFeatureKey("com.atlassian.darkfeature.key"));
34      }
35  
36      @Test
37      public void validWithDash() throws Exception {
38          assertTrue(ValidFeatureKeyPredicate.isValidFeatureKey("all-the-things"));
39      }
40  
41      @Test
42      public void validWithUnderscore() throws Exception {
43          assertTrue(ValidFeatureKeyPredicate.isValidFeatureKey("go_go"));
44      }
45  
46      @Test
47      public void validWithNumbers() throws Exception {
48          assertTrue(ValidFeatureKeyPredicate.isValidFeatureKey("v1"));
49      }
50  
51      @Test
52      public void checkValidFeatureKey() {
53          final String featureKey = "valid.feature.key";
54          final String result = ValidFeatureKeyPredicate.checkFeatureKey(featureKey);
55          assertThat(result, is(featureKey));
56      }
57  
58      @Test(expected = InvalidFeatureKeyException.class)
59      public void checkInvalidFeatureKey() {
60          ValidFeatureKeyPredicate.checkFeatureKey("  invalid   ");
61      }
62  }