1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.resource.repository;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.equalTo;
20 import static org.hamcrest.Matchers.is;
21
22 import java.net.MalformedURLException;
23 import java.net.URL;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31 import de.smartics.properties.resource.domain.ArtifactId;
32 import de.smartics.properties.resource.domain.ArtifactRef;
33 import de.smartics.properties.resource.domain.ClassPathEnvironment;
34 import de.smartics.testdoc.annotations.Uut;
35 import de.smartics.testdoc.categories.type.Coverage;
36
37
38
39
40 public class ClassPathEnvironmentTest
41 {
42
43
44
45
46 static final ArtifactRef DEFAULT_URL;
47
48 static final ArtifactRef ANOTHER_ARTIFACT_REF;
49
50 static
51 {
52 try
53 {
54 final ArtifactId.Builder builder = new ArtifactId.Builder();
55 builder.withGroupId("com.example.test").withName("one").withVersion("1.0").withArchiveType("jar");
56 final ArtifactId id1 = builder.build();
57 final ArtifactId id2 = builder.withName("two").build();
58
59 DEFAULT_URL = new ArtifactRef(id1, new URL("http://example.com/one"));
60 ANOTHER_ARTIFACT_REF = new ArtifactRef(id2, new URL("http://example.com/two"));
61 }
62 catch (final MalformedURLException e)
63 {
64 throw new IllegalStateException("Cannot create test URL.", e);
65 }
66 }
67
68
69
70 @Uut
71 private ClassPathEnvironment uut;
72
73
74
75
76
77
78
79 @Before
80 public void setUp()
81 {
82 uut = new ClassPathEnvironment();
83 }
84
85
86
87
88
89 @Test
90 public void neverRetursNullForAnRefsList()
91 {
92 final List<ArtifactRef> refs = uut.getArtifactRefs();
93
94 assertThat(refs.isEmpty(), is(true));
95 }
96
97 @Test(expected = UnsupportedOperationException.class)
98 public void returnedRefsListIsNotModifiable()
99 {
100 final List<ArtifactRef> refs = uut.getArtifactRefs();
101 refs.add(DEFAULT_URL);
102 }
103
104 @Test
105 public void allowsToAddRefsToTheListOfSearchRoots()
106 {
107 uut.addArchiveArtifactRef(DEFAULT_URL);
108
109 final List<ArtifactRef> urls = uut.getArtifactRefs();
110 final List<ArtifactRef> expected = new ArrayList<ArtifactRef>();
111 expected.add(DEFAULT_URL);
112 assertThat(urls, is(equalTo(expected)));
113 }
114
115 @Test
116 public void orderOfAddingRefsIsPreserved()
117 {
118 uut.addArchiveArtifactRef(DEFAULT_URL);
119 uut.addArchiveArtifactRef(ANOTHER_ARTIFACT_REF);
120
121 final List<ArtifactRef> refs = uut.getArtifactRefs();
122 final List<ArtifactRef> expected = new ArrayList<ArtifactRef>();
123 expected.add(DEFAULT_URL);
124 expected.add(ANOTHER_ARTIFACT_REF);
125 assertThat(refs, is(equalTo(expected)));
126 }
127
128 @Test
129 public void printsClassPathByItsToString()
130 {
131 uut.addArchiveArtifactRef(DEFAULT_URL);
132 uut.addArchiveArtifactRef(ANOTHER_ARTIFACT_REF);
133
134 final String string = uut.toString();
135 assertThat(string.length() > 0, is(true));
136 }
137
138 @Test
139 @Category(Coverage.class)
140 public void printsClassPathByItsToStringOnAnEmptyList()
141 {
142 final String string = uut.toString();
143 assertThat(string.length() > 0, is(true));
144 }
145 }