<?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>Failure case: Empty Catch Block</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>5</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public void bar() {
        try {
            system.debug(1);
        } catch(Exception e) {
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Success case: Empty Catch Block</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void foo() {
        try {
            system.debug(1);
        } catch(Exception e) {
            system.debug(e);
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#3569 - Verify use of allowExceptionNameRegex, negative test unspecified</description>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>7,16</expected-linenumbers>
        <code><![CDATA[
@IsTest
private class FunctionalityTest {
    static testMethod void testWithModifier() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception e) {
        }
    }

    @IsTest
    static void testWithAnnotation() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception e) {
        }
    }
}
]]></code>
    </test-code>

    <test-code>
        <description>#3569 - Verify use of allowExceptionNameRegex, negative test specified</description>
        <rule-property name="allowExceptionNameRegex">ignoreMe</rule-property>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>7,16</expected-linenumbers>
        <code><![CDATA[
@IsTest
private class FunctionalityTest {
    static testMethod void testWithModifier() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception expected) {
        }
    }

    @IsTest
    static void testWithAnnotation() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception ignored) {
        }
    }
}
]]></code>
    </test-code>

    <test-code>
        <description>#3569 - Verify use of allowExceptionNameRegex, positive test unspecified</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
@IsTest
private class FunctionalityTest {
    static testMethod void testWithModifier() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception expected) {
        }
    }

    @IsTest
    static void testWithAnnotation() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception ignored) {
        }
    }
}
]]></code>
    </test-code>

    <test-code>
        <description>#3569 - Verify use of allowExceptionNameRegex, positive test specified</description>
        <rule-property name="allowExceptionNameRegex">ignoreMe</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
@IsTest
private class FunctionalityTest {
    static testMethod void testWithModifier() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception ignoreMe) {
        }
    }

    @IsTest
    static void testWithAnnotation() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception ignoreMe) {
        }
    }
}
]]></code>
    </test-code>

    <test-code>
        <description>#3569 - Verify use of allowCommentedBlocks, negative test unspecified/default</description>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>7,17</expected-linenumbers>
        <code><![CDATA[
@IsTest
private class FunctionalityTest {
    static testMethod void testWithModifier() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception e) {
            // Expected
        }
    }

    @IsTest
    static void testWithAnnotation() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception e) {
            // Expected
        }
    }
}
]]></code>
    </test-code>

    <test-code>
        <description>#3569 - Verify use of allowCommentedBlocks, negative test specified</description>
        <rule-property name="allowCommentedBlocks">false</rule-property>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>7,17</expected-linenumbers>
        <code><![CDATA[
@IsTest
private class FunctionalityTest {
    static testMethod void testWithModifier() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception e) {
            // Expected
        }
    }

    @IsTest
    static void testWithAnnotation() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception e) {
            // Expected
        }
    }
}
]]></code>
    </test-code>

    <test-code>
        <description>#3569 - Verify use of allowCommentedBlocks, positive test</description>
        <rule-property name="allowCommentedBlocks">true</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
@IsTest
private class FunctionalityTest {
    static testMethod void testWithModifier() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception e) { // Expected
        }
    }

    @IsTest
    static void testWithAnnotation() {
        try {
            doSomethingThatShouldThrowAnException();
            System.assert(false, 'Expected an exception to be thrown.');
        } catch (Exception e) {
            // Expected
        }
    }
}
]]></code>
    </test-code>

    <code-fragment id="with-comments"><![CDATA[
@IsTest
private class FunctionalityTest {
    static testMethod void testWithModifier() {
        ///////////////////////////////
        //  eol comments
        ///////////////////////////////
        try {
        } catch (Exception e) {
          // OK: eol comment inside of empty catch block; should not be reported
        }

        try {
        } catch (Exception e) { // OK: eol comment inside of empty catch block, same line as begin; should not be reported
        }

        try {
        }
        // NOK: eol comment outside empty catch block; should be reported
        catch (Exception e) {
        }

        try {
        } catch (Exception e) {
        } // NOK: eol comment outside of catch block; should be reported

        ///////////////////////////////
        // block comments
        ///////////////////////////////
        try {
        } catch (Exception e) {
          /* OK: block comment inside of empty catch block; should not be reported */
        }

        try {
        } catch (Exception e) {
          /* OK: block comment inside of empty catch block;
           * multiple lines
           * should not be reported
           */
        }

        try {
        } catch (Exception e) { /* OK: block comment inside of empty catch block, same line as begin; should not be reported */
        }

        try {
        } catch (Exception e) {
        /* OK: block comment inside of empty catch block, same line as end; should not be reported */ }

        try {
        } catch (Exception e) { /* OK: block comment inside catch block, same line as begin/end; should be reported */ }

        try {
        } /* NOK: block comment outside of catch block; should be reported */ catch (Exception e) {
        }

        try {
        } catch (Exception e) {
        } /* NOK: block comment outside of catch block; should be reported */

        ///////////////////////////////
        //  doc comments
        ///////////////////////////////
        try {
        } catch (Exception e) {
          /** OK: doc comment inside of empty catch block; should be reported */
        }

        try {
        } catch (Exception e) {
          /** OK: doc comment inside of empty catch block;
           * multiple lines
           * should be reported
           */
        }

        try {
        } catch (Exception e) { /** OK: doc comment inside of empty catch block, same line as begin; should be reported */
        }

        try {
        } catch (Exception e) {
        /** OK: doc comment inside of empty catch block, same line as end; should be reported */ }

        try {
        } catch (Exception e) { /** OK: doc comment inside catch block, same line as begin/end; should be reported */ }
    }
}
    ]]></code-fragment>

    <test-code>
        <description>#3569 - Verify use of allowCommentedBlocks=false</description>
        <rule-property name="allowCommentedBlocks">false</rule-property>
        <expected-problems>16</expected-problems>
        <expected-linenumbers>8,13,19,23,30,35,43,47,51,54,58,65,70,78,82,86</expected-linenumbers>
        <code-ref id="with-comments"/>
    </test-code>

    <test-code>
        <description>#3569 - Verify use of allowCommentedBlocks=true, binary search boundaries verification</description>
        <rule-property name="allowCommentedBlocks">true</rule-property>
        <expected-problems>4</expected-problems>
        <expected-linenumbers>19,23,54,58</expected-linenumbers>
        <code-ref id="with-comments"/>
    </test-code>
</test-data>
