Skip to content

Commit

Permalink
Accept file separator difference in exception message (for Windows co…
Browse files Browse the repository at this point in the history
…mpatibility)
  • Loading branch information
jhoeller committed Jun 24, 2024
1 parent d9a2e0b commit 0a0f4c7
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ void addFileWhenPathIsOutsideOfRootThrowsException() {
@Test
void addFileWhenFileAlreadyAddedThrowsException() {
FileSystemGeneratedFiles generatedFiles = new FileSystemGeneratedFiles(this.root);
generatedFiles.addResourceFile("META-INF/test", "test");
assertThatIllegalStateException().isThrownBy(
() -> generatedFiles.addResourceFile("META-INF/test", "test"))
.withMessageContaining("META-INF/test", "already exists");
generatedFiles.addResourceFile("META-INF/mydir", "test");
assertThatIllegalStateException()
.isThrownBy(() -> generatedFiles.addResourceFile("META-INF/mydir", "test"))
.withMessageContainingAll("META-INF", "mydir", "already exists");
}

@Test
Expand All @@ -122,20 +122,21 @@ void handleFileWhenFileExistsProvidesFileHandler() {
@Test
void handleFileWhenFileExistsFailsToCreate() {
FileSystemGeneratedFiles generatedFiles = new FileSystemGeneratedFiles(this.root);
generatedFiles.addResourceFile("META-INF/test", "test");
ThrowingConsumer<FileHandler> consumer = handler -> handler.create(new ByteArrayResource("should fail".getBytes(StandardCharsets.UTF_8)));
generatedFiles.addResourceFile("META-INF/mydir", "test");
ThrowingConsumer<FileHandler> consumer = handler ->
handler.create(new ByteArrayResource("should fail".getBytes(StandardCharsets.UTF_8)));
assertThatIllegalStateException()
.isThrownBy(() -> generatedFiles.handleFile(Kind.RESOURCE, "META-INF/test", consumer))
.withMessageContaining("META-INF/test", "already exists");
.isThrownBy(() -> generatedFiles.handleFile(Kind.RESOURCE, "META-INF/mydir", consumer))
.withMessageContainingAll("META-INF", "mydir", "already exists");
}

@Test
void handleFileWhenFileExistsCanOverrideContent() {
FileSystemGeneratedFiles generatedFiles = new FileSystemGeneratedFiles(this.root);
generatedFiles.addResourceFile("META-INF/test", "test");
generatedFiles.handleFile(Kind.RESOURCE, "META-INF/test", handler ->
generatedFiles.addResourceFile("META-INF/mydir", "test");
generatedFiles.handleFile(Kind.RESOURCE, "META-INF/mydir", handler ->
handler.override(new ByteArrayResource("overridden".getBytes(StandardCharsets.UTF_8))));
assertThat(this.root.resolve("resources/META-INF/test")).content().isEqualTo("overridden");
assertThat(this.root.resolve("resources/META-INF/mydir")).content().isEqualTo("overridden");
}

private void assertPathMustBeRelative(FileSystemGeneratedFiles generatedFiles, String path) {
Expand Down

0 comments on commit 0a0f4c7

Please sign in to comment.