<?xml version="1.0" encoding="UTF-8"?>
<test-data>
    <test-code>
        <description><![CDATA[
premature declaration before unrelated test
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Bar {
	public int lengthSumOf(String[] strings) {
		
		int sum = 0;	// wasted cycles if strings have problems
		
		if (strings == null || strings.length == 0) return 0;
		
		for (int i=0; i<strings.length; i++) {
			sum += strings[i].length();
		}
		
		return sum;
	}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
optimal var declaration position
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Bar {
	public int lengthSumOf(String[] strings) {
				
		if (strings == null || strings.length == 0) return 0;
				
		int sum = 0;	// optimal placement
		
		for (int i=0; i<strings.length; i++) {
			sum += strings[i].length();
		}
		
		return sum;
	}
}
     ]]></code>
    </test-code>

    <test-code>
        <description>Bug #1064 Exception running PrematureDeclaration</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Bar {
    public int lengthSumOf(String[] strings) {

        if (strings == null || strings.length == 0) return 0;

        @SuppressWarnings("unchecked") Integer sum = 0; // optimal placement

        for (int i=0; i<strings.length; i++) {
            sum += strings[i].length();
        }

        return sum;
    }
}
     ]]></code>
    </test-code>

    <test-code>
        <description>#1305 variable declaration inside switch causes ClassCastException</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class PrematureDeclarationClassCastException {
    public void bar() {
        int switchvar = 0;
        switch (switchvar) {
            case 1:
                boolean localvar;
                break;
            case 2:
                localvar = false;
                if (localvar) {
                    //
                }
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1396 PrematureDeclaration lambda false positive</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class PrematureDeclarationLambda {
    public int lengthSumOf() {
        int sum = 0;
        Runnable r = () -> { return; };
        r.run();
        return sum;
    }
}
        ]]></code>
    </test-code>
</test-data>
