|
32 | 32 | import org.junit.jupiter.api.Nested;
|
33 | 33 | import org.junit.jupiter.api.Test;
|
34 | 34 |
|
| 35 | +import org.springframework.boot.loader.jarmode.JarModeErrorException; |
| 36 | + |
35 | 37 | import static org.assertj.core.api.Assertions.assertThat;
|
| 38 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
36 | 39 | import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
37 | 40 |
|
38 | 41 | /**
|
@@ -172,17 +175,18 @@ void failsOnIncompatibleJar() throws IOException {
|
172 | 175 | try (FileWriter writer = new FileWriter(file)) {
|
173 | 176 | writer.write("text");
|
174 | 177 | }
|
175 |
| - TestPrintStream out = run(file); |
176 |
| - assertThat(out).contains("is not compatible; ensure jar file is valid and launch script is not enabled"); |
| 178 | + assertThatExceptionOfType(JarModeErrorException.class).isThrownBy(() -> run(file)) |
| 179 | + .withMessageContaining("is not compatible; ensure jar file is valid and launch script is not enabled"); |
177 | 180 | }
|
178 | 181 |
|
179 | 182 | @Test
|
180 | 183 | void shouldFailIfDirectoryIsNotEmpty() throws IOException {
|
181 | 184 | File destination = file("out");
|
182 | 185 | Files.createDirectories(destination.toPath());
|
183 | 186 | Files.createFile(new File(destination, "file.txt").toPath());
|
184 |
| - TestPrintStream out = run(ExtractCommandTests.this.archive, "--destination", destination.getAbsolutePath()); |
185 |
| - assertThat(out).contains("already exists and is not empty"); |
| 187 | + assertThatExceptionOfType(JarModeErrorException.class) |
| 188 | + .isThrownBy(() -> run(ExtractCommandTests.this.archive, "--destination", destination.getAbsolutePath())) |
| 189 | + .withMessageContaining("already exists and is not empty"); |
186 | 190 | }
|
187 | 191 |
|
188 | 192 | @Test
|
@@ -266,10 +270,10 @@ void extractsOnlySelectedLayers() throws IOException {
|
266 | 270 | }
|
267 | 271 |
|
268 | 272 | @Test
|
269 |
| - void printErrorIfLayersAreNotEnabled() throws IOException { |
| 273 | + void failsIfLayersAreNotEnabled() throws IOException { |
270 | 274 | File archive = createArchive();
|
271 |
| - TestPrintStream out = run(archive, "--layers"); |
272 |
| - assertThat(out).hasSameContentAsResource("ExtractCommand-printErrorIfLayersAreNotEnabled.txt"); |
| 275 | + assertThatExceptionOfType(JarModeErrorException.class).isThrownBy(() -> run(archive, "--layers")) |
| 276 | + .withMessage("Layers are not enabled"); |
273 | 277 | }
|
274 | 278 |
|
275 | 279 | }
|
@@ -318,10 +322,11 @@ void extract() throws IOException {
|
318 | 322 | }
|
319 | 323 |
|
320 | 324 | @Test
|
321 |
| - void printErrorIfLayersAreNotEnabled() throws IOException { |
| 325 | + void failsIfLayersAreNotEnabled() throws IOException { |
322 | 326 | File archive = createArchive();
|
323 |
| - TestPrintStream out = run(archive, "--launcher", "--layers"); |
324 |
| - assertThat(out).hasSameContentAsResource("ExtractCommand-printErrorIfLayersAreNotEnabled.txt"); |
| 327 | + assertThatExceptionOfType(JarModeErrorException.class) |
| 328 | + .isThrownBy(() -> run(archive, "--launcher", "--layers")) |
| 329 | + .withMessage("Layers are not enabled"); |
325 | 330 | }
|
326 | 331 |
|
327 | 332 | @Test
|
|
0 commit comments