New LogMessageExtractorCheck which writes out TXT report of all loggers
[yangtools.git] / common / checkstyle-logging / src / test / java / org / opendaylight / yangtools / checkstyle / CheckstyleTest.java
index 0fe027b0af2e46d23e622e620ce4af4ceba77b40..9c0342355b4c7da6239ef2ba59d42da9e7fa81fa 100644 (file)
@@ -11,7 +11,9 @@ package org.opendaylight.yangtools.checkstyle;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import com.google.common.base.Charsets;
 import com.google.common.collect.Lists;
+import com.google.common.io.Files;
 import com.puppycrawl.tools.checkstyle.Checker;
 import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
 import com.puppycrawl.tools.checkstyle.DefaultLogger;
@@ -21,6 +23,7 @@ import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
 import com.puppycrawl.tools.checkstyle.api.Configuration;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.util.List;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -55,29 +58,25 @@ public class CheckstyleTest {
     @Test
     public void testLoggerChecks() throws Exception {
         verify(CheckLoggingTestClass.class, true,
-                "15: Logger must be declared as private static final",
-                "15: Logger name should be LOG",
-                "15: LoggerFactory.getLogger Class argument is incorrect",
-                "17: Logger might be declared only once",
-                "16: Logger must be slf4j",
-                "22: Line contains printStacktrace",
-                "23: Line contains console output",
-                "24: Line contains console output",
-                "26: Log message placeholders count is incorrect",
-                "32: Log message placeholders count is incorrect",
-                "41: Log message contains string concatenation");
+                "16: Logger must be declared as private static final",
+                "16: Logger name should be LOG",
+                "16: LoggerFactory.getLogger Class argument is incorrect",
+                "18: Logger might be declared only once",
+                "17: Logger must be slf4j",
+                "27: Log message placeholders count is incorrect",
+                "36: Log message placeholders count is incorrect",
+                "45: Log message contains string concatenation");
     }
 
     @Test
-    public void testCodingChecks() throws Exception {
-        verify(CheckCodingStyleTestClass.class, false,
-                "9: Line has Windows line delimiter.",
-                "14: Wrong order for",
-                "24:1: Line contains a tab character.",
-                "22: Line has trailing spaces.",
-                "22: 'ctor def' child have incorrect indentation level 16, expected level should be 8.",
-                "17:8: Unused import",
-                "23: Line has trailing spaces.");
+    public void testLogMessageExtractorCheck() throws Exception {
+        File logMessageReport = LogMessageExtractorCheck.DEFAULT_REPORT_FILE;
+        logMessageReport.delete();
+        verify(CheckLoggingTestClass.class, false);
+        List<String> reportLines = Files.readLines(logMessageReport, Charsets.UTF_8);
+        assertEquals(6, reportLines.size());
+        assertEquals("src/test/java/org/opendaylight/yangtools/checkstyle/CheckLoggingTestClass.java:27:\"foo {} {}\"", reportLines.get(0));
+        // TODO assertEquals("src/test/java/org/opendaylight/yangtools/checkstyle/CheckLoggingTestClass.java:28:\"foo {} bar {}\"", reportLines.get(1));
     }
 
     private void verify(final Class<?> testClass, final boolean checkCount, final String... expectedMessages) throws CheckstyleException {