1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.resource.filesystem;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is;
20 import static org.hamcrest.Matchers.not;
21 import static org.hamcrest.Matchers.endsWith;
22 import static org.hamcrest.Matchers.emptyCollectionOf;
23
24 import java.io.File;
25 import java.net.URL;
26 import java.util.Collection;
27
28 import org.junit.Before;
29 import org.junit.Test;
30
31 import de.smartics.properties.resource.domain.ClassPathEnvironment;
32 import de.smartics.properties.resource.filesystem.heap.FileSystemResourceHeap;
33 import de.smartics.testdoc.annotations.Uut;
34 import de.smartics.util.test.io.FileTestUtils;
35
36
37
38
39 public class FileSystemResourceHeapTest
40 {
41
42
43
44
45
46
47 @Uut
48 private FileSystemResourceHeap uut;
49
50
51
52
53
54
55
56 @Before
57 public void setUp()
58 {
59 uut = new FileSystemResourceHeap();
60 }
61
62
63
64
65
66 @Test
67 public void ableToDealWithNoRootDirectory()
68 {
69 final ClassPathEnvironment env = uut.resolve();
70 assertThat((Collection<URL>) env.getUrls(),
71 is(emptyCollectionOf(URL.class)));
72 }
73
74 @Test
75 public void ableToDealWithEmptyDirectories()
76 {
77 final File dir = FileTestUtils.getFileFromResource("fs/empty");
78
79 final FileSystemResourceHeap uut = new FileSystemResourceHeap();
80 uut.addRootFolder(dir);
81 final ClassPathEnvironment env = uut.resolve();
82 assertThat((Collection<URL>) env.getUrls(),
83 is(emptyCollectionOf(URL.class)));
84 }
85
86 @Test
87 public void ableToDealWithJars()
88 {
89 final File dir = FileTestUtils.getFileFromResource("fs/jar");
90
91 final FileSystemResourceHeap uut = new FileSystemResourceHeap();
92 uut.addRootFolder(dir);
93 final ClassPathEnvironment env = uut.resolve();
94 assertThat((Collection<URL>) env.getUrls(),
95 is(not(emptyCollectionOf(URL.class))));
96 }
97
98 @Test
99 public void ableToDealWithPropertiesFolder()
100 {
101 final File dir = FileTestUtils.getFileFromResource("fs/properties");
102
103 final FileSystemResourceHeap uut = new FileSystemResourceHeap();
104 uut.addRootFolder(dir);
105 final ClassPathEnvironment env = uut.resolve();
106 assertThat((Collection<URL>) env.getUrls(),
107 is(not(emptyCollectionOf(URL.class))));
108 assertThat(env.getUrls().get(0).toExternalForm(),
109 is(not(endsWith(".properties"))));
110 }
111 }