<?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>ok, implements Cloneable</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo implements Cloneable {
    void clone() {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>bad, doesn't implement Cloneable</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
    void clone() {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ok, not Object.clone since method has a param</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    void clone(int x) {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ok, doesn't implement Cloneable but only throw CloneNotSupportedException</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    final Object clone() { throw new CloneNotSupportedException(); }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ok, inner class implements Cloneable</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Bar {
    class Foo implements Cloneable {
        void clone() {}
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ok, implements interface in same package which extends Cloneable</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
package net.sourceforge.pmd.lang.java.rule.errorprone;
public class FooX extends MyInterface {
    void clone() {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ok, implements interface imported implicitly which extends Cloneable</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import net.sourceforge.pmd.lang.java.rule.errorprone.*;
public class FooX extends MyInterface {
    void clone() {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ok, implements interface which extends Cloneable</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class FooX extends net.sourceforge.pmd.lang.java.rule.errorprone.MyInterface {
    void clone() {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>ok, extends superclass AND implements cloneable</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
class Bar {}
public class Foo extends Bar implements Cloneable{
    void clone() {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Bug 1698550, nr 1</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public final Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException();
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Bug 1698550, nr 2</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public final class Foo {
    public Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException();
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Bug 681, extending a class which implements Clonable.</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class MyAbstractClass implements Cloneable{
}
public class MyClonableClass extends MyAbstractClass{
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>Bug 1765613, NullPointerException on enum</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public enum Foo {
    BAR("bar");

    private String bar;

    public String getBar() {
        return bar;
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1534 [java] CloneMethodMustImplementCloneable: ClassCastException with Annotation (java8)</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import java.util.List;
@interface Readonly {}
public class UnmodifiableList<T> implements @Readonly List<@Readonly T> {}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1532 [java] CloneMethodMustImplementCloneable: Implemented Interface extends Cloneable - part 1: interface</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
interface TestInterface extends Cloneable {
    TestInterface clone();
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1532 [java] CloneMethodMustImplementCloneable: Implemented Interface extends Cloneable - part 2: interface</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
interface TestInterface {
    TestInterface clone();
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1532 [java] CloneMethodMustImplementCloneable: Implemented Interface extends Cloneable</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
interface TestInterface extends Cloneable {
    TestInterface clone();
}

class CloneableClass implements TestInterface {
    @Override // creates a warning though CloneableClass is actually implementing Cloneable
    public CloneableClass clone() {
        // clone implementation
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>[java] CloneMethodMustImplementCloneable triggers for interfaces #1005</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
            public interface Foo
                    extends java.io.Serializable, Cloneable {
                Foo clone() throws CloneNotSupportedException;
            }
        ]]></code>
    </test-code>

    <test-code>
        <description>[java] CloneMethodMustImplementCloneable: False negative with local classes #3343</description>
        <expected-problems>2</expected-problems>
        <expected-linenumbers>3,9</expected-linenumbers>
        <code><![CDATA[
public class Outer {
    public static class Inner {
        public Object clone() throws CloneNotSupportedException {
            return super.clone();
        }
    }
    public void foo() {
        class Local {
            public Object clone() throws CloneNotSupportedException {
                return super.clone();
            }
        }
    }
}
        ]]></code>
    </test-code>
</test-data>
