Fix PMD CloseResource - BaseCLITest has actually setup/tearDown

which deals with restoring System.out/err already
This commit is contained in:
Andreas Dangel
2022-03-03 11:11:57 +01:00
parent 07504b1002
commit 2aebcbd1de

View File

@ -107,20 +107,13 @@ public abstract class BaseCLITest {
* Returns the log output.
*/
protected String runTest(int expectedExitCode, String... args) {
PrintStream oldOut = System.out;
PrintStream oldErr = System.err;
try {
ByteArrayOutputStream console = new ByteArrayOutputStream();
PrintStream out = new PrintStream(console);
System.setOut(out);
System.setErr(out);
StatusCode statusCode = PMD.runPmd(args);
assertEquals(expectedExitCode, statusCode.toInt());
return console.toString();
} finally {
System.setOut(oldOut);
System.setOut(oldErr);
}
ByteArrayOutputStream console = new ByteArrayOutputStream();
PrintStream out = new PrintStream(console);
System.setOut(out);
System.setErr(out);
StatusCode statusCode = PMD.runPmd(args);
assertEquals(expectedExitCode, statusCode.toInt());
return console.toString();
}
@Deprecated