Skip to content

Commit

Permalink
#3636: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 12, 2024
1 parent 7d6c669 commit 6f07f8f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
12 changes: 10 additions & 2 deletions eo-parser/src/main/java/org/eolang/parser/StrictXmir.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,16 @@ private static File download(final String uri, final Path path) {
new BytesOf(new InputOf(new URI(uri)))
).asBytes()
);
} catch (final IOException | URISyntaxException ex) {
throw new IllegalArgumentException(ex);
} catch (final IOException ex) {
throw new IllegalArgumentException(
String.format("Failed to download %s to %s", uri, path),
ex
);
} catch (final URISyntaxException ex) {
throw new IllegalArgumentException(
String.format("Wrong URI: %s", uri),
ex
);
}
}
return abs;
Expand Down
26 changes: 26 additions & 0 deletions eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.nio.file.Path;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.xembly.Directives;
Expand Down Expand Up @@ -72,4 +73,29 @@ void validatesXmir(@Mktmp final Path tmp) throws Exception {
);
}

@Test
@ExtendWith(MktmpResolver.class)
void validatesXmirWithBrokenUri(@Mktmp final Path tmp) {
Assertions.assertThrows(
IllegalArgumentException.class,
() -> new StrictXmir(
new Xmir(
new XMLDocument(
new Xembler(
new Directives()
.append(new DrProgram("foo"))
.xpath("/program")
.attr(
"noNamespaceSchemaLocation xsi http://www.w3.org/2001/XMLSchema-instance",
"https://www.invalid-website-uri/XMIR.xsd"
)
.add("objects")
).xml()
)
),
tmp
).validate(),
"validation should fail because of broken URI"
);
}
}

0 comments on commit 6f07f8f

Please sign in to comment.