Skip to content

Commit 29e498b

Browse files
committed
Only run Windows-related tests on Windows
See gh-44305
1 parent 4c1f63b commit 29e498b

File tree

1 file changed

+16
-71
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven

1 file changed

+16
-71
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ClasspathBuilderTests.java

+16-71
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717
package org.springframework.boot.maven;
1818

1919
import java.io.File;
20-
import java.net.MalformedURLException;
21-
import java.net.URL;
2220
import java.nio.file.Path;
2321
import java.nio.file.Paths;
24-
import java.util.ArrayList;
25-
import java.util.List;
2622

2723
import org.junit.jupiter.api.Nested;
2824
import org.junit.jupiter.api.Test;
@@ -43,113 +39,62 @@
4339
*/
4440
class ClasspathBuilderTests {
4541

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-
6642
@Nested
43+
@EnabledOnOs(OS.WINDOWS)
6744
class WindowsTests {
6845

6946
@Test
70-
void buildWithEmptyClassPath() throws MalformedURLException {
71-
Classpath classpath = classPathBuilder().build();
47+
void buildWithEmptyClassPath() {
48+
Classpath classpath = ClasspathBuilder.forURLs().build();
7249
assertThat(classpath.argument()).isEmpty();
7350
assertThat(classpath.elements()).isEmpty();
7451
}
7552

7653
@Test
7754
void buildWithSingleClassPathURL(@TempDir Path tempDir) throws Exception {
7855
Path file = tempDir.resolve("test.jar");
79-
Classpath classpath = classPathBuilder(file).build();
56+
Classpath classpath = ClasspathBuilder.forURLs(file.toUri().toURL()).build();
8057
assertThat(classpath.argument()).isEqualTo(file.toString());
8158
assertThat(classpath.elements()).singleElement().isEqualTo(file);
8259
}
8360

8461
@Test
8562
void buildWithMultipleClassPathURLs(@TempDir Path tempDir) throws Exception {
8663
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("\\", "\\\\") + "\"");
9669
}
9770

9871
}
9972

10073
@Nested
74+
@DisabledOnOs(OS.WINDOWS)
10175
class UnixTests {
10276

10377
@Test
104-
void buildWithEmptyClassPath() throws MalformedURLException {
105-
Classpath classpath = classPathBuilder().build();
78+
void buildWithEmptyClassPath() {
79+
Classpath classpath = ClasspathBuilder.forURLs().build();
10680
assertThat(classpath.argument()).isEmpty();
10781
assertThat(classpath.elements()).isEmpty();
10882
}
10983

11084
@Test
11185
void buildWithSingleClassPathURL(@TempDir Path tempDir) throws Exception {
11286
Path file = tempDir.resolve("test.jar");
113-
Classpath classpath = classPathBuilder(file).build();
87+
Classpath classpath = ClasspathBuilder.forURLs(file.toUri().toURL()).build();
11488
assertThat(classpath.argument()).isEqualTo(file.toString());
11589
assertThat(classpath.elements()).singleElement().isEqualTo(file);
11690
}
11791

11892
@Test
11993
void buildWithMultipleClassPathURLs(@TempDir Path tempDir) throws Exception {
12094
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);
15398
}
15499

155100
}

0 commit comments

Comments
 (0)