1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.ci.config.load;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is;
20 import static org.hamcrest.Matchers.notNullValue;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.when;
23
24 import java.io.File;
25 import java.io.FileNotFoundException;
26
27 import org.apache.commons.io.IOUtils;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31 import org.xml.sax.InputSource;
32
33 import de.smartics.ci.config.load.LocationManager;
34 import de.smartics.ci.config.projects.Project;
35 import de.smartics.testdoc.annotations.Uut;
36 import de.smartics.testdoc.categories.type.Coverage;
37 import de.smartics.util.test.io.FileTestUtils;
38
39
40
41
42 public class LocationManagerTest
43 {
44
45
46
47
48
49
50 @Uut
51 private LocationManager uut;
52
53
54
55
56
57
58
59 @Before
60 public void setUp()
61 {
62 uut = new LocationManager();
63 }
64
65
66
67
68
69 @Test
70 public void allowsToAddAFileLocation() throws FileNotFoundException
71 {
72 final File location =
73 FileTestUtils.getFileFromRelativeResource(Project.class,
74 Project.GLOBAL_RESOURCES);
75 uut.addLocation(location);
76 }
77
78 @Test(expected = NullPointerException.class)
79 public void allowsNotNullToBeAddedAsAFileLocation()
80 {
81 uut.addLocation((File) null);
82 }
83
84 @Test(expected = FileNotFoundException.class)
85 public void signalsMissingResources() throws FileNotFoundException
86 {
87 final File location =
88 FileTestUtils.getFileFromRelativeResource(Project.class,
89 Project.GLOBAL_RESOURCES);
90 uut.addLocation(location);
91 uut.open("unknown/resource.xml");
92 }
93
94 @Test
95 public void opensResourcesFromKnownLocations() throws FileNotFoundException
96 {
97 final File location =
98 FileTestUtils.getFileFromRelativeResource(Project.class,
99 Project.GLOBAL_RESOURCES);
100 uut.addLocation(location);
101 final InputSource source = uut.open(Project.GLOBAL_ROOT_XML);
102 assertThat(source, is(notNullValue()));
103 IOUtils.closeQuietly(source.getByteStream());
104 }
105
106 @Test(expected = IllegalArgumentException.class)
107 @Category(Coverage.class)
108 public void rejectsInvalidFiles() throws FileNotFoundException
109 {
110 final File location = mock(File.class);
111 when(location.toURI()).thenThrow(new IllegalArgumentException("Test"));
112 uut.addLocation(location);
113 }
114 }