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 {
12 @Test
13 public void invalidNullKey() throws Exception
14 {
15 assertFalse(ValidFeatureKeyPredicate.isValidFeatureKey(null));
16 }
17
18 @Test
19 public void invalidEmptyString() throws Exception
20 {
21 assertFalse(ValidFeatureKeyPredicate.isValidFeatureKey(""));
22 }
23
24 @Test
25 public void invalidSpaces() throws Exception
26 {
27 assertFalse(ValidFeatureKeyPredicate.isValidFeatureKey(" "));
28 }
29
30 @Test
31 public void invalidComma() throws Exception
32 {
33 assertFalse(ValidFeatureKeyPredicate.isValidFeatureKey(","));
34 }
35
36 @Test
37 public void validWithDots() throws Exception
38 {
39 assertTrue(ValidFeatureKeyPredicate.isValidFeatureKey("com.atlassian.darkfeature.key"));
40 }
41
42 @Test
43 public void validWithDash() throws Exception
44 {
45 assertTrue(ValidFeatureKeyPredicate.isValidFeatureKey("all-the-things"));
46 }
47
48 @Test
49 public void validWithUnderscore() throws Exception
50 {
51 assertTrue(ValidFeatureKeyPredicate.isValidFeatureKey("go_go"));
52 }
53
54 @Test
55 public void validWithNumbers() throws Exception
56 {
57 assertTrue(ValidFeatureKeyPredicate.isValidFeatureKey("v1"));
58 }
59
60 @Test
61 public void checkValidFeatureKey()
62 {
63 final String featureKey = "valid.feature.key";
64 final String result = ValidFeatureKeyPredicate.checkFeatureKey(featureKey);
65 assertThat(result, is(featureKey));
66 }
67
68 @Test(expected = InvalidFeatureKeyException.class)
69 public void checkInvalidFeatureKey()
70 {
71 ValidFeatureKeyPredicate.checkFeatureKey(" invalid ");
72 }
73 }