package com.puppycrawl.tools.checkstyle;

import com.puppycrawl.tools.checkstyle.checks.HeaderCheck;
import com.puppycrawl.tools.checkstyle.checks.RegexpHeaderCheck;
import com.puppycrawl.tools.checkstyle.CheckstyleException;

public class HeaderCheckTest extends BaseCheckTestCase
{
    public void testStaticHeader()
            throws Exception
    {
        final CheckConfiguration checkConfig = new CheckConfiguration();
        checkConfig.setClassname(HeaderCheck.class.getName());
        checkConfig.addProperty("headerFile", getPath("java.header"));
        checkConfig.addProperty("ignoreLines", "");
        final Checker c = createChecker(checkConfig);
        final String fname = getPath("inputHeader.java");
        final String[] expected = {
            "1: Missing a header - not enough lines in file."
        };
        verify(c, fname, expected);
    }

    public void testRegexpHeader()
        throws Exception
    {
        final CheckConfiguration checkConfig = new CheckConfiguration();
        checkConfig.setClassname(RegexpHeaderCheck.class.getName());
        checkConfig.addProperty("headerFile", getPath("regexp.header"));
        checkConfig.addProperty("ignoreLines", "4,5");
        final Checker c = createChecker(checkConfig);
        final String fname = getPath("InputScopeAnonInner.java");
        final String[] expected = {
            "3: Line does not match expected header line of '// Created: 2002'."
        };
        verify(c, fname, expected);
    }

    public void testRegexpHeaderIgnore()
        throws Exception
    {
        final CheckConfiguration checkConfig = new CheckConfiguration();
        checkConfig.setClassname(RegexpHeaderCheck.class.getName());
        checkConfig.addProperty("headerFile", getPath("regexp.header"));
        checkConfig.addProperty("ignoreLines", "3,4,5");
        final Checker c = createChecker(checkConfig);
        final String fname = getPath("InputScopeAnonInner.java");
        final String[] expected = {
        };
        verify(c, fname, expected);
    }

    public void testNoHeader()
        throws Exception
    {
        final CheckConfiguration checkConfig = new CheckConfiguration();
        checkConfig.setClassname(HeaderCheck.class.getName());
        // No header file specified
        final Checker c = createChecker(checkConfig);
        final String fname = getPath("InputScopeAnonInner.java");

        // TODO: Is this really what we want or should we throw an Exception?
        // Somehow checking nothing doesn't make too much sense...
        final String[] expected = {
        };

        verify(c, fname, expected);
    }

    public void testIllegalArgs()
            throws Exception
    {
        final CheckConfiguration checkConfig = new CheckConfiguration();
        checkConfig.setClassname(HeaderCheck.class.getName());
        checkConfig.addProperty("headerFile", getPath("nonexisting.file"));
        try {
            createChecker(checkConfig);
            fail();
        }
        catch (CheckstyleException ex) {
            // expected exception
        }
    }

}

@@ -2418,180 +2418,95 @@
     
-// TODO: Is this really what we want or should we throw an Exception?%0A        // Somehow checking nothing doesn't make too much sense...%0A        final String%5B%5D expected = %7B
+final String%5B%5D expected = %7B%0A            %221: Unable to check as missing lines to check.%22
 %0A   

Fix broken test - sorry about that.