Skip to content

Commit e3c011f

Browse files
Egor MartsynkovskyUbuntu
authored andcommitted
Unify test logic
DEVSIX-6440
1 parent c5c3c19 commit e3c011f

File tree

1 file changed

+28
-3
lines changed
  • styled-xml-parser/src/test/java/com/itextpdf/styledxmlparser/jsoup/nodes

1 file changed

+28
-3
lines changed

styled-xml-parser/src/test/java/com/itextpdf/styledxmlparser/jsoup/nodes/NodeTest.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,25 @@ public class NodeTest extends ExtendedITextTest {
119119
Assert.assertEquals("odd", el.attr("abs:href"));
120120
}
121121

122-
@Test public void handleAbsOnFileUris() {
122+
@Test
123+
public void handleAbsOnFileUris() {
123124
Document doc = Jsoup.parse("<a href='password'>One/a><a href='/var/log/messages'>Two</a>", "file:/etc/");
125+
String expectedUrl = "file:/etc/password";
126+
String expectedUrlAnotherValidVersion = createAnotherValidUrlVersion(expectedUrl);
127+
124128
Element one = doc.select("a").first();
125-
Assert.assertEquals("file:/etc/password", one.absUrl("href"));
129+
final String firstUrl = one.absUrl("href");
130+
// Both variants(namely with triple and single slashes) are valid.
131+
132+
Assert.assertTrue(expectedUrl.equals(firstUrl) || expectedUrlAnotherValidVersion.equals(firstUrl));
133+
134+
expectedUrl = "file:/var/log/messages";
135+
expectedUrlAnotherValidVersion = createAnotherValidUrlVersion(expectedUrl);
136+
126137
Element two = doc.select("a").get(1);
127-
Assert.assertEquals("file:/var/log/messages", two.absUrl("href"));
138+
final String secondUrl = two.absUrl("href");
139+
// Both variants(namely with triple and single slashes) are valid.
140+
Assert.assertTrue(expectedUrl.equals(secondUrl) || expectedUrlAnotherValidVersion.equals(secondUrl));
128141
}
129142

130143
@Test
@@ -353,4 +366,16 @@ private Attributes singletonAttributes() {
353366
attributes.put("value", "bar");
354367
return attributes;
355368
}
369+
370+
private static String createAnotherValidUrlVersion(String url) {
371+
if (url.startsWith("file:///")) {
372+
return "file:/" + url.substring("file:///".length());
373+
} else {
374+
if (url.startsWith("file:/")) {
375+
return "file:///" + url.substring("file:/".length());
376+
} else {
377+
return url;
378+
}
379+
}
380+
}
356381
}

0 commit comments

Comments
 (0)