Issue #2434: Inconvenience to debug UTs after recent changes in BaseCheckTestSupport

This commit is contained in:
Roman Ivanov 2015-10-24 06:41:10 -07:00
parent 3a2cb4d787
commit 189da7314d
1 changed files with 28 additions and 4 deletions

View File

@ -19,7 +19,7 @@
package com.puppycrawl.tools.checkstyle;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
@ -141,14 +141,37 @@ public class BaseCheckTestSupport {
messageFileName, expected);
}
/**
* We keep two verify methods with separate logic only for convenience of debuging
* We have minimum amount of multi-file test cases
*/
protected void verify(Checker checker,
File[] processedFiles,
String messageFileName,
String... expected)
throws Exception {
final Map<String, List<String>> expectedMessages = new HashMap<>(1);
expectedMessages.put(messageFileName, asList(expected));
verify(checker, processedFiles, expectedMessages);
stream.flush();
final List<File> theFiles = Lists.newArrayList();
Collections.addAll(theFiles, processedFiles);
final int errs = checker.process(theFiles);
// process each of the lines
final ByteArrayInputStream inputStream =
new ByteArrayInputStream(stream.toByteArray());
try (final LineNumberReader lnr = new LineNumberReader(
new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
for (int i = 0; i < expected.length; i++) {
final String expectedResult = messageFileName + ":" + expected[i];
final String actual = lnr.readLine();
assertEquals("error message " + i, expectedResult, actual);
}
assertEquals("unexpected output: " + lnr.readLine(),
expected.length, errs);
}
checker.destroy();
}
protected void verify(Checker checker,
@ -160,6 +183,7 @@ public class BaseCheckTestSupport {
Collections.addAll(theFiles, processedFiles);
final int errs = checker.process(theFiles);
// process each of the lines
final Map<String, List<String>> actualViolations = getActualViolations(errs);
final Map<String, List<String>> realExpectedViolations =
Maps.filterValues(expectedViolations, new Predicate<List<String>>() {