<?xml version="1.0" encoding="UTF-8"?>
<test-data>
    <test-code>
        <description><![CDATA[
calling public method from constructor
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
 public Foo() {
  bar();
 }
 public void bar() {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
calling protected method from constructor
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
 public Foo() {
  bar();
 }
 protected void bar() {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
calling package private method from constructor
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
 public Foo() {
  bar();
 }
 void bar() {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
calling private method, ok
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
 public Foo() {
  bar();
 }
 private void bar() {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
overloaded constructors, calling public method
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Foo {
 public Foo() {
  this("Bar");
 }
 private Foo(String bar) {
  bar();
 }
 public void bar() {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
calling method on literal bug
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
 public Foo(String s) {
  "foo".equals(s);
 }
 public void equals(String bar) {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
method in anonymous inner class is ok
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
 public Foo(String s) {
  addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {bar();}
  });
 }
 public void bar() {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
bug report 975407
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
 public Foo() {
  bar();
 }
 private void bar() {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
ignore abstract methods
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
 public Foo() {
  bar();
 }
 abstract void bar() {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Generics
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
package foo.bar;
public enum Buz {
 FOO(2);
 private Buz(String s) {}
}
     ]]></code>
        <source-type>java 1.5</source-type>
    </test-code>
    <test-code>
        <description><![CDATA[
985989, base line
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class SeniorClass {
    public SeniorClass(){
        toString(); //may throw NullPointerException if overridden
    }
    public String toString(){
        return "IAmSeniorClass";
    }
}
public class JuniorClass extends SeniorClass {
    private String name;
    
    public JuniorClass() {
        super(); //Automatic call leads to NullPointerException
        name = "JuniorClass";
    }
    public String toString(){
        return name.toUpperCase();
    }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
985989, inner static class should be checked as well
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
public class Test {

    public static class SeniorClass {
        public SeniorClass(){
            toString(); //may throw NullPointerException if overridden
        }
        public String toString(){
            return "IAmSeniorClass";
        }
    }
    public static class JuniorClass extends SeniorClass {
        private String name;
        
        public JuniorClass() {
            super(); //Automatic call leads to NullPointerException
            name = "JuniorClass";
        }
        public String toString(){
            return name.toUpperCase();
        }
    }
    public static void main (String[] args) {
        System.out.println(": "+new SeniorClass());
        System.out.println(": "+new JuniorClass());
    }

}
     ]]></code>
    </test-code>
    <test-code>
        <description>bug #1005 False + for ConstructorCallsOverridableMethod - overloaded methods</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
 public Foo() {
  bar(true);
 }
 public final void bar(boolean b) {}
 public void bar(String o) {}
}
        ]]></code>
    </test-code>
    <test-code>
        <description>bug #1127 False positive: Constructor Calls Overridable Method</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public final class Foo {
    public Foo() {
        bar();
    }

    public void bar() {}
}
        ]]></code>
    </test-code>
    <test-code>
        <description>NullPointer while analyzing ExcessiveLengthRule</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
package net.sourceforge.pmd.lang.java.rule.design;

import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.rule.AbstractStatisticalJavaRule;
import net.sourceforge.pmd.stat.DataPoint;

public class ExcessiveLengthRule extends AbstractStatisticalJavaRule {
    private Class<?> nodeClass;
    public ExcessiveLengthRule(Class<?> nodeClass) {
        this.nodeClass = nodeClass;
    }
    @Override
    public Object visit(JavaNode node, Object data) {
        if (nodeClass.isInstance(node)) {
            DataPoint point = new DataPoint();
            point.setNode(node);
            point.setScore(1.0 * (node.getEndLine() - node.getBeginLine()));
            point.setMessage(getMessage());
            addDataPoint(point);
        }
        return node.childrenAccept(this, data);
    }
}
        ]]></code>
    </test-code>
</test-data>
