You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2026/09/11 13:15:21 UTC
(maven-script-interpreter) branch i208 created (now 98be423)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a change to branch i208
in repository https://gitbox.apache.org/repos/asf/maven-script-interpreter.git
at 98be423 Test failure to throw exception
This branch includes the following new commits:
new 98be423 Test failure to throw exception
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-script-interpreter) 01/01: Test failure to throw exception
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch i208
in repository https://gitbox.apache.org/repos/asf/maven-script-interpreter.git
commit 98be4233be534d4096d206ff6986a6650eaad722
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Fri Sep 11 09:15:05 2026 -0400
Test failure to throw exception
---
.../shared/scriptinterpreter/ScriptRunnerTest.java | 65 ++++++++--------------
1 file changed, 23 insertions(+), 42 deletions(-)
diff --git a/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java b/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
index 86d4309..5f60ee1 100644
--- a/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
+++ b/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
@@ -32,6 +32,7 @@ import org.junit.jupiter.params.provider.ValueSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Olivier Lamy
@@ -81,44 +82,35 @@ class ScriptRunnerTest {
@Test
void failedBeanshellShouldCreateProperLogsMessage() throws Exception {
File logFile = new File(tempDir, "build.log");
-
TestMirrorHandler mirrorHandler = new TestMirrorHandler();
- Exception catchedException = null;
-
try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler);
ScriptRunner scriptRunner = new ScriptRunner()) {
scriptRunner.run("test", new File("src/test/resources/bsh-test"), "failed", buildContext(), fileLogger);
- } catch (ScriptEvaluationException e) {
- catchedException = e;
+ fail();
+ } catch (ScriptEvaluationException expected) {
+ String logContent = new String(Files.readAllBytes(logFile.toPath()));
+ assertTrue(logContent.contains(new File("src/test/resources/bsh-test/failed.bsh").getPath()));
+ assertEquals(logContent, mirrorHandler.getLoggedMessage());
}
-
- assertNotNull(catchedException);
- String logContent = new String(Files.readAllBytes(logFile.toPath()));
- assertTrue(logContent.contains(new File("src/test/resources/bsh-test/failed.bsh").getPath()));
- assertEquals(logContent, mirrorHandler.getLoggedMessage());
}
@Test
void beanshellReturnedNotTrueShouldThrowException() throws Exception {
File logFile = new File(tempDir, "build.log");
-
TestMirrorHandler mirrorHandler = new TestMirrorHandler();
- ScriptReturnException catchedException = null;
-
try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler);
ScriptRunner scriptRunner = new ScriptRunner()) {
scriptRunner.run("test", new File("src/test/resources/bsh-test"), "return-not-true", null, fileLogger);
- } catch (ScriptReturnException e) {
- catchedException = e;
+ fail();
+ } catch (ScriptReturnException expected) {
+ assertEquals("Not true value", expected.getResult());
+ assertEquals("The test returned Not true value.", expected.getMessage());
+ String logContent = new String(Files.readAllBytes(logFile.toPath()));
+ assertTrue(logContent.contains(new File("src/test/resources/bsh-test/return-not-true.bsh").getPath()));
+ assertEquals(logContent, mirrorHandler.getLoggedMessage());
}
-
- assertEquals("Not true value", catchedException.getResult());
- assertEquals("The test returned Not true value.", catchedException.getMessage());
- String logContent = new String(Files.readAllBytes(logFile.toPath()));
- assertTrue(logContent.contains(new File("src/test/resources/bsh-test/return-not-true.bsh").getPath()));
- assertEquals(logContent, mirrorHandler.getLoggedMessage());
}
@Test
@@ -181,45 +173,34 @@ class ScriptRunnerTest {
@Test
void failedGroovyShouldCreateProperLogsMessage() throws Exception {
File logFile = new File(tempDir, "build.log");
-
TestMirrorHandler mirrorHandler = new TestMirrorHandler();
- Exception catchedException = null;
-
try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler);
ScriptRunner scriptRunner = new ScriptRunner()) {
scriptRunner.run("test", new File("src/test/resources/groovy-test"), "failed", buildContext(), fileLogger);
- } catch (ScriptEvaluationException e) {
- catchedException = e;
+ } catch (ScriptEvaluationException expected) {
+ String logContent = new String(Files.readAllBytes(logFile.toPath()));
+ assertTrue(logContent.contains(new File("src/test/resources/groovy-test/failed.groovy").getPath()));
+ assertEquals(logContent, mirrorHandler.getLoggedMessage());
}
-
- assertNotNull(catchedException);
- String logContent = new String(Files.readAllBytes(logFile.toPath()));
- assertTrue(logContent.contains(new File("src/test/resources/groovy-test/failed.groovy").getPath()));
- assertEquals(logContent, mirrorHandler.getLoggedMessage());
}
@Test
void groovyReturnedFalseShouldThrowException() throws Exception {
File logFile = new File(tempDir, "build.log");
-
TestMirrorHandler mirrorHandler = new TestMirrorHandler();
- ScriptReturnException catchedException = null;
-
try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler);
ScriptRunner scriptRunner = new ScriptRunner()) {
scriptRunner.run(
"test", new File("src/test/resources/groovy-test"), "return-false", buildContext(), fileLogger);
- } catch (ScriptReturnException e) {
- catchedException = e;
+ } catch (ScriptReturnException expected) {
+ assertEquals(false, expected.getResult());
+ assertEquals("The test returned false.", expected.getMessage());
+ String logContent = new String(Files.readAllBytes(logFile.toPath()));
+ assertTrue(logContent.contains(new File("src/test/resources/groovy-test/return-false.groovy").getPath()));
+ assertEquals(logContent, mirrorHandler.getLoggedMessage());
}
-
- assertEquals(false, catchedException.getResult());
- assertEquals("The test returned false.", catchedException.getMessage());
- String logContent = new String(Files.readAllBytes(logFile.toPath()));
- assertTrue(logContent.contains(new File("src/test/resources/groovy-test/return-false.groovy").getPath()));
- assertEquals(logContent, mirrorHandler.getLoggedMessage());
}
@Test