apache / apache/maven-script-interpreter

Tests don't properly note that expected exception wasn't thrown

Open Beginner friendly
#210 0 comments 0 reactions 0 assignees View on GitHub
maintenance
Dominant language
Java
Stars
14
Forks
9
Avg merge
5d 15h
Merged PRs (30d)
2

Description

### Affected version

HEAD

### Bug description

Needs to fail in the try block and move assertions into catch block. One example of what we need to fix:

```
@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;
}

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());
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the test method beanshellReturnedNotTrueShouldThrowException and similar exception tests in the test sources. Run the relevant test suite, then adjust the tests so an absent expected exception causes failure and the result, message, and logging assertions are checked only after the exception is caught; confirm the suite passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.