<?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>Bad, very deep</description>
        <rule-property name="problemDepth">3</rule-property>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        Integer x=2;
        Integer y=3;
        Integer z=4;
        if (x>y) {
            if (y>z) {
                if (z==x) {
                    // this is officially out of control now
                }
            }
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>OK, not so deep</description>
        <rule-property name="problemDepth">3</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        if (true) {
        } else if (true) {
        } else if (true) {
        } else {
            // this ain't good code, but it shouldn't trigger this rule
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Bad, many deep ifs</description>
        <rule-property name="problemDepth">3</rule-property>
        <expected-problems>4</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        if (true) {
            if (true) {
                if (true) {
                }
            }
            if(true) {
                if(true) {
                    if(true) {
                    }
                }
                if(true) {
                }
                if(true) {
                }
            }
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>nested ifs with else if</description>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>5,7</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public void bar(Integer x, Integer y, Integer z) {
        if (x>y) {
            if (y>z) {
                if (z==x) { // violation 1
                    // !! too deep
                } else if (z == 42) { // violation 2
                    // !! too deep
                }
            }
        }
    }
}
]]></code>
    </test-code>

    <test-code>
        <description>if statements within trigger (#5138)</description>
        <rule-property name="problemDepth">3</rule-property>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>11,14</expected-linenumbers>
        <code><![CDATA[
// https://github.com/SalesforceLabs/Partner-Onboarding/blob/main/Partner%20Onboarding/triggers/AccountTrigger.trigger
trigger AccountTrigger on Account (after insert, after update) {

    public List<Account> updatedAccounts = Trigger.new;
    if(trigger.isAfter){
        Map<Id,Account> mapOfOldValues = trigger.oldMap;
        Map<Id,Id> accountWithOnboardingTemplateIDs = new Map<Id,Id>();
        for(Account updated_Account : updatedAccounts) {
            if(updated_Account.Onboarding_Plan__c != null)
            {
                if(mapOfOldValues == null){
                    accountWithOnboardingTemplateIDs.put(updated_Account.Id, updated_Account.Onboarding_Plan__c);
                } else {
                    if(updated_Account.Onboarding_Plan__c != mapOfOldValues.get(updated_Account.Id).Onboarding_Plan__c)
                        accountWithOnboardingTemplateIDs.put(updated_Account.Id, updated_Account.Onboarding_Plan__c);
                }
            }
        } //End For

        if(accountWithOnboardingTemplateIDs.size() > 0){
            OnboardingPlanService.updateContactsWithOndbPlan(accountWithOnboardingTemplateIDs);
        }
    }
}
]]></code>
    </test-code>
</test-data>
