<?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">

    <code-fragment id="basic-violation"><![CDATA[
public class Foo {
    public void example() {
        Integer x = 0;
        Integer a = 0;
        Integer b = 0;
        Integer c = 0;
        Integer d = 0;
        Integer a1 = 0;
        Integer a2 = 0;
        Integer b1 = 0;
        Integer b2 = 0;
        Integer z = 0;
        Integer h = 0;
        Integer e = 0;
        Integer f = 0;

        if (a == b) {
            if (a1 == b1) {
                x = 2;
            } else if (a2 == b2) {
                x = 2;
            } else {
                x = 2;
            }
        } else if (c == d) {
            while (c == d) {
                x = 2;
            }
        } else if (e == f) {
            for (Integer n = 0; n < h; n++) {
                x = 2;
            }
        } else {
            // taken out switch with 4 cases
        }
    }
}
    ]]></code-fragment>

    <test-code>
        <description>Simple method</description>
        <rule-property name="reportLevel">1</rule-property>
        <expected-problems>2</expected-problems>
        <expected-messages>
            <message>The class 'Foo' has a Standard Cyclomatic Complexity of 2 (Highest = 1).</message>
            <message>The method 'foo' has a Standard Cyclomatic Complexity of 1.</message>
        </expected-messages>
        <code><![CDATA[
public class Foo {
    public void foo() {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Simple trigger</description>
        <rule-property name="reportLevel">1</rule-property>
        <expected-problems>2</expected-problems>
        <code><![CDATA[
trigger Accounts on Account (before insert, after insert, before update, after update, before delete, after delete) {
    fflib_SObjectDomain.triggerHandler(Accounts.class);
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Simple enum</description>
        <rule-property name="reportLevel">1</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public enum Day {
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
    THURSDAY, FRIDAY, SATURDAY
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Simple interface</description>
        <rule-property name="reportLevel">1</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public interface Foo {
    void fuu();
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Complicated method</description>
        <rule-property name="reportLevel">1</rule-property>
        <expected-problems>2</expected-problems>
        <expected-messages>
            <message>The class 'Foo' has a Standard Cyclomatic Complexity of 9 (Highest = 8).</message>
            <message>The method 'example' has a Standard Cyclomatic Complexity of 8.</message>
        </expected-messages>
        <code-ref id="basic-violation"/>
    </test-code>

    <test-code>
        <description>Constructor</description>
        <rule-property name="reportLevel">1</rule-property>
        <expected-problems>2</expected-problems>
        <expected-messages>
            <message>The class 'Foo' has a Standard Cyclomatic Complexity of 2 (Highest = 1).</message>
            <message>The constructor 'Foo' has a Standard Cyclomatic Complexity of 1.</message>
        </expected-messages>
        <code><![CDATA[
public class Foo {
    public Foo() {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Testing new parameter showClassesComplexity</description>
        <rule-property name="reportLevel">1</rule-property>
        <rule-property name="showClassesComplexity">false</rule-property>
        <expected-problems>1</expected-problems>
        <code-ref id="basic-violation"/>
    </test-code>

    <test-code>
        <description>Testing new parameter showMethodsMethods</description>
        <rule-property name="reportLevel">1</rule-property>
        <rule-property name="showMethodsComplexity">false</rule-property>
        <expected-problems>1</expected-problems>
        <code-ref id="basic-violation"/>
    </test-code>

    <test-code>
        <description>Testing default value of showClassMethods and showClassesComplexity</description>
        <rule-property name="reportLevel">1</rule-property>
        <expected-problems>2</expected-problems>
        <code-ref id="basic-violation"/>
    </test-code>

    <code-fragment id="constructor-violation"><![CDATA[
public class Test {
    public Test() {
        if (a == 1) {
            if (b == 2) {
                System.out.println('b');
            } else if (b == 1) {
            }
        } else {
        }
    }
}
    ]]></code-fragment>

    <test-code>
        <description>#984 Cyclomatic complexity should treat constructors like methods: 1 - showMethodsComplexity=true</description>
        <rule-property name="showClassesComplexity">false</rule-property>
        <rule-property name="showMethodsComplexity">true</rule-property>
        <rule-property name="reportLevel">1</rule-property>
        <expected-problems>1</expected-problems>
        <code-ref id="constructor-violation"/>
    </test-code>

    <test-code>
        <description>#984 Cyclomatic complexity should treat constructors like methods: 2 - showMethodsComplexity=false</description>
        <rule-property name="showClassesComplexity">false</rule-property>
        <rule-property name="showMethodsComplexity">false</rule-property>
        <rule-property name="reportLevel">1</rule-property>
        <expected-problems>0</expected-problems>
        <code-ref id="constructor-violation"/>
    </test-code>

    <test-code>
        <description>StdCyclomaticComplexity for triggers</description>
        <rule-property name="reportLevel">1</rule-property>
        <expected-problems>3</expected-problems>
        <expected-messages>
            <message>The method 'invoke' has a Standard Cyclomatic Complexity of 4.</message>
            <message>The trigger 'Accounts' has a Standard Cyclomatic Complexity of 4 (Highest = 4).</message>
            <message>The method 'anotherMethod' has a Standard Cyclomatic Complexity of 3.</message>
        </expected-messages>
        <code><![CDATA[
trigger Accounts on Account (before insert, before update, before delete, after insert, after update, after delete, after undelete) {
    for(Account acc : Trigger.new) {
        if(Trigger.isInsert) {
            // ...
        }

        // ...

        if(Trigger.isDelete) {
            // ...
        }
    }

    void anotherMethod(Integer i) {
        if (i == 1) {
        } else if (i == 2) {
        }
    }
}
]]></code>
    </test-code>
</test-data>
