<?xml version="1.0" encoding="UTF-8"?>
<test-data>
    <test-code>
        <description><![CDATA[
failure case
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
class Foo {
 private void bar(String x) {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
method called on param
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
class Foo {
 private void foo (String s) {
  String str = s.toString();
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
assignment to param
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
class Foo {
 private void bar(int s) {
  s = 2;
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
interface
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public interface Foo {
 void foo(int x);
}
     ]]></code>
    </test-code>
    <code-fragment id="public methods"><![CDATA[
class Foo {
 public void bar(int s) {}
}
     ]]></code-fragment>
    <test-code>
        <description><![CDATA[
don't flag public methods by default
     ]]></description>
        <expected-problems>0</expected-problems>
        <code-ref id="public methods"/>
    </test-code>
        <test-code>
        <description><![CDATA[
flag public methods if checkall property is set
     ]]></description>
        <rule-property name="checkAll">true</rule-property>
        <expected-problems>1</expected-problems>
        <code-ref id="public methods"/>
    </test-code>
    <test-code>
        <description><![CDATA[
skip native/abstract methods
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
class Foo {
 public native void bar(int s);
 protected abstract void foo(Long s);
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
anonymous inner class npe
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
class Foo {
 void bar() {
  ActionListener a  = new ActionListener() {
   public void event(Event e) {}
  };
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
unused constructor param
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
class Foo {
 public Foo(int s) {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
assigned but not used
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
class Foo {
 private void foo (String s) {
  s = "hello";
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
array element is set
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
class Foo {
 private void foo (String[] s) {
  s[2] = "hello";
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
unused array in constructor
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
class Foo {
 int type;
 public Foo (int type, String[] s) {
  this.type = type;
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
unused array in method
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
class Foo {
 private final void setLang(final String lang[]){
 }
}
     ]]></code>
    </test-code>
    <test-code>
	<description>
		<![CDATA[
			False - ! if "checkAll" property is not set
		]]>
	</description>
	<rule-property name="checkAll">true</rule-property>
	<expected-problems>1</expected-problems>
	<code>
	<![CDATA[
	public class Foo {
		public void bar2(Object paramA, Object paramB)
		{
			paramA.hashCode();
		}
	}
	]]>
	</code>
	</test-code>
    <test-code>
	<description>
		<![CDATA[
			violation suppression regex works
		]]>
	</description>
	<rule-property name="violationSuppressRegex">.*'paramB'.*</rule-property>
	<expected-problems>0</expected-problems>
	<code>
	<![CDATA[
	public class Foo {
		private void bar2(Object paramA, Object paramB)
		{
			paramA.hashCode();
		}
	}
	]]>
	</code>
	</test-code>
    <test-code>
	<description>
		<![CDATA[
			violation suppression xpath works, by name
		]]>
	</description>
	<rule-property name="violationSuppressXPath">.[@Image = 'paramB']</rule-property>
	<expected-problems>0</expected-problems>
	<code>
	<![CDATA[
	public class Foo {
		private void bar2(Object paramA, Object paramB)
		{
			paramA.hashCode();
		}
	}
	]]>
	</code>
	</test-code>
    <test-code>
	<description>
		<![CDATA[
			violation suppression xpath works, by type
		]]>
	</description>
	<rule-property name="violationSuppressXPath">.[typeof('java.lang.String')]</rule-property>
	<expected-problems>0</expected-problems>
	<code>
	<![CDATA[
	public class Foo {
		private void bar2(Object paramA, String paramB)
		{
			paramA.hashCode();
		}
	}
	]]>
	</code>
	</test-code>
	<test-code>
		<description>#878 don't flag abstract methods even if checkall property is set when checking an abstract class</description>
		<rule-property name="checkAll">true</rule-property>
		<expected-problems>0</expected-problems>
		<code><![CDATA[
abstract class Foo {
    protected abstract void foo(Long s);
}
		]]></code>
	</test-code>
    <test-code>
        <description>#1159 false positive UnusedFormalParameter readObject(ObjectInputStream) if not used</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    private void readObject(ObjectInputStream stream) throws InvalidObjectException{
       throw new InvalidObjectException("Proxy required");
    }
}
        ]]></code>
    </test-code>
    <test-code>
        <description>#1159 correct UnusedFormalParameter for readObject(foo) if not used</description>
        <rule-property name="checkAll">true</rule-property>
        <expected-problems>5</expected-problems>
        <code><![CDATA[
public class Foo {
    // throws declaration is missing - so not the serialization readObject method
    private void readObject(ObjectInputStream stream) {
       throw new InvalidObjectException("Proxy required");
    }
    // argument is not a ObjectInputStream
    private void readObject(Foo a) throws InvalidObjectException {
       throw new InvalidObjectException("Proxy required");
    }
    // two arguments - two violations
    private void readObject(ObjectInputStream stream, Object o) throws InvalidObjectException{
       throw new InvalidObjectException("Proxy required");
    }
    // it's public
    public void readObject(ObjectInputStream stream) throws InvalidObjectException{
       throw new InvalidObjectException("Proxy required");
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1456 UnusedFormalParameter should ignore overriding methods</description>
        <expected-problems>0</expected-problems>
        <rule-property name="checkAll">true</rule-property>
        <code><![CDATA[
abstract class Base{
  abstract public int badMethod(int arg1, String arg2);
}

class Imp1 extends Base {
  @Override
  public int badMethod(int arg1, String arg2) {
    return arg2.length();
  }
}

class Imp2 extends Base {
  @Override
  public int badMethod(int arg1, String arg2) {
    return arg2.length() + arg1;
  }
}
        ]]></code>
    </test-code>
</test-data>
