<?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>bad</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        int x = 2;
        if ((x = getX()) == 3) {
            System.out.println("3!");
        }
    }
    private int getX() {
        return 3;
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ok</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        if (false) {}
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>assignment in if conditional expression</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        if (false) {
            int x =2;
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>assignment in while conditional expression</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        int x = 2;
        while ( (x = getX()) != 0 ) {}
    }
    private int getX() {return 2;}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ok</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        for (int i = 0; i < 10; i++) {
            int x = i;
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>assignment in for conditional expression</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        for (int i = 0; (i = i + 1) < 10; i++) {
            int x = i;
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>increment in if conditional expression</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        int x = 0;
        if (x++ > 0) {
            x = 2;
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>assignment in while conditional expression, allowed</description>
        <rule-property name="allowWhile">true</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        int x = 2;
        while ( (x = getX()) != 0 ) {}
    }
    private int getX() {return 2;}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>assignment in if conditional expression, allowed</description>
        <rule-property name="allowIf">true</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        int x = 2;
        if ((x = getX()) == 3) {
            System.out.println("3!");
        }
    }
    private int getX() {
        return 3;
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>assignment in for conditional expression, allowed</description>
        <rule-property name="allowFor">true</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        for (int i = 0; (i = i + 1) < 10; i++) {
            int x = i;
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>increment in if conditional expression, allowed</description>
        <rule-property name="allowIncrementDecrement">true</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void bar() {
        int x = 0;
        if (x++ > 0) {
            x = 2;
        }
    }
}
        ]]></code>
    </test-code>
</test-data>
