Skip to content

Commit 787f065

Browse files
pbludovrnveach
authored andcommitted
Issue #7391: mute System.{err,out} in tests
1 parent f0af108 commit 787f065

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
<dependency>
272272
<groupId>org.itsallcode</groupId>
273273
<artifactId>junit5-system-extensions</artifactId>
274-
<version>1.0.3</version>
274+
<version>1.1.0</version>
275275
<scope>test</scope>
276276
</dependency>
277277
<!-- till https://github.com/checkstyle/checkstyle/issues/7368 -->

src/test/java/com/puppycrawl/tools/checkstyle/JavadocPropertiesGeneratorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ protected final String getNonCompilablePath(String filename) throws IOException
8888
*/
8989
@BeforeEach
9090
public void setUp(@SysErr Capturable systemErr, @SysOut Capturable systemOut) {
91-
systemErr.capture();
92-
systemOut.capture();
91+
systemErr.captureMuted();
92+
systemOut.captureMuted();
9393
}
9494

9595
@Test

src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ private static String getFilePath(String filename) throws IOException {
177177
*/
178178
@BeforeEach
179179
public void setUp(@SysErr Capturable systemErr, @SysOut Capturable systemOut) {
180-
systemErr.capture();
181-
systemOut.capture();
180+
systemErr.captureMuted();
181+
systemOut.captureMuted();
182182

183183
LOG.setLevel(ORIGINAL_LOG_LEVEL);
184184

src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheckTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.itsallcode.io.Capturable;
4242
import org.itsallcode.junit.sysextensions.SystemErrGuard;
4343
import org.itsallcode.junit.sysextensions.SystemErrGuard.SysErr;
44+
import org.junit.jupiter.api.BeforeEach;
4445
import org.junit.jupiter.api.Test;
4546
import org.junit.jupiter.api.extension.ExtendWith;
4647
import org.junit.jupiter.api.io.TempDir;
@@ -64,6 +65,19 @@ protected String getPackageLocation() {
6465
return "com/puppycrawl/tools/checkstyle/checks/javadoc/abstractjavadoc";
6566
}
6667

68+
/**
69+
* <p>Configures the environment for each test.</p>
70+
* <ul>
71+
* <li>Start output capture for {@link System#err}</li>
72+
* </ul>
73+
*
74+
* @param systemErr wrapper for {@code System.err}
75+
*/
76+
@BeforeEach
77+
public void setUp(@SysErr Capturable systemErr) {
78+
systemErr.captureMuted();
79+
}
80+
6781
@Test
6882
public void testJavadocTagsWithoutArgs() throws Exception {
6983
final DefaultConfiguration checkconfig = createModuleConfig(TempCheck.class);
@@ -112,7 +126,6 @@ public void testCustomTag() throws Exception {
112126

113127
@Test
114128
public void testParsingErrors(@SysErr Capturable systemErr) throws Exception {
115-
systemErr.capture();
116129
final DefaultConfiguration checkConfig = createModuleConfig(TempCheck.class);
117130
final String[] expected = {
118131
"4: " + getCheckMessage(MSG_JAVADOC_MISSED_HTML_CLOSE, 4, "unclosedTag"),
@@ -135,7 +148,6 @@ public void testWithMultipleChecks() throws Exception {
135148

136149
@Test
137150
public void testAntlrError(@SysErr Capturable systemErr) throws Exception {
138-
systemErr.capture();
139151
final DefaultConfiguration checkConfig = createModuleConfig(TempCheck.class);
140152
final String[] expected = {
141153
"4: " + getCheckMessage(MSG_JAVADOC_PARSE_RULE_ERROR, 78,
@@ -148,7 +160,6 @@ public void testAntlrError(@SysErr Capturable systemErr) throws Exception {
148160
@Test
149161
public void testCheckReuseAfterParseErrorWithFollowingAntlrErrorInTwoFiles(
150162
@SysErr Capturable systemErr) throws Exception {
151-
systemErr.capture();
152163
final DefaultConfiguration checkConfig = createModuleConfig(TempCheck.class);
153164
final Map<String, List<String>> expectedMessages = new LinkedHashMap<>(2);
154165
expectedMessages.put(getPath("InputAbstractJavadocParsingErrors.java"), asList(

0 commit comments

Comments
 (0)