Search in sources :

Example 1 with TestLoggingReporter

use of com.puppycrawl.tools.checkstyle.internal.testmodules.TestLoggingReporter in project checkstyle by checkstyle.

the class RegexpMultilineCheckTest method testStateIsBeingReset.

/**
 * Done as a UT cause new instance of Detector is created each time 'verify' executed.
 *
 * @throws Exception some Exception
 */
@Test
public void testStateIsBeingReset() throws Exception {
    final TestLoggingReporter reporter = new TestLoggingReporter();
    final DetectorOptions detectorOptions = DetectorOptions.newBuilder().reporter(reporter).format("\\r").maximum(1).build();
    final MultilineDetector detector = new MultilineDetector(detectorOptions);
    final File file = File.createTempFile("junit", null, temporaryFolder);
    Files.write(file.toPath(), "first line \r\n second line \n\r third line".getBytes(StandardCharsets.UTF_8));
    detector.processLines(new FileText(file, StandardCharsets.UTF_8.name()));
    detector.processLines(new FileText(file, StandardCharsets.UTF_8.name()));
    assertWithMessage("Logged unexpected amount of issues").that(reporter.getLogCount()).isEqualTo(2);
}
Also used : TestLoggingReporter(com.puppycrawl.tools.checkstyle.internal.testmodules.TestLoggingReporter) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with TestLoggingReporter

use of com.puppycrawl.tools.checkstyle.internal.testmodules.TestLoggingReporter in project checkstyle by checkstyle.

the class RegexpSinglelineCheckTest method testStateIsBeingReset.

/**
 * Done as a UT cause new instance of Detector is created each time 'verify' executed.
 *
 * @throws Exception some Exception
 */
@Test
public void testStateIsBeingReset() throws Exception {
    final String illegal = "System\\.(out)|(err)\\.print(ln)?\\(";
    final TestLoggingReporter reporter = new TestLoggingReporter();
    final DetectorOptions detectorOptions = DetectorOptions.newBuilder().reporter(reporter).format(illegal).maximum(1).build();
    final SinglelineDetector detector = new SinglelineDetector(detectorOptions);
    final File file = new File(getPath("InputRegexpSinglelineSemantic8.java"));
    detector.processLines(new FileText(file, StandardCharsets.UTF_8.name()));
    detector.processLines(new FileText(file, StandardCharsets.UTF_8.name()));
    assertWithMessage("Logged unexpected amount of issues").that(reporter.getLogCount()).isEqualTo(0);
}
Also used : TestLoggingReporter(com.puppycrawl.tools.checkstyle.internal.testmodules.TestLoggingReporter) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

FileText (com.puppycrawl.tools.checkstyle.api.FileText)2 TestLoggingReporter (com.puppycrawl.tools.checkstyle.internal.testmodules.TestLoggingReporter)2 File (java.io.File)2 Test (org.junit.jupiter.api.Test)2