Repository: mockito/mockito
Issue: Remove deprecated API from Mockito 2 

# This is a reminder to remove all deprecated API's from the upcoming mockito 2.

This issue blocks #123 [Release Mockito 2.0](123)

Relates to 
-  #273 [Get rid of ReturnValues](273)


Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/src/main/java/org/mockito/Answers.java b/src/main/java/org/mockito/Answers.java
index db3f5723ad..ff89b4b482 100644
--- a/src/main/java/org/mockito/Answers.java
+++ b/src/main/java/org/mockito/Answers.java
@@ -87,15 +87,6 @@ public enum Answers implements Answer<Object>{
         this.implementation = implementation;
     }
 
-    /**
-     * @deprecated Use the enum-constant directly, instead of this getter. This method will be removed in a future release<br> 
-     * E.g. instead of <code>Answers.CALLS_REAL_METHODS.get()</code> use <code>Answers.CALLS_REAL_METHODS</code> .
-     */
-    @Deprecated
-    public Answer<Object> get() {
-        return this;
-    }
-
     public Object answer(InvocationOnMock invocation) throws Throwable {
         return implementation.answer(invocation);
     }
diff --git a/src/main/java/org/mockito/ArgumentCaptor.java b/src/main/java/org/mockito/ArgumentCaptor.java
index e84de14c83..0bf639d414 100644
--- a/src/main/java/org/mockito/ArgumentCaptor.java
+++ b/src/main/java/org/mockito/ArgumentCaptor.java
@@ -65,26 +65,6 @@ public class ArgumentCaptor<T> {
     private final CapturingMatcher<T> capturingMatcher = new CapturingMatcher<T>();
     private final Class<? extends T> clazz;
 
-    /**
-     * @deprecated
-     * 
-     * <b>Please use factory method {@link ArgumentCaptor#forClass(Class)} to create captors</b>
-     * <p>
-     * This is required to avoid NullPointerExceptions when autoUnboxing primitive types.
-     * See issue 99.
-     * <p>
-     * Example:
-     * <pre class="code"><code class="java">
-     *   ArgumentCaptor&lt;Person&gt; argument = ArgumentCaptor.forClass(Person.class);
-     *   verify(mock).doSomething(argument.capture());
-     *   assertEquals("John", argument.getValue().getName());
-     * </code></pre>
-     */
-    @Deprecated
-    public ArgumentCaptor() {
-        this.clazz = null;
-    }
-
     private ArgumentCaptor(Class<? extends T> clazz) {
         this.clazz = clazz;
     }
diff --git a/src/main/java/org/mockito/exceptions/Discrepancy.java b/src/main/java/org/mockito/exceptions/Discrepancy.java
deleted file mode 100644
index 4b3e4d7f2d..0000000000
--- a/src/main/java/org/mockito/exceptions/Discrepancy.java
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
-package org.mockito.exceptions;
-
-@Deprecated
-/**
- * @Deprecated. This class has been moved to internal packages because it was never meant to be public.
- * If you need it for extending Mockito please let us know. You can still use {@link org.mockito.internal.reporting.Discrepancy}.
- * However, the package clearly states that the class in a part of a public API so it can change.
- */
-public class Discrepancy extends org.mockito.internal.reporting.Discrepancy {
-    public Discrepancy(int wantedCount, int actualCount) {
-        super(wantedCount, actualCount);
-    }
-}
\ No newline at end of file
diff --git a/src/main/java/org/mockito/exceptions/Pluralizer.java b/src/main/java/org/mockito/exceptions/Pluralizer.java
deleted file mode 100644
index 0dcecee5e9..0000000000
--- a/src/main/java/org/mockito/exceptions/Pluralizer.java
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
-package org.mockito.exceptions;
-
-@Deprecated
-/**
- * @Deprecated. This class has been moved to internal packages because it was never meant to be public.
- * If you need it for extending Mockito please let us know. You can still use {@link org.mockito.internal.reporting.Pluralizer}.
- * However, the package clearly states that the class in a part of a public API so it can change.
- */
-public class Pluralizer extends org.mockito.internal.reporting.Pluralizer {}
diff --git a/src/main/java/org/mockito/exceptions/PrintableInvocation.java b/src/main/java/org/mockito/exceptions/PrintableInvocation.java
deleted file mode 100644
index 52e288ddc8..0000000000
--- a/src/main/java/org/mockito/exceptions/PrintableInvocation.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
-
-package org.mockito.exceptions;
-
-import org.mockito.invocation.DescribedInvocation;
-import org.mockito.invocation.Location;
-
-@Deprecated
-/**
- * @Deprecated. We needed to move this class to a better place to keep consistency of the API.
- * Please use {@link DescribedInvocation} instead.
- */
-public interface PrintableInvocation {
-
-    String toString();
-
-    Location getLocation();
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/mockito/exceptions/verification/junit/JUnitTool.java b/src/main/java/org/mockito/exceptions/verification/junit/JUnitTool.java
deleted file mode 100644
index f5c614a3d3..0000000000
--- a/src/main/java/org/mockito/exceptions/verification/junit/JUnitTool.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
-package org.mockito.exceptions.verification.junit;
-
-@Deprecated
-/**
- * @Deprecated. This class has been moved to internal packages because it was never meant to be public.
- * If you need it for extending Mockito please let us know. You can still use {@link org.mockito.internal.junit.JUnitTool}.
- * However, the package clearly states that the class in a part of a public API so it can change.
- */
-public class JUnitTool {
-    
-    public static boolean hasJUnit() {
-        return org.mockito.internal.junit.JUnitTool.hasJUnit();
-    }
-
-    public static AssertionError createArgumentsAreDifferentException(String message, String wanted, String actual)  {
-        return org.mockito.internal.junit.JUnitTool.createArgumentsAreDifferentException(message, wanted, actual);
-    }
-}
\ No newline at end of file
diff --git a/src/main/java/org/mockito/invocation/DescribedInvocation.java b/src/main/java/org/mockito/invocation/DescribedInvocation.java
index b18223560b..fc975aba44 100644
--- a/src/main/java/org/mockito/invocation/DescribedInvocation.java
+++ b/src/main/java/org/mockito/invocation/DescribedInvocation.java
@@ -4,12 +4,11 @@
  */
 package org.mockito.invocation;
 
-import org.mockito.exceptions.PrintableInvocation;
 
 /**
  * Provides information about the invocation, specifically a human readable description and the location.
  */
-public interface DescribedInvocation extends PrintableInvocation {
+public interface DescribedInvocation {
 
     /**
      * Describes the invocation in the human friendly way.
diff --git a/src/main/java/org/mockito/listeners/MethodInvocationReport.java b/src/main/java/org/mockito/listeners/MethodInvocationReport.java
index da171ba911..a7303e892b 100644
--- a/src/main/java/org/mockito/listeners/MethodInvocationReport.java
+++ b/src/main/java/org/mockito/listeners/MethodInvocationReport.java
@@ -4,7 +4,6 @@
  */
 package org.mockito.listeners;
 
-import org.mockito.exceptions.PrintableInvocation;
 import org.mockito.invocation.DescribedInvocation;
 
 /**
@@ -18,10 +17,6 @@
  */
 public interface MethodInvocationReport {
     /**
-     * The return type is deprecated, please assign the return value from this method
-     * to the {@link DescribedInvocation} type. Sorry for inconvenience but we had to move
-     * {@link PrintableInvocation} to better place to keep the API consistency.
-     *
      * @return Information on the method call, never {@code null}
      */
     DescribedInvocation getInvocation();
diff --git a/src/main/java/org/mockito/runners/MockitoJUnit44Runner.java b/src/main/java/org/mockito/runners/MockitoJUnit44Runner.java
deleted file mode 100644
index 4080d1ef8e..0000000000
--- a/src/main/java/org/mockito/runners/MockitoJUnit44Runner.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
-
-package org.mockito.runners;
-
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-import java.lang.reflect.InvocationTargetException;
-
-/**
- * <b>Deprecated: Simply use {@link MockitoJUnitRunner}</b>
- * <p>
- * Compatible only with <b>JUnit 4.4</b>, this runner adds following behavior:
- * <ul>
- *   <li>
- *      Initializes mocks annotated with {@link Mock},
- *      so that explicit usage of {@link MockitoAnnotations#initMocks(Object)} is not necessary. 
- *      Mocks are initialized before each test method.
- *   <li>
- *      validates framework usage after each test method. See javadoc for {@link Mockito#validateMockitoUsage()}.
- * </ul>
- * 
- * Runner is completely optional - there are other ways you can get &#064;Mock working, for example by writing a base class.
- * Explicitly validating framework usage is also optional because it is triggered automatically by Mockito every time you use the framework.
- * See javadoc for {@link Mockito#validateMockitoUsage()}.
- * <p>
- * Read more about &#064;Mock annotation in javadoc for {@link MockitoAnnotations}
- * <p>
- * Example:
- * <pre class="code"><code class="java">
- * &#064;RunWith(MockitoJUnitRunner.class)
- * public class ExampleTest {
- * 
- *     &#064;Mock
- *     private List list;
- * 
- *     &#064;Test
- *     public void shouldDoSomething() {
- *         list.add(100);
- *     }
- * }
- * <p>
- * 
- * </code></pre>
- */
-@Deprecated
-public class MockitoJUnit44Runner extends MockitoJUnitRunner {
-
-    public MockitoJUnit44Runner(Class<?> klass) throws InvocationTargetException {
-        super(klass);
-    }
-}
\ No newline at end of file
diff --git a/src/main/java/org/mockito/stubbing/answers/ReturnsElementsOf.java b/src/main/java/org/mockito/stubbing/answers/ReturnsElementsOf.java
deleted file mode 100644
index bd8f182455..0000000000
--- a/src/main/java/org/mockito/stubbing/answers/ReturnsElementsOf.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
-package org.mockito.stubbing.answers;
-
-import java.util.Collection;
-
-/**
- * Returns elements of the collection. Keeps returning the last element forever.
- * Might be useful on occasion when you have a collection of elements to return.
- * <p>
- * <pre class="code"><code class="java">
- *   //this:
- *   when(mock.foo()).thenReturn(1, 2, 3);
- *   //is equivalent to:
- *   when(mock.foo()).thenReturn(new ReturnsElementsOf(Arrays.asList(1, 2, 3)));
- * </code></pre>
- *
- * @deprecated Use {@link org.mockito.AdditionalAnswers#returnsElementsOf}
- */
-@Deprecated
-public class ReturnsElementsOf extends org.mockito.internal.stubbing.answers.ReturnsElementsOf {
-
-    @Deprecated
-    public ReturnsElementsOf(Collection<?> elements) {
-        super(elements);
-    }
-}
\ No newline at end of file


Test patch:
diff --git a/src/test/java/org/mockito/runners/RunnersValidateFrameworkUsageTest.java b/src/test/java/org/mockito/runners/RunnersValidateFrameworkUsageTest.java
index 35f29a78d3..44f1de9a06 100644
--- a/src/test/java/org/mockito/runners/RunnersValidateFrameworkUsageTest.java
+++ b/src/test/java/org/mockito/runners/RunnersValidateFrameworkUsageTest.java
@@ -16,7 +16,7 @@
 import org.mockito.internal.runners.util.FrameworkUsageValidator;
 import org.mockitoutil.TestBase;
 
-@SuppressWarnings({"unchecked", "deprecation"})
+@SuppressWarnings({"unchecked"})
 public class RunnersValidateFrameworkUsageTest extends TestBase {
     
     private Runner runner;
@@ -51,7 +51,7 @@ public void shouldValidateWithDefaultRunner() throws Exception {
     @Test
     public void shouldValidateWithD44Runner() throws Exception {
         //given
-        runner = new MockitoJUnit44Runner(DummyTest.class);
+        runner = new MockitoJUnitRunner(DummyTest.class);
 
         //when
         runner.run(notifier);
diff --git a/src/test/java/org/mockitousage/junitrunner/JUnit44RunnerTest.java b/src/test/java/org/mockitousage/junitrunner/JUnit44RunnerTest.java
deleted file mode 100644
index cc5e08a451..0000000000
--- a/src/test/java/org/mockitousage/junitrunner/JUnit44RunnerTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
-package org.mockitousage.junitrunner;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-import static org.mockitousage.junitrunner.Filters.*;
-
-import java.util.List;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnit44Runner;
-
-@RunWith(MockitoJUnit44Runner.class)
-@SuppressWarnings( { "unchecked", "deprecation" })
-public class JUnit44RunnerTest {
-
-    @InjectMocks
-    private ListDependent listDependent = new ListDependent();
-
-    @Mock
-    private List list;
-
-    @Test
-    public void shouldInitMocksUsingRunner() {
-        list.add("test");
-        verify(list).add("test");
-    }
-    @Test
-    public void shouldInjectMocksUsingRunner() {
-        assertSame(list, listDependent.getList());
-    }
-
-    @Test
-    public void shouldFilterTestMethodsCorrectly() throws Exception{
-        MockitoJUnit44Runner runner = new MockitoJUnit44Runner(this.getClass());
-
-        runner.filter(methodNameContains("shouldInitMocksUsingRunner"));
-
-        assertEquals(1, runner.testCount());
-    }
-
-    class ListDependent {
-        private List list;
-
-        public List getList() {
-            return list;
-        }
-    }
-}
\ No newline at end of file
diff --git a/src/test/java/org/mockitousage/matchers/CapturingArgumentsTest.java b/src/test/java/org/mockitousage/matchers/CapturingArgumentsTest.java
index 43c362a9b4..9457cd51c5 100644
--- a/src/test/java/org/mockitousage/matchers/CapturingArgumentsTest.java
+++ b/src/test/java/org/mockitousage/matchers/CapturingArgumentsTest.java
@@ -63,7 +63,7 @@ interface EmailService {
     @Test
     public void should_allow_assertions_on_captured_argument() {
         //given
-        ArgumentCaptor<Person> argument = new ArgumentCaptor<Person>();
+        ArgumentCaptor<Person> argument = ArgumentCaptor.forClass(Person.class);
 
         //when
         bulkEmailService.email(12);
diff --git a/src/test/java/org/mockitousage/stacktrace/PointingStackTraceToActualInvocationTest.java b/src/test/java/org/mockitousage/stacktrace/PointingStackTraceToActualInvocationTest.java
index ea57e5e645..2522224197 100644
--- a/src/test/java/org/mockitousage/stacktrace/PointingStackTraceToActualInvocationTest.java
+++ b/src/test/java/org/mockitousage/stacktrace/PointingStackTraceToActualInvocationTest.java
@@ -12,13 +12,12 @@
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.exceptions.verification.NeverWantedButInvoked;
-import org.mockito.runners.MockitoJUnit44Runner;
+import org.mockito.runners.MockitoJUnitRunner;
 import org.mockitousage.IMethods;
 import org.mockitoutil.TestBase;
 
 //This is required to make sure stack trace is well filtered when runner is ON
-@SuppressWarnings("deprecation")
-@RunWith(MockitoJUnit44Runner.class)
+@RunWith(MockitoJUnitRunner.class)
 public class PointingStackTraceToActualInvocationTest extends TestBase {
     
     @Mock private IMethods mock;
diff --git a/src/test/java/org/mockitousage/stubbing/StubbingWithExtraAnswersTest.java b/src/test/java/org/mockitousage/stubbing/StubbingWithExtraAnswersTest.java
index b85c2394eb..8fb8a89857 100644
--- a/src/test/java/org/mockitousage/stubbing/StubbingWithExtraAnswersTest.java
+++ b/src/test/java/org/mockitousage/stubbing/StubbingWithExtraAnswersTest.java
@@ -11,9 +11,9 @@
 import java.util.List;
 
 import org.junit.Test;
+import org.mockito.AdditionalAnswers;
 import org.mockito.Mock;
 import org.mockito.exceptions.base.MockitoException;
-import org.mockito.stubbing.answers.ReturnsElementsOf;
 import org.mockitousage.IMethods;
 import org.mockitoutil.TestBase;
 
@@ -25,7 +25,7 @@ public class StubbingWithExtraAnswersTest extends TestBase {
     public void shouldWorkAsStandardMockito() throws Exception {
         //when
         List<Integer> list = asList(1, 2, 3);
-        when(mock.objectReturningMethodNoArgs()).thenAnswer(new ReturnsElementsOf(list));
+        when(mock.objectReturningMethodNoArgs()).thenAnswer(AdditionalAnswers.returnsElementsOf(list));
         
         //then
         assertEquals(1, mock.objectReturningMethodNoArgs());
@@ -40,7 +40,7 @@ public void shouldWorkAsStandardMockito() throws Exception {
     public void shouldReturnNullIfNecessary() throws Exception {
         //when
         List<Integer> list = asList(1, null);
-        when(mock.objectReturningMethodNoArgs()).thenAnswer(new ReturnsElementsOf(list));
+        when(mock.objectReturningMethodNoArgs()).thenAnswer(AdditionalAnswers.returnsElementsOf(list));
         
         //then
         assertEquals(1, mock.objectReturningMethodNoArgs());
@@ -52,7 +52,7 @@ public void shouldReturnNullIfNecessary() throws Exception {
     public void shouldScreamWhenNullPassed() throws Exception {
         try {
             //when
-            new ReturnsElementsOf(null);
+            AdditionalAnswers.returnsElementsOf(null);
             //then
             fail();
         } catch (MockitoException e) {}