<?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">

    <code-fragment id="full-example"><![CDATA[

// Data class from ArgoUML
/**
* A property that can be displayed and edited within a PropertyTable.
*
* @author Jeremy Jones
**/
public class Property implements Comparable {

private String      _name;
private Class       _valueType;
private Object      _initialValue;
private Object      _currentValue;
private Object[]    _availableValues;

public Property(String name, Class valueType, Object initialValue) {
this(name, valueType, initialValue, null);
}


public Property(String name, Class valueType, Object initialValue, Object[] values) {
    _name = name;
    _valueType = valueType;
    _initialValue = initialValue;
    _availableValues = values;
    _currentValue = _initialValue;
}

public String getName() {
return _name;
}

public Class getValueType() {
return _valueType;
}

public Object getInitialValue() {
return _initialValue;
}

public Object[] getAvailableValues() {
return _availableValues;
}

public Object getCurrentValue() {
return _currentValue;
}

public void setCurrentValue(Object value) {
_currentValue = value;
}

public int compareTo(Object o) {
return _name.compareTo(((Property) o)._name);
}
}
     ]]></code-fragment>


    <test-code>
        <description>Full example</description>
        <expected-problems>1</expected-problems>
        <expected-messages>
            <message>'Property' has value 0.0952.</message>
        </expected-messages>
        <code-ref id="full-example"/>
    </test-code>

    <test-code>
        <description>Test empty class</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
        public class Foo {
        }
        ]]></code>
    </test-code>

    <test-code>
        <description>TCC doesn't support interfaces or annotations</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
        public interface Foo {

           public final int h;

           @interface Tag {
              public static final int num = 0;
           }
        }
        ]]></code>
    </test-code>

    <test-code>
        <description>Do not crash on local class, refs #827</description>
        <expected-problems>1</expected-problems>
        <expected-messages>
            <message>'com.pack.Pack$1Inner' has value 0.</message>
        </expected-messages>
        <code><![CDATA[
        package com.pack;

        import java.util.ArrayList;
        import java.util.Arrays;
        import java.util.Date;
        import java.util.HashMap;
        import java.util.List;
        import java.util.Map;

        public class Pack implements IPack {


            @Override
            public Map<String, String> get() {

                class Inner implements IInner {

                    private Map<String, String> results;

                    public Inner(Map<String, String> results) {
                        this.results = results;
                    }

                    public void method() {
                        this.results = new HashMap<String, String>();
                    }

                    private void otherMethod() {
                        this.results.clear();
                    }
                }
                return null;
            }
        }
        ]]></code>
    </test-code>

    <test-code>
        <description>Attribute accesses in local class count as accesses of the method</description>
        <expected-problems>2</expected-problems>
        <expected-messages>
            <message>'com.pack.Pack' has value 1.</message>
            <message>'com.pack.Pack$1Inner' has value 0.</message>
        </expected-messages>
        <code><![CDATA[
        package com.pack;

        import java.util.ArrayList;
        import java.util.Arrays;
        import java.util.Date;
        import java.util.HashMap;
        import java.util.List;
        import java.util.Map;

        public class Pack implements IPack {

            // the attribute is in the outer class
            private Map<String, String> results;

            public void paired() {
                results.clear();
            }

            @Override
            public Map<String, String> get() {

                class Inner implements IInner {


                    public Inner(Map<String, String> results) {
                        this.results = results;
                    }

                    public void method() {
                        this.results = new HashMap<String, String>();
                    }

                    private void otherMethod() {
                        this.results.clear();
                    }
                }
                return null;
            }
        }
        ]]></code>
    </test-code>


</test-data>
