/*
 * Created by IntelliJ IDEA.
 * User: lk
 * Date: Sep 22, 2002
 * Time: 8:06:12 AM
 * To change template for new class use
 * Code Style | Class Templates options (Tools | IDE Options).
 */
package com.puppycrawl.tools.checkstyle;

import java.io.IOException;
import java.io.LineNumberReader;
import java.io.FileReader;
import java.io.Reader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Properties;
import java.lang.reflect.InvocationTargetException;

import junit.framework.TestCase;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessages;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
import org.apache.regexp.RESyntaxException;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;

public class BaseCheckTestCase
    extends TestCase
{
    /** a brief logger that only display info about errors */
    protected static class BriefLogger
        extends DefaultLogger
    {
        public BriefLogger(OutputStream out)
        {
            super(out, true);
        }
        public void auditStarted(AuditEvent evt) {}
        public void fileFinished(AuditEvent evt) {}
        public void fileStarted(AuditEvent evt) {}
    }

    private final ByteArrayOutputStream mBAOS = new ByteArrayOutputStream();
    private final PrintStream mStream = new PrintStream(mBAOS);
    protected final Properties mProps = new Properties();

    public BaseCheckTestCase(String aName)
    {
        super(aName);
    }

    protected Checker createChecker(CheckConfiguration aCheckConfig)
        throws RESyntaxException, FileNotFoundException, IOException,
        ParserConfigurationException, SAXException, ClassNotFoundException,
        InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
    {
        final Checker c = new Checker(new Configuration(mProps, mStream),
                                      new CheckConfiguration[] {aCheckConfig});
        final AuditListener listener = new BriefLogger(mStream);
        c.addListener(listener);
        return c;
    }

    protected static String getPath(String aFilename)
        throws IOException
    {
        final File f = new File(System.getProperty("testinputs.dir"),
                                aFilename);
        return f.getCanonicalPath();
    }

    protected void verify(Checker aC, String aFilename, String[] aExpected)
        throws Exception
    {
        mStream.flush();
        final int errs = aC.processNEW(new String[] {aFilename});

        // process each of the lines
        final ByteArrayInputStream bais =
            new ByteArrayInputStream(mBAOS.toByteArray());
        final LineNumberReader lnr =
            new LineNumberReader(new InputStreamReader(bais));

        for (int i = 0; i < aExpected.length; i++) {
            assertEquals(aFilename + ":" + aExpected[i], lnr.readLine());
        }
        assertEquals(aExpected.length, errs);
        aC.destroy();
    }
}

@@ -1,399 +1,72 @@
-/*%0A * Created by IntelliJ IDEA.%0A * User: lk%0A * Date: Sep 22, 2002%0A * Time: 8:06:12 AM%0A * To change template for new class use%0A * Code Style %7C Class Templates options (Tools %7C IDE Options).%0A */%0Apackage com.puppycrawl.tools.checkstyle;%0A%0Aimport java.io.IOException;%0Aimport java.io.LineNumberReader;%0Aimport java.io.FileReader;%0Aimport java.io.Reader;%0Aimport java.io.BufferedReader;%0Aimport java.io.Out
+package com.puppycrawl.tools.checkstyle;%0A%0Aimport java.io.ByteArrayIn
 putS
@@ -114,36 +114,8 @@
 am;%0A
-import java.io.PrintStream;%0A
 impo
@@ -184,36 +184,27 @@
 java.io.
-ByteArrayInputStream
+IOException
 ;%0Aimport
@@ -247,51 +247,84 @@
 ava.
-util.ArrayList;%0Aimport java.util.Properties
+io.LineNumberReader;%0Aimport java.io.OutputStream;%0Aimport java.io.PrintStream
 ;%0Aim
@@ -373,25 +373,24 @@
 eption;%0A
-%0A
 import j
 unit.fra
@@ -385,207 +385,115 @@
 rt j
-unit.framework.TestCase;%0Aimport com.puppycrawl.tools.checkstyle.api.DetailAST;%0Aimport com.puppycrawl.tools.checkstyle.api.LocalizedMessages;%0Aimport com.puppycrawl.tools.checkstyle.api.LocalizedMessag
+ava.util.Properties;%0Aimport javax.xml.parsers.ParserConfigurationException;%0A%0Aimport junit.framework.TestCas
 e;%0Ai
@@ -573,70 +573,23 @@
 n;%0A%0A
-import javax.xml.parsers.ParserConfigurationException;%0A%0Apublic
+public abstract
  cla

make class abstract so IDEA's JUnit integration knows that this is not a test to be run