<?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>Test property defaults</description>
        <expected-problems>4</expected-problems>
        <expected-messages>
            <message>The field name 'Foo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The final field name 'Hoo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The static field name 'Bar' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The constant name 'BOLGaaa_FIELD' doesn't match '[A-Z][A-Z_0-9]*'</message>
        </expected-messages>
        <code><![CDATA[
public class Bar {

    int Foo;
    final int Hoo;
    static int Bar;
    static final int BOLGaaa_FIELD;
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Test default field property</description>
        <rule-property name="defaultFieldPattern">[A-Z][A-Z0-9]+</rule-property>
        <expected-problems>3</expected-problems>
        <expected-messages>
            <message>The field name 'Foo' doesn't match '[A-Z][A-Z0-9]+'</message>
            <message>The final field name 'Hoo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The static field name 'Bar' doesn't match '[a-z][a-zA-Z0-9]*'</message>
        </expected-messages>
        <code><![CDATA[
public class Bar {

    int Foo;
    final int Hoo;
    static int Bar;
    static final int BOLG_FIELD;

}
        ]]></code>
    </test-code>

    <test-code>
        <description>Test final field property</description>
        <rule-property name="finalFieldPattern">[A-Z][A-Z0-9]+</rule-property>
        <expected-problems>3</expected-problems>
        <expected-messages>
            <message>The field name 'Foo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The final field name 'Hoo' doesn't match '[A-Z][A-Z0-9]+'</message>
            <message>The static field name 'Bar' doesn't match '[a-z][a-zA-Z0-9]*'</message>
        </expected-messages>
        <code><![CDATA[
public class Bar {

    int Foo;
    final int Hoo;
    static int Bar;
    static final int BOLG_FIELD;
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Test static field property</description>
        <rule-property name="staticFieldPattern">[A-Z][A-Z0-9]+</rule-property>
        <expected-problems>3</expected-problems>
        <expected-messages>
            <message>The field name 'Foo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The final field name 'Hoo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The static field name 'Bar' doesn't match '[A-Z][A-Z0-9]+'</message>
        </expected-messages>
        <code><![CDATA[
public class Bar {

    int Foo;
    final int Hoo;
    static int Bar;
    static final int BOLG_FIELD;
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Test constant field property</description>
        <rule-property name="constantPattern">cons_[A-Z][A-Z0-9]+</rule-property>
        <expected-problems>4</expected-problems>
        <expected-messages>
            <message>The field name 'Foo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The final field name 'Hoo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The static field name 'Bar' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The constant name 'BOLG_FIELD' doesn't match 'cons_[A-Z][A-Z0-9]+'</message>
        </expected-messages>
        <code><![CDATA[
public class Bar {

    int Foo;
    final int Hoo;
    static int Bar;
    static final int BOLG_FIELD;
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Test enum constant property</description>
        <rule-property name="enumConstantPattern">cons_[A-Z][A-Z0-9]+</rule-property>
        <expected-problems>2</expected-problems>
        <expected-messages>
            <message>The enum constant name 'ORG' doesn't match 'cons_[A-Z][A-Z0-9]+'</message>
            <message>The enum constant name 'NET' doesn't match 'cons_[A-Z][A-Z0-9]+'</message>
        </expected-messages>
        <code><![CDATA[
public class Bar {

    enum AnEnum {
        ORG, NET, cons_COM;
    }

}
        ]]></code>
    </test-code>

    <test-code>
        <description>Test public constant property</description>
        <rule-property name="publicConstantPattern">cons_[A-Z][A-Z0-9]+</rule-property>
        <expected-problems>5</expected-problems>
        <expected-messages>
            <message>The field name 'Foo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The final field name 'Hoo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The static field name 'Bar' doesn't match '[a-z][a-zA-Z0-9]*'</message>
            <message>The constant name 'cons_BOLG_FIELD' doesn't match '[A-Z][A-Z_0-9]*'</message>
            <message>The public constant name 'DDD' doesn't match 'cons_[A-Z][A-Z0-9]+'</message>
        </expected-messages>
        <code><![CDATA[
public class Bar {

    int Foo;
    final int Hoo;
    static int Bar;
    static final int cons_BOLG_FIELD;
    public static final int DDD;
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Interface fields should be treated like public constants</description>
        <expected-problems>3</expected-problems>
        <expected-messages>
            <message>The public constant name 'Foo' doesn't match '[A-Z][A-Z_0-9]*'</message>
            <message>The public constant name 'Hoo' doesn't match '[A-Z][A-Z_0-9]*'</message>
            <message>The public constant name 'Bar' doesn't match '[A-Z][A-Z_0-9]*'</message>
        </expected-messages>
        <code><![CDATA[
public interface Bar {

    int Foo;
    final int Hoo;
    static int Bar;
    static final int BOLG_FIELD;
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Exclude serialVersionUID by default</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class MyException extends RuntimeException {

    private static final long serialVersionUID = -8134636876462178354L;


    public MyException(String message, Throwable cause) {
        super(message, cause);
    }


    public MyException(String message) {
        super(message);
    }

}
        ]]></code>
    </test-code>

    <test-code>
        <description>Exclude serialPersistentFields by default</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.io.*;
import java.util.*;
public class Foo implements Serializable {

    List next;

    private static final ObjectStreamField[] serialPersistentFields = {new ObjectStreamField("next", List.class)};

}
        ]]></code>
    </test-code>

    <test-code>
        <description>More exclusions can be configured</description>
        <rule-property name="exclusions">m$mangled,serialVersionUID</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class MyException {
    private static final long serialVersionUID = -8134636876462178354L;
    private static final long m$mangled = -8134636876462178354L;

}
        ]]></code>
    </test-code>
    <test-code>
        <description>[java] FieldNamingConventions: false positive with lombok's @UtilityClass #4455</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import lombok.experimental.UtilityClass;
public  class Foo {
    @UtilityClass
    public class Test1 {
        private final String FINAL_F = "final_field";  // should not report a warning
    }
    public class Test2 {
        private static final String FINAL_F = "final_field";  // report no warning
    }
}
        ]]></code>
    </test-code>
</test-data>
