<?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>returning a HashSet, bad</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>3</expected-linenumbers>
        <code><![CDATA[
import java.util.HashSet;
public class Foo {
    HashSet foo() {
        return new HashSet();
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>returning a Map, OK</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.Map;
import java.util.HashMap;
public class Foo {
    Map getFoo() {
        return new HashMap();
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>no problemo</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    void foo() {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>returning a set</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.*;
public class Foo {
    Set fooSet = new HashSet(); // OK
    Set foo() {
        return fooSet;
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>field declared of type HashSet</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
import java.util.HashSet;
public class Foo {
    HashSet fooSet = new HashSet(); // NOT OK
}
        ]]></code>
    </test-code>

    <test-code>
        <description>field, return type both HashSet</description>
        <expected-problems>2</expected-problems>
        <code><![CDATA[
import java.util.HashSet;
public class Foo {
    HashSet fooSet = new HashSet(); // NOT OK
    HashSet foo() { // NOT OK
        return fooSet;
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>two fields</description>
        <expected-problems>2</expected-problems>
        <code><![CDATA[
import java.util.HashSet;
import java.util.HashMap;
public class Foo {
    HashSet fooSet = new HashSet();
    HashMap fooMap = new HashMap();
}
        ]]></code>
    </test-code>

    <test-code>
        <description>method param is HashMap</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
import java.util.HashMap;
public class Foo {
    void foo(HashMap bar) {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Vector could be List</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
import java.util.*;
public class Foo {
    public void foo(Vector bar) {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ArrayList could be List</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
import java.util.*;
public class Foo {
    public void foo(ArrayList bar) {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#938 False positive on LooseCoupling for overriding methods</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.LinkedHashMap;

public class Test {
    @Override
    public LinkedHashMap findGetters() {}
}
        ]]></code>
    </test-code>
    <test-code>
        <description>FP with method reference</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.HashMap;

public class Test {
    private static final ThreadLocal TREE_CACHE =
            ThreadLocal.withInitial(HashMap::new);
}
        ]]></code>
    </test-code>
    <test-code>
        <description>FP with instanceof and cast</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.*;

public class Test {
    boolean m(Map m) {
        if (m instanceof HashMap) {
            return ((HashMap) m).isEmpty();
        }
        return false;
    }
}
        ]]></code>
    </test-code>
    <test-code>
        <description>FP with static method call</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.HashMap;
import java.util.Map;

public class MyMap implements Map {
    static Map create() { return null; }
}

class Foo {
    final Map map =
            MyMap.create();
}
        ]]></code>
    </test-code>
    <test-code>
        <description>FP with array creation</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.*;

public class MyMap implements Map { }

class Foo {
    final Map[] map = new MyMap[5]; // ok
}
        ]]></code>
    </test-code>
    <test-code>
        <description>FP with j.util.Properties</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.Properties;

class Foo {
    final Properties map = new Properties();
}
        ]]></code>
    </test-code>
    <test-code>
        <description>Exception list, no exception</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
package mine;
import java.util.List;

class O implements List {
    final O map = new O();
}
        ]]></code>
    </test-code>
    <test-code>
        <description>Exception list</description>
        <rule-property name="allowedTypes">mine.O</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
package mine;
import java.util.List;

class O implements List {
    final O map = new O();
}
        ]]></code>
    </test-code>
    <test-code>
        <description>#2464 class literals</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.ArrayList;

class Foo {
    final Object o = ArrayList.class;
}
        ]]></code>
    </test-code>
    <test-code>
        <description>Inner class selection</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.AbstractMap;

class Foo {
    final Object o =
            new AbstractMap.SimpleEntry<>("", "");
}
        ]]></code>
    </test-code>
    <test-code>
        <description>Extends clause</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.AbstractMap;

class Foo extends AbstractMap<String, String> {

}
        ]]></code>
    </test-code>
    <test-code>
        <description>This/super qualifier</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.ArrayList;

class Foo extends ArrayList {

    {
        Foo.super.clear();
    }

    class Inner {
        {
            Foo.this.clear();
            Foo.super.clear();
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Verify with nested (local) classes</description>
        <expected-problems>3</expected-problems>
        <expected-linenumbers>6,11,15</expected-linenumbers>
        <code><![CDATA[
import java.util.HashSet;
public class Foo {
    void firstMethod() { }
    void myMethod() {
        class Inner {
            HashSet foo() {
                return new HashSet();
            }
        }
        Object o = new Object() {
            HashSet foo() { return new HashSet(); }
        };
    }
    class Nested {
        HashSet foo() {
            return new HashSet();
        }
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>False positive with generics #3672</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.Collection;
import java.util.Set;
public final class Foo<A, B extends Collection<A>> {
    private final Set<? super B> things;
}
        ]]></code>
    </test-code>
</test-data>
