|
17 | 17 | package org.springframework.boot.maven;
|
18 | 18 |
|
19 | 19 | import java.io.File;
|
20 |
| -import java.net.MalformedURLException; |
21 |
| -import java.net.URL; |
22 | 20 | import java.nio.file.Path;
|
23 | 21 | import java.nio.file.Paths;
|
24 |
| -import java.util.ArrayList; |
25 |
| -import java.util.List; |
26 | 22 |
|
27 | 23 | import org.junit.jupiter.api.Nested;
|
28 | 24 | import org.junit.jupiter.api.Test;
|
|
43 | 39 | */
|
44 | 40 | class ClasspathBuilderTests {
|
45 | 41 |
|
46 |
| - @Test |
47 |
| - @DisabledOnOs(OS.WINDOWS) |
48 |
| - void buildWithMultipleClassPathURLs(@TempDir Path tempDir) throws Exception { |
49 |
| - Path file = tempDir.resolve("test.jar"); |
50 |
| - Path file1 = tempDir.resolve("test1.jar"); |
51 |
| - assertThat(ClasspathBuilder.forURLs(file.toUri().toURL(), file1.toUri().toURL()).build().argument()) |
52 |
| - .isEqualTo(file + File.pathSeparator + file1); |
53 |
| - } |
54 |
| - |
55 |
| - @Test |
56 |
| - @EnabledOnOs(OS.WINDOWS) |
57 |
| - void buildWithMultipleClassPathURLsOnWindows(@TempDir Path tempDir) throws Exception { |
58 |
| - Path file = tempDir.resolve("test.jar"); |
59 |
| - Path file1 = tempDir.resolve("test1.jar"); |
60 |
| - String classpath = ClasspathBuilder.forURLs(file.toUri().toURL(), file1.toUri().toURL()).build().argument(); |
61 |
| - assertThat(classpath).startsWith("@"); |
62 |
| - assertThat(Paths.get(classpath.substring(1))) |
63 |
| - .hasContent("\"" + (file + File.pathSeparator + file1).replace("\\", "\\\\") + "\""); |
64 |
| - } |
65 |
| - |
66 | 42 | @Nested
|
| 43 | + @EnabledOnOs(OS.WINDOWS) |
67 | 44 | class WindowsTests {
|
68 | 45 |
|
69 | 46 | @Test
|
70 |
| - void buildWithEmptyClassPath() throws MalformedURLException { |
71 |
| - Classpath classpath = classPathBuilder().build(); |
| 47 | + void buildWithEmptyClassPath() { |
| 48 | + Classpath classpath = ClasspathBuilder.forURLs().build(); |
72 | 49 | assertThat(classpath.argument()).isEmpty();
|
73 | 50 | assertThat(classpath.elements()).isEmpty();
|
74 | 51 | }
|
75 | 52 |
|
76 | 53 | @Test
|
77 | 54 | void buildWithSingleClassPathURL(@TempDir Path tempDir) throws Exception {
|
78 | 55 | Path file = tempDir.resolve("test.jar");
|
79 |
| - Classpath classpath = classPathBuilder(file).build(); |
| 56 | + Classpath classpath = ClasspathBuilder.forURLs(file.toUri().toURL()).build(); |
80 | 57 | assertThat(classpath.argument()).isEqualTo(file.toString());
|
81 | 58 | assertThat(classpath.elements()).singleElement().isEqualTo(file);
|
82 | 59 | }
|
83 | 60 |
|
84 | 61 | @Test
|
85 | 62 | void buildWithMultipleClassPathURLs(@TempDir Path tempDir) throws Exception {
|
86 | 63 | Path file = tempDir.resolve("test.jar");
|
87 |
| - Path file2 = tempDir.resolve("test2.jar"); |
88 |
| - Classpath classpath = classPathBuilder(file, file2).build(); |
89 |
| - assertThat(classpath.argument()).startsWith("@"); |
90 |
| - assertThat(Paths.get(classpath.argument().substring(1))) |
91 |
| - .hasContent("\"" + (file + File.pathSeparator + file2).replace("\\", "\\\\") + "\""); |
92 |
| - } |
93 |
| - |
94 |
| - private ClasspathBuilder classPathBuilder(Path... files) throws MalformedURLException { |
95 |
| - return new TestClasspathBuilder(true, files); |
| 64 | + Path file1 = tempDir.resolve("test1.jar"); |
| 65 | + String classpath = ClasspathBuilder.forURLs(file.toUri().toURL(), file1.toUri().toURL()).build().argument(); |
| 66 | + assertThat(classpath).startsWith("@"); |
| 67 | + assertThat(Paths.get(classpath.substring(1))) |
| 68 | + .hasContent("\"" + (file + File.pathSeparator + file1).replace("\\", "\\\\") + "\""); |
96 | 69 | }
|
97 | 70 |
|
98 | 71 | }
|
99 | 72 |
|
100 | 73 | @Nested
|
| 74 | + @DisabledOnOs(OS.WINDOWS) |
101 | 75 | class UnixTests {
|
102 | 76 |
|
103 | 77 | @Test
|
104 |
| - void buildWithEmptyClassPath() throws MalformedURLException { |
105 |
| - Classpath classpath = classPathBuilder().build(); |
| 78 | + void buildWithEmptyClassPath() { |
| 79 | + Classpath classpath = ClasspathBuilder.forURLs().build(); |
106 | 80 | assertThat(classpath.argument()).isEmpty();
|
107 | 81 | assertThat(classpath.elements()).isEmpty();
|
108 | 82 | }
|
109 | 83 |
|
110 | 84 | @Test
|
111 | 85 | void buildWithSingleClassPathURL(@TempDir Path tempDir) throws Exception {
|
112 | 86 | Path file = tempDir.resolve("test.jar");
|
113 |
| - Classpath classpath = classPathBuilder(file).build(); |
| 87 | + Classpath classpath = ClasspathBuilder.forURLs(file.toUri().toURL()).build(); |
114 | 88 | assertThat(classpath.argument()).isEqualTo(file.toString());
|
115 | 89 | assertThat(classpath.elements()).singleElement().isEqualTo(file);
|
116 | 90 | }
|
117 | 91 |
|
118 | 92 | @Test
|
119 | 93 | void buildWithMultipleClassPathURLs(@TempDir Path tempDir) throws Exception {
|
120 | 94 | Path file = tempDir.resolve("test.jar");
|
121 |
| - Path file2 = tempDir.resolve("test2.jar"); |
122 |
| - Classpath classpath = classPathBuilder(file, file2).build(); |
123 |
| - assertThat(classpath.argument()).doesNotStartWith("@") |
124 |
| - .isEqualTo((file + File.pathSeparator + file2).replace("\\", "\\\\")); |
125 |
| - } |
126 |
| - |
127 |
| - private ClasspathBuilder classPathBuilder(Path... files) throws MalformedURLException { |
128 |
| - return new TestClasspathBuilder(false, files); |
129 |
| - } |
130 |
| - |
131 |
| - } |
132 |
| - |
133 |
| - private static class TestClasspathBuilder extends ClasspathBuilder { |
134 |
| - |
135 |
| - private final boolean needsClasspathArgFile; |
136 |
| - |
137 |
| - protected TestClasspathBuilder(boolean needsClasspathArgFile, Path... files) throws MalformedURLException { |
138 |
| - super(toURLs(files)); |
139 |
| - this.needsClasspathArgFile = needsClasspathArgFile; |
140 |
| - } |
141 |
| - |
142 |
| - private static List<URL> toURLs(Path... files) throws MalformedURLException { |
143 |
| - List<URL> urls = new ArrayList<>(); |
144 |
| - for (Path file : files) { |
145 |
| - urls.add(file.toUri().toURL()); |
146 |
| - } |
147 |
| - return urls; |
148 |
| - } |
149 |
| - |
150 |
| - @Override |
151 |
| - protected boolean needsClasspathArgFile() { |
152 |
| - return this.needsClasspathArgFile; |
| 95 | + Path file1 = tempDir.resolve("test1.jar"); |
| 96 | + assertThat(ClasspathBuilder.forURLs(file.toUri().toURL(), file1.toUri().toURL()).build().argument()) |
| 97 | + .isEqualTo(file + File.pathSeparator + file1); |
153 | 98 | }
|
154 | 99 |
|
155 | 100 | }
|
|
0 commit comments