1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.spi.core.value;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.equalTo;
20 import static org.hamcrest.Matchers.hasItems;
21 import static org.hamcrest.Matchers.is;
22
23 import java.util.List;
24
25 import org.junit.Before;
26 import org.junit.Test;
27
28 import de.smartics.properties.spi.core.value.CollectionPropertyValueRange;
29 import de.smartics.testdoc.annotations.Uut;
30 import de.smartics.util.lang.NullArgumentException;
31
32
33
34
35 @Uut(type = CollectionPropertyValueRange.class)
36 public class CollectionPropertyValueRangeWithArrayTest
37 {
38
39
40
41
42 private static final String ELEMENT_2 = "two";
43
44 private static final String ELEMENT_1 = "one";
45
46 private static final String[] TEST_ARRAY =
47 { ELEMENT_1, ELEMENT_2 };
48
49
50
51 private CollectionPropertyValueRange<String> uut;
52
53
54
55
56
57
58
59 @Before
60 public void setUp()
61 {
62 uut = new CollectionPropertyValueRange<String>(TEST_ARRAY);
63 }
64
65
66
67
68
69 @Test
70 public void providesAStringRepresentation()
71 {
72 final String result = uut.toString();
73
74 assertThat(result, is(equalTo("one, two")));
75 }
76
77 @Test
78 public void providesAnElementInstanceFromAString()
79 {
80 final String elementName = ELEMENT_2;
81 final String element = uut.fromString(elementName);
82
83 assertThat(element, is(equalTo(ELEMENT_2)));
84 }
85
86 @Test(expected = IllegalArgumentException.class)
87 public void signalsRequestOfUnknownElementWithAnException()
88 {
89 final String elementName = "unknown-element-name";
90 uut.fromString(elementName);
91 }
92
93 @Test
94 public void allowsToRetrieveAllValues()
95 {
96 final List<String> values = uut.getValues();
97
98 assertThat(values.size(), is(equalTo(2)));
99 assertThat(values, hasItems(ELEMENT_1, ELEMENT_2));
100 }
101
102 @Test(expected = NullArgumentException.class)
103 public void constructionRequiresANonNullArray()
104 {
105 new CollectionPropertyValueRange<String>((String[]) null);
106 }
107 }