<?xml version="1.0" encoding="UTF-8"?>
<test-data
    xmlns="http://pmd.sourceforge.net/rule-tests"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
    <test-code>
        <description><![CDATA[
missing argument
        ]]></description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>9</expected-linenumbers>
        <code><![CDATA[
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Foo {
	private static final Logger LOGGER = LoggerFactory.getLogger(Foo.class);

	public void call() {
		final String oneArg = "one argument";
		LOGGER.error("forget the arg {} and {}", oneArg);
	}
}
        ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
too many arguments
         ]]></description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>9</expected-linenumbers>
        <code><![CDATA[
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Foo {
	private static final Logger LOGGER = LoggerFactory.getLogger(Foo.class);
	private final String MESSAGE = "too many args {}";

	public void call() {
		LOGGER.error(MESSAGE, "arg1", "arg2");
	}
}
         ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Logger without problems
        ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Foo {
	private static final Logger LOGGER = LoggerFactory.getLogger(Foo.class);

	public void call() {
		final String message = "expected {} argument";
		LOGGER.error(message, 1);
	}
}
        ]]></code>
    </test-code>
    <test-code>
         <description><![CDATA[
ignore the exception param
        ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Foo {
	private static final Logger LOGGER = LoggerFactory.getLogger(Foo.class);

	public void call() {
		LOGGER.error("params {} and {}", "arg1", "arg2", new IllegalStateException("Extra arg"));
	}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Class cast exception with Method calls</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class MethodCallClassCastExceptionProblem {
    public void foo() {
        // a method call
        otherMethod();
    }

    private void otherMethod() {
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Null pointer with VariableNameDeclaration / VariableDeclaratorId</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class NullPointerTypeProblem {
    public void foo() {
        java.util.StringTokenizer st = new java.util.StringTokenizer("a.b.c.d", ".");
        while (st.hasMoreTokens()) {
            System.out.println(st.nextToken());
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1509 [java] InvalidSlf4jMessageFormat NPE</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
package my.test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Test {

    private static final Logger log = LoggerFactory.getLogger(Test.class);

    public static void main(String[] args) {
        log.info("1" + "2");
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1500 [java] InvalidSlf4jMessageFormat: doesn't ignore exception param</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class InvalidSlf4jExceptionTest {

    private static final Logger LOGGER = LoggerFactory.getLogger(InvalidSlf4jExceptionTest.class);

    public void foo() {
        try {
            throw new RuntimeException();
        } catch (RuntimeException e) {
            try {
                LOGGER.error("Exception was thrown during conversion from tc model: {}.", jsonMarshaller.marshall(tcmport));
            } catch (IOException e1) {
                LOGGER.error("Problem to marshall to json tcImport: {}", tcsTripImport, e1);
            }
            throw e;
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1541 [java] InvalidSlf4jMessageFormat: False positive with placeholder and exception</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class InvalidSl4jExceptionBug1541 {
    private static final Logger log = LoggerFactory.getLogger(InvalidSl4jExceptionBug1541.class);

    public static void main(String[] args) {
        try {
            // ...
        } catch (Exception e) {
            log.error("Arg1 = {}. Exception: {}", "arg1Value", e);
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1551 [java] InvalidSlf4jMessageFormat: fails with NPE</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestBug1551
{
    private static final Logger LOGGER = LoggerFactory.getLogger(TestBug1551.class);

    public void test()
    {
        String message = generateMessage();
        LOGGER.info(message);
    }

    private String generateMessage()
    {
        return "message";
    }
}
        ]]></code>
    </test-code>
    
    <test-code>
        <description>#365 [java] InvalidSlf4jMessageFormat: false positive with pre-incremented variable</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Foo
{
    private static final Logger LOGGER = LoggerFactory.getLogger(Foo.class);

    public void test()
    {
        int attempt = 0;
        LOGGER.info("test (attempt #{})", ++attempt);
    }
}
        ]]></code>
    </test-code>
    
    <test-code>
        <description>#721 NPE in PMD 5.8.1 InvalidSlf4jMessageFormat</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
            import org.slf4j.Logger;
        
            public class LoggerHelper {
                public LoggerHelper(String loggerName) {
                    Logger logger = LoggerFactory.getLogger(loggerName);
                    logger.info(message);
                }
            }
        ]]></code>
    </test-code>
    
    
</test-data>