<?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>Fail, BigInteger(1)</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>4</expected-linenumbers>
        <code><![CDATA[
import java.math.BigInteger;

public class Foo {
    BigInteger b = new BigInteger("1");
}
        ]]></code>
        <source-type>java 1.4</source-type>
    </test-code>

    <test-code>
        <description>Pass, BigInteger(10)</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.math.BigInteger;

public class Foo {
    BigInteger b = new BigInteger("10");
}
        ]]></code>
        <source-type>java 1.4</source-type>
    </test-code>

    <test-code>
        <description>Fail, BigInteger(0)</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>4</expected-linenumbers>
        <code><![CDATA[
import java.math.BigInteger;

public class Foo {
    BigInteger b = new BigInteger("0");
}
        ]]></code>
        <source-type>java 1.4</source-type>
    </test-code>

    <test-code>
        <description>Pass, BigDecimal(i - 1)</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.math.BigDecimal;

public class Foo {
    int i = 42;
    BigDecimal b = new BigDecimal(i - 1);
}
        ]]></code>
        <source-type>java 1.4</source-type>
    </test-code>

    <test-code>
        <description>Pass, BigInteger("10") and BigDecimal in 1.4 mode</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.math.BigInteger;
import java.math.BigDecimal;

public class Foo {
    void test14() {
        BigInteger b = new BigInteger("10");
        BigDecimal d;
        d = new BigDecimal(0);
        d = new BigDecimal(1);
        d = new BigDecimal(10);
        d = new BigDecimal("0");
        d = new BigDecimal("1");
        d = new BigDecimal("10");
    }
}
        ]]></code>
        <source-type>java 1.4</source-type>
    </test-code>

    <test-code>
        <description>Fail, BigInteger(10) 1.5 mode</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>4</expected-linenumbers>
        <code><![CDATA[
import java.math.BigInteger;

public class Foo {
    BigInteger b = new BigInteger("10");
}
        ]]></code>
        <source-type>java 1.5</source-type>
    </test-code>

    <test-code>
        <description>Fail, BigDecimal(1)</description>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>4,5</expected-linenumbers>
        <code><![CDATA[
import java.math.BigDecimal;

public class Foo {
    BigDecimal b1 = new BigDecimal(1);
    BigDecimal b2 = new BigDecimal("1");
}
        ]]></code>
        <source-type>java 1.5</source-type>
    </test-code>

    <test-code>
        <description>Fail, BigDecimal(10)</description>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>4,5</expected-linenumbers>
        <code><![CDATA[
import java.math.BigDecimal;

public class Foo {
    BigDecimal b1 = new BigDecimal(10);
    BigDecimal b2 = new BigDecimal("10");
}
        ]]></code>
        <source-type>java 1.5</source-type>
    </test-code>

    <test-code>
        <description>Fail, BigDecimal(0)</description>
        <expected-problems>3</expected-problems>
        <expected-linenumbers>4,5,6</expected-linenumbers>
        <code><![CDATA[
import java.math.BigDecimal;

public class Foo {
    BigDecimal b1 = new BigDecimal(0);
    BigDecimal b2 = new BigDecimal("0");
    BigDecimal b3 = new BigDecimal("0.");
    BigDecimal b4 = new BigDecimal("0.0"); // that's not ZERO - ZERO has no decimals, this has 1 decimal (scale)
}
        ]]></code>
        <source-type>java 1.5</source-type>
    </test-code>

    <test-code>
        <description>Fail, BigInteger(2) with Java9</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>4</expected-linenumbers>
        <code><![CDATA[
import java.math.BigInteger;

public class Foo {
    BigInteger b = new BigInteger("2"); // Use BigInteger.TWO instead
}
        ]]></code>
        <source-type>java 9</source-type>
    </test-code>

    <test-code>
        <description>False negative with indirect const string</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>5</expected-linenumbers>
        <code><![CDATA[
import java.math.BigInteger;

class Foo {
    static final String Z = "0";
    static { new BigInteger(Z); }

    public void test(String a) {
        new BigInteger(a); // not a const value
    }
}
        ]]></code>
    </test-code>
    
    <test-code>
        <description>[java] BigIntegerInstantiation: False Positive with Java 17 and BigDecimal.TWO #4886</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.math.BigDecimal;

class Foo {
    static {
        new BigDecimal("2");
    }
}
]]></code>
        <source-type>java 17</source-type>
    </test-code>

    <test-code>
        <description>[java] BigIntegerInstantiation: BigDecimal.TWO with Java 19 #4886</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
import java.math.BigDecimal;

class Foo {
    static {
        new BigDecimal("2");
    }
}
]]></code>
        <source-type>java 19</source-type>
    </test-code>
</test-data>
