<?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>Problematic apex unit test assert statements - assert should have 2/3 params</description>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>5,7</expected-linenumbers>
        <code><![CDATA[
@isTest
public class Foo {
     @isTest
    static void methodATest() {
        System.assertNotEquals('123', o.StageName); // not good
        System.assertEquals('123', o.StageName, 'Opportunity stageName is wrong.'); // good
        System.assert(o.isClosed); // not good
        System.assert(o.isClosed, 'Opportunity is not closed.'); // good
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>[apex] assert should have 2 param and assertEquals should have 3 param.</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
@isTest
public class Foo {
     @isTest
    static void methodATest() {
        System.assertEquals('Test opportunity', o.Name, 'Opportunity Name' + o.Name + 'is wrong.'); // good
        System.assert(o.isClosed, 'Opportunity is not closed.'); // good
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>[apex] Avoid false positive in non test classes.</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    static void methodA() {
        System.assertEquals('Test opportunity', o.Name);
        System.assert(o.isClosed);
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>[apex] Support new Assert class (Apex v56.0) #4097</description>
         <expected-problems>0</expected-problems>
         <code><![CDATA[
@isTest
public class Foo {
    @isTest
    static void testAreEqual() {
        String sub = 'abcde'.substring(2);
        Assert.areEqual('cde', sub, 'Expected characters after first two');
   }

    @isTest
    static void testAreNotEqual() {
        String sub = 'abcde'.substring(2);
        Assert.areNotEqual('xyz', sub, 'Characters not expected after first two');
   }

    @isTest
    static void testFail() {
        try {
            SomeClass.methodUnderTest();
            Assert.fail('DmlException Expected');
        } catch (DmlException ex) {
            // Add assertions here about the expected exception
        }
   }

    @isTest
    static void testIsFalse() {
        Boolean containsCode = 'Salesforce'.contains('code');
        Assert.isFalse(containsCode, 'No code');
   }

    @isTest
    static void testIsInstanceOf() {
        Account o = new Account();
        Assert.isInstanceOfType(o, Account.class, 'Wrong instance');
   }

    @isTest
    static void testIsNotInstanceOf() {
        Contact con = new Contact();
        Assert.isNotInstanceOfType(con, Account.class, 'Not expected type');
   }

    @isTest
    static void testIsNotNull() {
        String myString = 'value';
        Assert.isNotNull(myString, 'myString should not be null');
   }

    @isTest
    static void testIsNull() {
        String myString = null;
        Assert.isNull(myString, 'String should be null');
   }

    @isTest
    static void testIsTrue() {
        Boolean containsForce = 'Salesforce'.contains('force');
        Assert.isTrue(containsForce, 'Contains force');
   }
}
        ]]></code>
   </test-code>

    <test-code>
        <description>[apex] Support new Assert class (Apex v56.0) - negative test case #4097</description>
        <expected-problems>9</expected-problems>
        <expected-linenumbers>6,12,19,28,34,40,46,52,58</expected-linenumbers>
        <code><![CDATA[
@isTest
public class Foo {
    @isTest
    static void testAreEqual() {
        String sub = 'abcde'.substring(2);
        Assert.areEqual('cde', sub);
   }

    @isTest
    static void testAreNotEqual() {
        String sub = 'abcde'.substring(2);
        Assert.areNotEqual('xyz', sub);
   }

    @isTest
    static void testFail() {
        try {
            SomeClass.methodUnderTest();
            Assert.fail();
        } catch (DmlException ex) {
            // Add assertions here about the expected exception
        }
   }

    @isTest
    static void testIsFalse() {
        Boolean containsCode = 'Salesforce'.contains('code');
        Assert.isFalse(containsCode);
   }

    @isTest
    static void testIsInstanceOf() {
        Account o = new Account();
        Assert.isInstanceOfType(o, Account.class);
   }

    @isTest
    static void testIsNotInstanceOf() {
        Contact con = new Contact();
        Assert.isNotInstanceOfType(con, Account.class);
   }

    @isTest
    static void testIsNotNull() {
        String myString = 'value';
        Assert.isNotNull(myString);
   }

    @isTest
    static void testIsNull() {
        String myString = null;
        Assert.isNull(myString);
   }

    @isTest
    static void testIsTrue() {
        Boolean containsForce = 'Salesforce'.contains('force');
        Assert.isTrue(containsForce);
   }
}
        ]]></code>
    </test-code>
</test-data>
