<?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 - no assert calls</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
@isTest
public class Foo {
   public static testMethod void testSomething() {
      Account a = null;
      // This is better than having a NullPointerException
      // System.assertNotEquals(a, null, 'account not found');
      a.toString();
   }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1543 [apex] ApexUnitTestClassShouldHaveAsserts assumes APEX is case sensitive</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
@isTest
public class Foo {
   public static testMethod void testSomething() {
      Account a = null;
      SYSTEM.AssertNotEquals(a, null, 'account not found');
   }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1521 [apex] ApexUnitTestClassShouldHaveAsserts: Parsing error on APEX class: expected one element but was: &lt;BlockStatement, BlockStatement&gt;</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
@isTest
private class C2_Assignment_Report_Job_Test {

    public static testMethod void testCreateAssignmentsForDifferentRoles() {
        User u = C2_Test_Utils.getWFUser('testWfc', true);
        System.runAs(u) {
            C2_Assignment_Report_Data_Aggregate_Job job = new C2_Assignment_Report_Data_Aggregate_Job();
            String query = job.start(null).getQuery();
            C2_Receiver_Unit__c ru = new C2_Receiver_Unit__c(Name='RU1');
            insert ru;
            List<C2_Case__c> cases = new List<C2_Case__c>();
            cases.add(new C2_Case__c(Name='TT0000000', Queue__c = 'PA-CSA', Status__c=C2_Case_Util.STATUS_NEW, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
            cases.add(new C2_Case__c(Name='TT0000001', Queue__c = 'PA-CSA', Status__c=C2_Case_Util.STATUS_NEW, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
            cases.add(new C2_Case__c(Name='TT0000002', Queue__c = 'PA-CSA', Status__c=C2_Case_Util.STATUS_NEW, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
            cases.add(new C2_Case__c(Name='TT0000011', Queue__c = 'DSA', Status__c=C2_Case_Util.STATUS_PACSA_COMPLETE, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
            cases.add(new C2_Case__c(Name='TT0000012', Queue__c = 'DSA', Status__c=C2_Case_Util.STATUS_PACSA_COMPLETE, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
            cases.add(new C2_Case__c(Name='TT0000021', Queue__c = 'QR-CSA', Status__c=C2_Case_Util.STATUS_DSA_COMPLETE, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
            insert cases;
            List<C2_Case__c> scope = Database.query(query);
            Test.startTest();
            job.execute(null, scope);
            Test.stopTest();
            List<C2_Case_Assign_Report_Data__c> caseEventEntries =
                    [select Num_Cases_Assign__c, Num_Cases_Not_Completed__c, Num_Cases_Reassigned__c, Num_Cases_Completed__c, User__c, Role__c
                    from C2_Case_Assign_Report_Data__c];
            System.assertEquals(3, caseEventEntries.size());
            Map<String, Integer> userIdWithRole2ReportData = getCaseEventEntriesMap(caseEventEntries);
            System.assertEquals(3, userIdWithRole2ReportData.get(createUserRoleKey(u.Id, 'PA-CSA')));
            System.assertEquals(2, userIdWithRole2ReportData.get(createUserRoleKey(u.Id, 'DSA')));
            System.assertEquals(1, userIdWithRole2ReportData.get(createUserRoleKey(u.Id, 'QR-CSA')));
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1089 [apex] ApexUnitTestClassShouldHaveAsserts: Verify use of additionalAssertMethodPattern, positive test</description>
        <rule-property name="additionalAssertMethodPattern">(MyAssert\.\w+|verify\w+)</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
@isTest
public class Foo {
   public static testMethod void testAssertIsTrue() {
      MyAssert.isTrue(someCondition);
   }

   public static testMethod void testLocalVerify() {
      verifyState();
   }

   private static void verifyState() {
   }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1089 [apex] ApexUnitTestClassShouldHaveAsserts: Verify use of additionalAssertMethodPattern, negative test</description>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>3,7</expected-linenumbers>
        <code><![CDATA[
@isTest
public class Foo {
   public static testMethod void testAssertIsTrue() {
      MyAssert.isTrue(someCondition);
   }

   public static testMethod void testLocalVerify() {
      verifyState();
   }

   private static void verifyState() {
   }
}
        ]]></code>
    </test-code>

    <test-code>
      <description>[apex] ApexUnitTestClassShouldHaveAssertsRule: 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);
   }

   @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>
