<?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>Few public fields</description>
        <rule-property name="minimum">50</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public Integer foo;
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Too many public fields</description>
        <rule-property name="minimum">2</rule-property>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
    public Integer foo;
    public Integer bif;
    public Integer baz;
    public Integer bof;
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Static final</description>
        <rule-property name="minimum">1</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public static final Integer foo;
    public static final Integer foo1;
    public static final Integer foo2;
    public static final Integer foo3;
}
        ]]></code>
    </test-code>

    <code-fragment id="id-3-public-methods"><![CDATA[
public class Foo {
    public Integer foo1() {return 1;}
    public Integer foo2() {return 1;}
    public Integer foo3() {return 1;}
}
    ]]></code-fragment>

    <test-code>
        <description>Some public methods</description>
        <rule-property name="minimum">50</rule-property>
        <expected-problems>0</expected-problems>
        <code-ref id="id-3-public-methods"/>
    </test-code>

    <test-code>
        <description>Reduced minimum</description>
        <rule-property name="minimum">2</rule-property>
        <expected-problems>1</expected-problems>
        <code-ref id="id-3-public-methods"/>
    </test-code>

    <test-code>
        <description>Private fields</description>
        <rule-property name="minimum">50</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    private static final Integer foo;
    private static final Integer foo1;
    private static final Integer foo2;
    private static final Integer foo3;
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Private methods</description>
        <rule-property name="minimum">50</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    private Integer foo1() {return 1;}
    private Integer foo2() {return 1;}
    private Integer foo3() {return 1;}
}
        ]]></code>
    </test-code>

    <test-code>
       <description>#1396 Class with javadoc</description>
       <expected-problems>0</expected-problems>
       <code><![CDATA[
/**
 * Class comment
 */
public class SomeClass {

    /**
     * Comment
     */
    public void doSomething() {
        System.debug('hello world');
    }

    /** Field comment */
    private String field;
}
       ]]></code>
    </test-code>

    <test-code>
        <description>#4509 class with inner classes</description>
        <rule-property name="minimum">1</rule-property>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>1,5</expected-linenumbers>
        <expected-messages>
            <message>The class OuterClass has 2 public methods, attributes, and properties (limit: 1)</message>
            <message>The class InnerClass has 4 public methods, attributes, and properties (limit: 1)</message>
        </expected-messages>
        <code><![CDATA[
public class OuterClass {
    public int outerField1;
    public int outerField2;

    public class InnerClass {
        public String field1;
        public int field2;

        public void method1() { }
        public void method2() { }
    }
}
]]></code>
    </test-code>
    
    <test-code>
        <description>[apex] ExcessivePublicCount ignores properties #4596</description>
        <rule-property name="minimum">4</rule-property>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>1</expected-linenumbers>
        <expected-messages>
            <message>The class Example has 4 public methods, attributes, and properties (limit: 4)</message>
        </expected-messages>
        <code><![CDATA[
public class Example {
    public void publicMethod1() { }             // count: 1
    public Integer publicField;                 // count: 2
    public String publicProperty1 {get; set; }  // count: 3
    public String publicProperty2 {             // count: 4
        get {
            return publicProperty2;
        }
        set {
            publicProperty2 = value;
        }
    }
    private String privateProperty1 {get; set;}
}
]]></code>
    </test-code>
</test-data>
