<?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>simple failure</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
    void bar() {
        try {} catch (Exception e) {}
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ok</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    void bar() {
        try {} catch (RuntimeException e) {e.getMessage();}
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>no catch with nested catch in finally</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
    void foo() {
        try {
        } finally {
            try {
                int x =2;
            } catch (Exception e) {}
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>multiple catch blocks</description>
        <expected-problems>2</expected-problems>
        <code><![CDATA[
public class Foo {
    void foo() {
        try {
        } catch (Exception e) {
        } catch (Throwable t) {
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>empty try with finally</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    void foo() {
        try {
        } catch (Exception e) {
            ;
        } finally {}
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>InterruptedException is not OK - changed behavior in PMD7</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>7</expected-linenumbers>
        <code><![CDATA[
            public class Foo {
                void foo() {
                    try {
                    } catch (InterruptedException ignored) {}

                    try {
                    } catch (InterruptedException notok) {}
                }
            }
            ]]></code>
    </test-code>
    <test-code>
        <description>CloneNotSupportedException is not OK - changed behavior in PMD7</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>7</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    void foo() {
        try {
        } catch (CloneNotSupportedException ignored) {}

        try {
        } catch (CloneNotSupportedException notok) {}
    }
}
        ]]></code>
    </test-code>

    <!-- Catch blocks - with/without allowCommentedBlocks -->
    <test-code>
        <description>empty block is not OK with allowCommentedBlocks</description>
        <rule-property name="allowCommentedBlocks">true</rule-property>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
    void bar() {
        try {} catch (Exception e) {}
    }
}
]]></code>
    </test-code>
    <code-fragment id="single-line-comment"><![CDATA[
public class Foo {
    void bar() {
        try {
        } catch (Exception e) { // Commented
        }
    }
}
    ]]></code-fragment>

    <test-code>
        <description>single-line comment is not OK</description>
        <expected-problems>1</expected-problems>
        <code-ref id="single-line-comment"/>
    </test-code>

    <test-code>
        <description>single-line comment is OK with allowCommentedBlocks</description>
        <rule-property name="allowCommentedBlocks">true</rule-property>
        <expected-problems>0</expected-problems>
        <code-ref id="single-line-comment"/>
    </test-code>

    <code-fragment id="multiple-line-comment"><![CDATA[
public class Foo {
    void bar() {
        try {
        } catch (Exception e) { /* Commented */
        }
    }
}
    ]]></code-fragment>

    <test-code>
        <description>multiple-line comment is not OK</description>
        <expected-problems>1</expected-problems>
        <code-ref id="multiple-line-comment"/>
    </test-code>

    <test-code>
        <description>multiple-line comment is OK with allowCommentedBlocks</description>
        <rule-property name="allowCommentedBlocks">true</rule-property>
        <expected-problems>0</expected-problems>
        <code-ref id="multiple-line-comment"/>
    </test-code>

    <code-fragment id="javadoc-comment"><![CDATA[
public class Foo {
    void bar() {
        try {
        } catch (Exception e) { /** Commented */
        }
    }
}
    ]]></code-fragment>

    <test-code>
        <description>Javadoc comment is not OK</description>
        <expected-problems>1</expected-problems>
        <code-ref id="javadoc-comment"/>
    </test-code>

    <test-code>
        <description>Javadoc comment is OK with allowCommentedBlocks</description>
        <rule-property name="allowCommentedBlocks">true</rule-property>
        <expected-problems>0</expected-problems>
        <code-ref id="javadoc-comment"/>
    </test-code>

    <!-- END Commented blocks -->
    <test-code>
        <description>Exceptions named "ignored" and "expected" are ignored by default</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    void foo() {
        try {
        } catch (NullPointerException expected) {
        } catch (IllegalArgumentException ignored) {
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Allow to ignore exceptions by name</description>
        <rule-property name="allowExceptionNameRegex">^idontcare$</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    void foo() {
        try {
        } catch (NullPointerException idontcare) {
        }
    }
}
        ]]></code>
    </test-code>
</test-data>
