Skip to content

Commit e33a326

Browse files
committed
Fix tests on windows
1 parent 5515267 commit e33a326

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

maven-model-builder/src/test/java/org/apache/maven/model/io/LocalXmlResolverTest.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020

2121
import javax.xml.stream.XMLStreamException;
2222

23+
import java.io.File;
2324
import java.nio.file.Paths;
2425

2526
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.condition.DisabledOnOs;
28+
import org.junit.jupiter.api.condition.OS;
2629

2730
import static org.junit.jupiter.api.Assertions.assertThrows;
2831
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -46,6 +49,7 @@ void testAbsoluteUriWithAbsolutePath() {
4649
}
4750

4851
@Test
52+
@DisabledOnOs(OS.WINDOWS)
4953
void testRelativeUriWithDifferentAbsolutePath() {
5054
XMLStreamException exception =
5155
assertThrows(XMLStreamException.class, () -> new LocalXmlResolver(Paths.get("/users/base"))
@@ -54,13 +58,32 @@ void testRelativeUriWithDifferentAbsolutePath() {
5458
}
5559

5660
@Test
61+
void testRelativeUriWithDifferentAbsolutePathWin() {
62+
// `C:/users` is parsed as a `C` scheme !
63+
XMLStreamException exception =
64+
assertThrows(XMLStreamException.class, () -> new LocalXmlResolver(Paths.get("/users/base"))
65+
.resolveEntity(null, "C:/foo/bar.xml", "file:/users/base/pom.xml", null));
66+
assertTrue(exception.getMessage().contains("systemID must be a relative URI"), exception.getMessage());
67+
}
68+
69+
@Test
70+
@DisabledOnOs(OS.WINDOWS)
5771
void testRelativeUriWithSameAbsolutePath() {
5872
XMLStreamException exception =
5973
assertThrows(XMLStreamException.class, () -> new LocalXmlResolver(Paths.get("/users/base"))
6074
.resolveEntity(null, "/users/base/foo/bar.xml", "file:/users/base/pom.xml", null));
6175
assertTrue(exception.getMessage().contains("systemID must be a relative path"), exception.getMessage());
6276
}
6377

78+
@Test
79+
void testRelativeUriWithSameAbsolutePathWin() {
80+
// `C:/users` is parsed as a `C` scheme !
81+
XMLStreamException exception =
82+
assertThrows(XMLStreamException.class, () -> new LocalXmlResolver(Paths.get("/users/base"))
83+
.resolveEntity(null, "C:/users/base/foo/bar.xml", "file:/users/base/pom.xml", null));
84+
assertTrue(exception.getMessage().contains("systemID must be a relative URI"), exception.getMessage());
85+
}
86+
6487
@Test
6588
void testRelativeUriWithRelativeUriToParentOutsideTree() {
6689
XMLStreamException exception =
@@ -78,7 +101,7 @@ void testRelativeUriWithRelativeUriToParentInsideTree() {
78101
.resolveEntity(null, "../bar.xml", "file:/users/base/foo/pom.xml", null));
79102
assertTrue(
80103
exception.getMessage().contains("Unable to create Source")
81-
&& exception.getMessage().contains("/users/base/bar.xml"),
104+
&& exception.getMessage().contains("/users/base/bar.xml".replace('/', File.separatorChar)),
82105
exception.getMessage());
83106
}
84107

@@ -89,7 +112,7 @@ void testRelativeUriWithRelativePath() {
89112
.resolveEntity(null, "foo/bar.xml", "file:/users/base/pom.xml", null));
90113
assertTrue(
91114
exception.getMessage().contains("Unable to create Source")
92-
&& exception.getMessage().contains("/users/base/foo/bar.xml"),
115+
&& exception.getMessage().contains("/users/base/foo/bar.xml".replace('/', File.separatorChar)),
93116
exception.getMessage());
94117
}
95118
}

0 commit comments

Comments
 (0)