1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.api.core.domain;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.equalTo;
20 import static org.hamcrest.Matchers.is;
21 import static org.hamcrest.Matchers.nullValue;
22
23 import org.junit.Test;
24 import org.junit.experimental.categories.Category;
25
26 import de.smartics.properties.api.core.domain.PropertyKey;
27 import de.smartics.testdoc.annotations.Uut;
28 import de.smartics.testdoc.categories.type.Construction;
29
30
31
32
33 @Uut(type = PropertyKey.class, method = "PropertyKey(String,String)")
34 public class PropertyKeyConstructionTest
35 {
36 private static final String VALID_NAME = "test.key";
37
38 private static final String VALID_COMPONENT_NAME = "Test-Component";
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 @Test
57 @Category(Construction.class)
58 public void allowsToCreateKeyWithoutAComponentName()
59 {
60 final PropertyKey uut = new PropertyKey(null, VALID_NAME);
61 assertThat(uut.getPropertySet(), is(nullValue()));
62 assertThat(uut.getName(), is(equalTo(VALID_NAME)));
63 }
64
65 @Test(expected = IllegalArgumentException.class)
66 @Category(Construction.class)
67 public void butTheComponentNameMustNotContainOnlyWhitespaces()
68 {
69 new PropertyKey(" \n\t ", VALID_NAME);
70 }
71
72 @Test(expected = IllegalArgumentException.class)
73 @Category(Construction.class)
74 public void butTheComponentNameMustNotBeEmpty()
75 {
76 new PropertyKey("", VALID_NAME);
77 }
78
79 @Test(expected = IllegalArgumentException.class)
80 @Category(Construction.class)
81 public void theNameOfTheKeyMustNotBeBlank()
82 {
83 new PropertyKey(VALID_COMPONENT_NAME, "");
84 }
85
86 @Test
87 @Category(Construction.class)
88 public void aValidKeyContainsAnOptionalComponentNameAndANonBlankName()
89 {
90 final PropertyKey uut = new PropertyKey(VALID_COMPONENT_NAME, VALID_NAME);
91 assertThat(uut.getPropertySet(), is(equalTo(VALID_COMPONENT_NAME)));
92 assertThat(uut.getName(), is(equalTo(VALID_NAME)));
93 }
94 }