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

    <!-- Begin Schema method invocations -->
    <test-code>
        <description>High cost performance getGlobalDescribe in loop (correct code) #4675</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void testGetGlobalDescribe() {
        Map<String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap();
        Set<String> fieldNameSet = new Set<String> {'Id'};

        for (String fieldNameOrDefaultValue : fieldNameOrDefaultValueList) {
            if (fieldMap.containsKey(fieldNameOrDefaultValue.trim())) {
                fieldNameSet.add(fieldNameOrDefaultValue);
            }
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>High cost performance getGlobalDescribe in loop #4675</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>5</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public void testGetGlobalDescribe() {
        Set<String> fieldNameSet = new Set<String> {'Id'};
        for (String fieldNameOrDefaultValue : fieldNameOrDefaultValueList) {
            if (Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap().containsKey(fieldNameOrDefaultValue.trim() )) {
                fieldNameSet.add(fieldNameOrDefaultValue);
            }
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>High cost performance getGlobalDescribe in loop - fully qualified #4675</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>5</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public void testGetGlobalDescribe() {
        Set<String> fieldNameSet = new Set<String> {'Id'};
        for (String fieldNameOrDefaultValue : fieldNameOrDefaultValueList) {
            if (System.Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap().containsKey(fieldNameOrDefaultValue.trim() )) {
                fieldNameSet.add(fieldNameOrDefaultValue);
            }
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>High cost performance describeSObjects in loop (correct code) #4675</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void testDescribeSObjects() {
        Map<String, Schema.SObjectField> fieldMap = Schema.describeSObjects(new List<String> { 'Account' })[0].fields.getMap();
        Set<String> fieldNameSet = new Set<String> {'Id'};
        for (String fieldNameOrDefaultValue : fieldNameOrDefaultValueList) {
            if (fieldMap.containsKey(fieldNameOrDefaultValue.trim())) {
                fieldNameSet.add(fieldNameOrDefaultValue);
            }
        }
    }
}
            ]]></code>
    </test-code>

    <test-code>
        <description>High cost performance describeSObjects in loop #4675</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>6</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public void testDescribeSObjects() {
        String sObjectType = 'Account';
        Set<String> fieldNameSet = new Set<String> {'Id'};
        for (String fieldNameOrDefaultValue : fieldNameOrDefaultValueList) {
            if (Schema.describeSObjects(new List<String> { sObjectType })[0].fields.getMap().containsKey(fieldNameOrDefaultValue.trim())) {
                fieldNameSet.add(fieldNameOrDefaultValue);
            }
        }
    }
}
            ]]></code>
    </test-code>

    <test-code>
        <description>High cost performance describeSObjects in loop with SObjectDescribeOptions #4675</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>6</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public void testDescribeSObjects() {
        String sObjectType = 'Account';
        Set<String> fieldNameSet = new Set<String> {'Id'};
        for (String fieldNameOrDefaultValue : fieldNameOrDefaultValueList) {
            if (Schema.describeSObjects(new List<String> { sObjectType }, SObjectDescribeOptions.FULL)[0].fields.getMap().containsKey(fieldNameOrDefaultValue.trim())) {
                fieldNameSet.add(fieldNameOrDefaultValue);
            }
        }
    }
}
            ]]></code>
    </test-code>

    <test-code>
        <description>High cost performance describeSObjects in loop - fully qualified #4675</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>6</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public void testDescribeSObjects() {
        String sObjectType = 'Account';
        Set<String> fieldNameSet = new Set<String> {'Id'};
        for (String fieldNameOrDefaultValue : fieldNameOrDefaultValueList) {
            if (System.Schema.describeSObjects(new List<String> { sObjectType })[0].fields.getMap().containsKey(fieldNameOrDefaultValue.trim())) {
                fieldNameSet.add(fieldNameOrDefaultValue);
            }
        }
    }
}
            ]]></code>
    </test-code>
    <!-- End Schema method invocations -->

    <test-code>
        <description>#5139 [apex] OperationWithHighCostInLoop not firing in triggers</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>4</expected-linenumbers>
        <code><![CDATA[
trigger AccountTrigger on Account (before insert, before update) {
    integer i = 0;
    for (i = 0; i <15; i++) {
        SObjectType token = Schema.getGlobalDescribe().get('Account');
    }
}
]]></code>
    </test-code>
</test-data>
