<?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><![CDATA[
Contains assert
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public void test1() {
  assertEquals("1 == 1", 1, 1);
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Missing assert
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public void test1() {
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
All ok
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public void setUp() {
 }
 public void test1() {
  assertTrue("foo", "foo".equals("foo"));
 }
 public void test2() {
  assertEquals("foo", "foo");
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Two wrong
     ]]></description>
        <expected-problems>2</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public void setUp() {
 }
 public void test1() {
 	int a;
 	callMethod(a);
 }
 public void test2() {
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Contains fail
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public void test1() {
  fail("1 == 1");
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
One wrong
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public void setUp() {
 }
 public void test1() {
 	int a;
 	callMethod(a);
 }
 public void test2() {
 	fail();
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Skip interfaces
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public void setUp() throws Exception;
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Skip abstract methods
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public abstract void setUp() throws Exception;
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Another fail() case
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public abstract class AbstractAggregateCreatorTest extends TestCase{
    public abstract int getType();
    public abstract ProfileAggregate create(DatabaseTransaction db,
        DailyProfileList profiles, ProfileType type, ProfileStatus status)
        throws VixenException;
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
BUG 1105633 - False +: JUnit testcases could have fail() instead of assert
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public void testNPEThrown() {
  try {
   methodCall(null);
   fail("Expected NullPointerException to be thrown.");
  } catch (NullPointerException npe) {
   // Caught expected exception
  }
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
BUG 1146116 PMDException with inner interfaces
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
package at.herold.anthilltest;
import junit.framework.TestCase;
public class TestJunitRuleExceptionTest extends TestCase {
   interface I1 { 
      public void meth(); // this is ok
   }
   interface I2 {
      public void meth() throws Exception; // this causes PMDException
   }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
skip static test methods
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public static void testfoo() {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
exceptions shouldn't block it
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
import junit.framework.TestCase;
public class FooTest extends TestCase {
 public void testfoo() throws Exception {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Not a JUnit test (exceptions shouldn't block it)
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class FooTest {
 public void testfoo() throws Exception {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
JUnit 4 test (exceptions shouldn't block it)
     ]]></description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
import org.junit.Test;
public class Foo {
 @Test
 public void foo() throws Exception {}
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Junit 4 static import
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import static org.junit.Assert.assertFalse;
import org.junit.Test;
public class AssertTest {
  @Test public void testFalse() {
    assertFalse(1 == 2);
  }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
Junit 4 test using Assert.assert...
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.junit.Assert;
import org.junit.Test;
public class AssertTest {
  @Test public void testTrue() {
    Assert.assertTrue(1 != 2);
  }
}
     ]]></code>
    </test-code>

    <test-code>
        <description>#968 Issues with JUnit4 @Test annotation with expected exception</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.junit.Test;
public class Foo_Test
{
    /** Tests that doSomething throws an exception if arg is negative */
    @Test(expected = IllegalArgumentException.class)
    public  void testDoSomethingFail()
    {
        new Foo().doSomething(-1);
        // Note - no assert is needed as we expect an exception (which is basically an assert).
    }
}
        ]]></code>
    </test-code>
    <test-code>
        <description>#285 Issues with @Rule annotation and ExpectedException</description>
	<expected-problems>1</expected-problems>
	<expected-linenumbers>7</expected-linenumbers>
        <code><![CDATA[
import org.junit.*;
public class SimpleExpectedExceptionTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();

   @Test
   public void throwsExceptionWithSpecificType() {
     throw new NullPointerException(); // No expect! this is a violation
   }
     
   @Test
   public void throwsIllegalArgumentExceptionIfIconIsNull() {
     thrown.expect(IllegalArgumentException.class);
     thrown.expectMessage("Icon is null, not a file, or doesn't exist.");
     new DigitalAssetManager(null, null);
   } 
}
        ]]></code>
    </test-code>    
    <test-code>
        <description>#285 Follow-up for @org.junit.Rule</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.junit.*;
public class SimpleExpectedExceptionTest {
     @org.junit.Rule
     public ExpectedException thrown = ExpectedException.none();

     @Test
     public void throwsExceptionWithSpecificType() {
         thrown.expect(NullPointerException.class);
         throw new NullPointerException();
     }
 }
        ]]></code>
    </test-code>    
    <test-code>
        <description>#330 Rule treats AllocationExpression correctly</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
	
import org.junit.*;
import javafx.embed.swing.JFXPanel;

public class BaseConsoleTest extends UART {
    @Test 
    public void testInitialize() throws InterruptedException {
        new JFXPanel(); // AllocationExpression
    }
}
        ]]></code>
    </test-code>
    <test-code>
        <description>#330 NPE accessing local field / method with this.XXX</description>
        <expected-problems>1</expected-problems>
        <code><![CDATA[
import org.junit.Test;
public class Foo {
    @Test
    public void testName() {
        this.field = null;
    }
}
        ]]></code>
    </test-code>
    <test-code>
        <description>#358 Treat Mockito's verify as assert expressions</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public class FooTest {

    @Mock
    private Bar bar;

    @Test
    public void testFooCallsBar() {
        Foo foo = new Foo(bar);
        foo.doTask();

        verify(bar, times(1)).actuallyDoTask();
    }
}]]></code>
    </test-code>
    <test-code>
        <description>#358 Treat Mockito's Mockito.verify as assert expressions</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;


@RunWith(MockitoJUnitRunner.class)
public class FooTest {

    @Mock
    private Bar bar;

    @Test
    public void testFooCallsBar() {
        Foo foo = new Foo(bar);
        foo.doTask();

        Mockito.verify(bar, Mockito.times(1)).actuallyDoTask();
    }
}]]></code>
    </test-code>
    <test-code>
        <description>#465 NullPointerException when dealing with @SuppressWarnings</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class FooTest {

  @SuppressWarnings("deprecation")
  private static Foo foo = new Foo();

  @Test
  public void testFoo() {
    assertEquals("doesn't matter", "doesn't matter");
  }

}]]></code>
    </test-code>
</test-data>
