1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.tutorial.property.list;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.contains;
20
21 import java.net.URL;
22 import java.util.List;
23
24 import org.junit.Before;
25 import org.junit.Test;
26
27 import de.smartics.projectdoc.annotations.DocCategory;
28 import de.smartics.projectdoc.annotations.Document;
29 import de.smartics.projectdoc.annotations.topic.DocChapter;
30 import de.smartics.projectdoc.annotations.topic.DocSection;
31 import de.smartics.properties.api.config.domain.ConfigurationProperties;
32 import de.smartics.properties.impl.config.classpath.ClasspathConfigurationProperties;
33 import de.smartics.properties.impl.config.classpath.ClasspathConfigurationPropertiesFactory;
34
35
36
37
38
39
40
41
42 @Document(title = "List Properties", sortKey = "basics0100")
43 @DocCategory({ "basics" })
44
45 public class ListPropertyTutorial
46 {
47 private ConfigurationProperties config;
48
49 private ListProperties properties;
50
51 @Before
52 public void setUp()
53 {
54 config = createConfiguration();
55 properties = config.getProperties(ListProperties.class);
56 }
57
58 private static ConfigurationProperties createConfiguration()
59 {
60 final ClasspathConfigurationPropertiesFactory factory =
61 new ClasspathConfigurationPropertiesFactory();
62 final ClasspathConfigurationProperties config = factory.create();
63 config.addClassPathProperties(ListProperties.class);
64 return config;
65 }
66
67
68
69
70
71
72
73
74
75
76
77 @Test
78 @DocChapter
79 public void propertyWithValueOfTypeListOfString()
80 {
81 final List<String> list = properties.listOfStrings();
82 assertThat(list, contains("one", "two", "three"));
83 }
84
85
86
87
88
89
90
91
92
93
94
95 @Test
96 @DocChapter
97 public void propertyWithValueOfTypeListOfInteger()
98 {
99 final List<Integer> list = properties.listOfInts();
100 assertThat(list, contains(1, 2, 3));
101 }
102
103
104
105
106
107
108 @Test
109 @DocChapter
110 public void separators()
111 {
112 final List<String> list = properties.listOfStrings();
113 assertThat(list, contains("one", "two", "three"));
114 }
115
116
117
118
119
120
121 @Test
122 @DocSection
123 public void pipeAsSeparator()
124 {
125 final List<String> list = properties.pipedListOfStrings();
126 assertThat(list, contains("one", "two", "three"));
127 }
128
129
130
131
132
133
134 @Test
135 @DocSection
136 public void blankAsSeparator()
137 {
138 final List<String> list = properties.blankedListOfStrings();
139 assertThat(list, contains("one", "two", "three"));
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153 @Test
154 @DocSection
155 public void propertyWithSpecialStrings()
156 {
157 final List<String> list = properties.extremeListOfStrings();
158 assertThat(list,
159 contains("one", "two two", "three three three", "comma',", "\"hey!\""));
160 }
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177 @Test
178 @DocChapter
179 public void propertyWithValueOfTypeListOfUrl() throws Exception
180 {
181 final List<URL> list = properties.listOfUrls();
182 assertThat(
183 list,
184 contains(new URL("http://www.example.com/index.html"), new URL(
185 "http://www.example.com/products.html"), new URL(
186 "http://www.example.com/news.html")));
187 }
188
189
190
191
192
193
194 @DocSection
195 public void urlsSeparatedByNewlines() throws Exception
196 {
197 final List<URL> list = properties.listOfNewLineUrls();
198 assertThat(
199 list,
200 contains(new URL("http://www.example.com/index.html"), new URL(
201 "http://www.example.com/products.html"), new URL(
202 "http://www.example.com/news.html")));
203 }
204
205
206
207
208
209
210
211
212
213
214
215 @Test
216 @DocChapter
217 public void propertyWithValueOfTypeListOfEnums()
218 {
219 final List<Priority> list = properties.listOfPriorities();
220 assertThat(
221 list,
222 contains(Priority.REQUIRED, Priority.VERY_IMPORTANT,
223 Priority.NICE_TO_HAVE));
224 }
225 }