<?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>hash code only</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>2</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public int hashCode() {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>equals only</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>2</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public boolean equals(Object other) {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>overrides both</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public boolean equals(Object other) {}
    public int hashCode() {}
}
        ]]></code>
    </test-code>

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

    <test-code>
        <description>equals sig uses String, not Object</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>5</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public boolean equals(String o) {
        return true;
    }
    public int hashCode() {
        return 0;
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>interface</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public interface Foo {
    public boolean equals(Object o);
}
        ]]></code>
    </test-code>

    <test-code>
        <description>java.lang.Object</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public boolean equals(java.lang.Object o) {
        return true;
    }
    public int hashCode() {
        return 0;
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>skip Comparable implementations</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo implements Comparable {
    public boolean equals(Object other) { return false; }
    public int compareTo(Object other) { return 42; }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>implements equals but with 2 args</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public boolean equals(java.lang.Object o1, java.lang.Object o2) {
        return true;
    }
    public int hashCode(java.lang.Object o) {
        return 0;
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>overloaded hashCode</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo  {
    public int hashCode(Object o1) { return false; }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>overloaded both</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo  {
    public boolean equals(Object o1, Object o2) { return false; }
    public int hashCode(Object o1) { return false; }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>overloaded hashCode, should fail on equals</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>2</expected-linenumbers>
        <code><![CDATA[
public class Foo  {
    public boolean equals(Object o1) { return false; }
    public int hashCode(Object o1) { return false; }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>implements hashCode but with args</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public int hashCode(double a[]) {
        return 0;
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>implements interface other than Comparable, not resolvable</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>2</expected-linenumbers>
        <code><![CDATA[
public class Foo implements C {
    public boolean equals(Object other) { return false; }
    public int compareTo(Object other) { return 42; }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>implements interface other than Comparable, resolvable (#1303 OverrideBothEqualsAndHashcodeRule does not work on class implements resolvable interfaces)</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>2</expected-linenumbers>
        <code><![CDATA[
public class Foo implements Runnable {
    public boolean equals(Object other) { return false; }
    public int compareTo(Object other) { return 42; }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>[java] OverrideBothEqualsAndHashcode: false negative with anonymous classes #4457</description>
        <expected-problems>2</expected-problems>
        <code><![CDATA[
public class Foo {
  public class B {
      Object o = new Object() {
          public boolean equals(Object other) {   // report no warning
              return false;
          }
      };
      public int hashCode() {
          return 1;
      }
  }
}
        ]]></code>
    </test-code>
    <test-code>
        <description>[java] OverrideBothEqualsAndHashCode ignores records #4546</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
            public record Foo(int x) {
                    public int hashCode() {
                        return 1;
                    }
            }
            ]]></code>
    </test-code>
</test-data>
