1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.spi.core.classpath;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.hasItems;
20 import static org.hamcrest.Matchers.is;
21
22 import help.de.smartics.properties.core.SimpleProperties;
23
24 import java.io.IOException;
25 import java.net.URL;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.HashSet;
29 import java.util.Set;
30
31 import org.hamcrest.Matcher;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35
36 import de.smartics.properties.spi.core.classpath.PropertiesFilesLoader;
37 import de.smartics.testdoc.annotations.Uut;
38 import de.smartics.testdoc.categories.Technical;
39 import de.smartics.testdoc.categories.type.Coverage;
40
41
42
43
44 public class PropertiesFilesLoaderTest
45 {
46
47
48
49
50
51
52 @Uut
53 private PropertiesFilesLoader uut;
54
55
56
57
58
59
60
61 @Before
62 public void setUp()
63 {
64 uut = new PropertiesFilesLoader();
65 }
66
67
68
69
70
71 @Test
72 @Category(Technical.class)
73 public void allowsNullAsCollectionOfClassPathRoots()
74 {
75 final Set<String> propertiesFiles = uut.getPropertiesFiles(null);
76 assertThat(propertiesFiles.isEmpty(), is(true));
77 }
78
79 @Test
80 @Category(Technical.class)
81 public void allowsAnEmptyCollectionOfClassPathRoots()
82 {
83 final Set<String> propertiesFiles =
84 uut.getPropertiesFiles(new HashSet<URL>());
85 assertThat(propertiesFiles.isEmpty(), is(true));
86 }
87
88 @Test
89 @Category(Technical.class)
90 @SuppressWarnings({ "unchecked", "rawtypes" })
91 public void returnsOnlyPropertiesFiles() throws IOException
92 {
93 final String propertiesFileInClassPath =
94 "example/de/smartics/properties/simple/configuration.properties";
95
96 final ClassLoader loader = SimpleProperties.class.getClassLoader();
97 final URL url = loader.getResource("");
98 final Set<String> propertiesFiles =
99 uut.getPropertiesFiles(Arrays.asList(url));
100 assertThat(propertiesFiles.isEmpty(), is(false));
101 assertThat(propertiesFiles, (Matcher) hasItems(propertiesFileInClassPath));
102 }
103
104 @Test
105 @Category(Technical.class)
106 @SuppressWarnings({ "unchecked", "rawtypes" })
107 public void returnsBootPropertiesFile() throws IOException
108 {
109 final String bootPropertiesInClassPath =
110 "META-INF/smartics-properties/boot.properties";
111
112 final ClassLoader loader = SimpleProperties.class.getClassLoader();
113 final URL url = loader.getResource("example/de/smartics/properties/boot");
114 final Set<String> propertiesFiles =
115 uut.getBootPropertiesFiles(Arrays.asList(url));
116 assertThat(propertiesFiles.isEmpty(), is(false));
117 assertThat(propertiesFiles, (Matcher) hasItems(bootPropertiesInClassPath));
118 }
119
120 @Test
121 @Category(Technical.class)
122 public void returnsNoBootPropertiesFileIfNoneIsProvided() throws IOException
123 {
124 final ClassLoader loader = SimpleProperties.class.getClassLoader();
125 final URL url = loader.getResource("example/de/smartics/properties/simple");
126 final Set<String> propertiesFiles =
127 uut.getBootPropertiesFiles(Arrays.asList(url));
128 assertThat(propertiesFiles.isEmpty(), is(true));
129 }
130
131 @Test
132 @Category(Coverage.class)
133 public void fetchingBootPropertiesAllowsUrlsToBeNull() throws IOException
134 {
135 final Set<String> propertiesFiles = uut.getBootPropertiesFiles(null);
136 assertThat(propertiesFiles.isEmpty(), is(true));
137 }
138
139 @Test
140 @Category(Coverage.class)
141 public void fetchingBootPropertiesAllowsUrlsToBeEmpty() throws IOException
142 {
143 final Set<String> propertiesFiles =
144 uut.getBootPropertiesFiles(new ArrayList<URL>(0));
145 assertThat(propertiesFiles.isEmpty(), is(true));
146 }
147 }