Repository: mockito/mockito
Issue: Get rid of ReturnValues
Labels: 1.* incompatible

`org.mockito.ReturnValues` has been deprecated for years, it should be removed in mockito 2.0


Issue comments:
Fixed by  #294


Pull request review comments:

Patch that resolved the issue:
diff --git a/src/main/java/org/mockito/Mockito.java b/src/main/java/org/mockito/Mockito.java
index 04f4a9e69e..e2eca63a6d 100644
--- a/src/main/java/org/mockito/Mockito.java
+++ b/src/main/java/org/mockito/Mockito.java
@@ -1327,41 +1327,6 @@ public static MockingDetails mockingDetails(Object toInspect) {
         return MOCKITO_CORE.mockingDetails(toInspect);
     }
 
-    /**
-     * <b>Deprecated : Please use mock(Foo.class, defaultAnswer);</b>
-     * <p>
-     * See {@link Mockito#mock(Class, Answer)}
-     * <p>
-     * Why it is deprecated? ReturnValues is being replaced by Answer
-     * for better consistency & interoperability of the framework.
-     * Answer interface has been in Mockito for a while and it has the same responsibility as ReturnValues.
-     * There's no point in mainting exactly the same interfaces.
-     * <p>
-     * Creates mock with a specified strategy for its return values.
-     * It's quite advanced feature and typically you don't need it to write decent tests.
-     * However it can be helpful when working with legacy systems.
-     * <p>
-     * Obviously return values are used only when you don't stub the method call.
-     *
-     * <pre class="code"><code class="java">
-     *   Foo mock = mock(Foo.class, Mockito.RETURNS_SMART_NULLS);
-     *   Foo mockTwo = mock(Foo.class, new YourOwnReturnValues());
-     * </code></pre>
-     *
-     * <p>See examples in javadoc for {@link Mockito} class</p>
-     *
-     * @param classToMock class or interface to mock
-     * @param returnValues default return values for unstubbed methods
-     *
-     * @return mock object
-     *
-     * @deprecated <b>Please use mock(Foo.class, defaultAnswer);</b>
-     */
-    @Deprecated
-    public static <T> T mock(Class<T> classToMock, ReturnValues returnValues) {
-        return mock(classToMock, withSettings().defaultAnswer(new AnswerReturnValuesAdapter(returnValues)));
-    }
-
     /**
      * Creates mock with a specified strategy for its answers to interactions.
      * It's quite advanced feature and typically you don't need it to write decent tests.
diff --git a/src/main/java/org/mockito/ReturnValues.java b/src/main/java/org/mockito/ReturnValues.java
deleted file mode 100644
index f9402129c2..0000000000
--- a/src/main/java/org/mockito/ReturnValues.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
-
-package org.mockito;
-
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-/**
- * @deprecated
- * <b>Instead, please use {@link Answer} interface</b>
- * <p>
- * In rare cases your code might not compile with recent deprecation & changes.
- * Very sorry for inconvenience but it had to be done in order to keep framework consistent.  
- * <p>
- * Why it is deprecated? ReturnValues is being replaced by Answer
- * for better consistency & interoperability of the framework. 
- * Answer interface has been in Mockito for a while and it has the same responsibility as ReturnValues.
- * There's no point in mainting exactly the same interfaces.
- * <p>
- * Configures return values for an unstubbed invocation
- * <p>
- * Can be used in {@link Mockito#mock(Class, ReturnValues)}
- */
-@Deprecated
-public interface ReturnValues {
-
-    /**
-     * return value for an unstubbed invocation
-     * 
-     * @param invocation placeholder for mock and a method
-     * @return the return value
-     */
-    Object valueFor(InvocationOnMock invocation) throws Throwable;
-}
\ No newline at end of file
diff --git a/src/main/java/org/mockito/configuration/DefaultMockitoConfiguration.java b/src/main/java/org/mockito/configuration/DefaultMockitoConfiguration.java
index fe9a8f6062..ce5714d0c0 100644
--- a/src/main/java/org/mockito/configuration/DefaultMockitoConfiguration.java
+++ b/src/main/java/org/mockito/configuration/DefaultMockitoConfiguration.java
@@ -4,7 +4,6 @@
  */
 package org.mockito.configuration;
 
-import org.mockito.ReturnValues;
 import org.mockito.internal.configuration.InjectingAnnotationEngine;
 import org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues;
 import org.mockito.stubbing.Answer;
@@ -16,17 +15,7 @@
  * <p>
  * See javadocs for {@link IMockitoConfiguration} on info how to configure Mockito
  */
-@SuppressWarnings("deprecation")//suppressed until ReturnValues are removed
 public class DefaultMockitoConfiguration implements IMockitoConfiguration {
-    
-    /* (non-Javadoc)
-     * @see org.mockito.IMockitoConfiguration#getReturnValues()
-     */
-    @Deprecated
-    public ReturnValues getReturnValues() {
-        throw new RuntimeException("\n" + "This method should not be used by the framework because it was deprecated"
-                + "\n" + "Please report the failure to the Mockito mailing list");
-    }
 
     public Answer<Object> getDefaultAnswer() {
         return new ReturnsEmptyValues();
diff --git a/src/main/java/org/mockito/configuration/IMockitoConfiguration.java b/src/main/java/org/mockito/configuration/IMockitoConfiguration.java
index 2f693879ff..cebd25f366 100644
--- a/src/main/java/org/mockito/configuration/IMockitoConfiguration.java
+++ b/src/main/java/org/mockito/configuration/IMockitoConfiguration.java
@@ -4,7 +4,6 @@
  */
 package org.mockito.configuration;
 
-import org.mockito.ReturnValues;
 import org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues;
 import org.mockito.stubbing.Answer;
 
@@ -26,31 +25,8 @@
  * <p>
  * If you have comments on Mockito configuration feature don't hesitate to write to mockito@googlegroups.com
  */
-@SuppressWarnings("deprecation")//suppressed until ReturnValues are removed
 public interface IMockitoConfiguration {
 
-    /**
-     * @deprecated
-     * <b>Please use {@link IMockitoConfiguration#getDefaultAnswer()}</b>
-     * <p>
-     * Steps: 
-     * <p>
-     * 1. Leave the implementation of getReturnValues() method empty - it's not going to be used anyway.
-     * <p>
-     * 2. Implement getDefaultAnswer() instead.
-     * <p>
-     * In rare cases your code might not compile with recent deprecation & changes.
-     * Very sorry for inconvenience but it had to be done in order to keep framework consistent.
-     * <p>
-     * See javadoc {@link ReturnValues} for info why this method was deprecated
-     * <p>
-     * Allows configuring the default return values of unstubbed invocations
-     * <p>
-     * See javadoc for {@link IMockitoConfiguration}
-     */
-    @Deprecated
-    ReturnValues getReturnValues();
-    
     /**
      * Allows configuring the default answers of unstubbed invocations
      * <p>
diff --git a/src/main/java/org/mockito/internal/configuration/GlobalConfiguration.java b/src/main/java/org/mockito/internal/configuration/GlobalConfiguration.java
index 9a54c27a69..c8a94e8937 100644
--- a/src/main/java/org/mockito/internal/configuration/GlobalConfiguration.java
+++ b/src/main/java/org/mockito/internal/configuration/GlobalConfiguration.java
@@ -4,7 +4,6 @@
  */
 package org.mockito.internal.configuration;
 
-import org.mockito.ReturnValues;
 import org.mockito.configuration.AnnotationEngine;
 import org.mockito.configuration.DefaultMockitoConfiguration;
 import org.mockito.configuration.IMockitoConfiguration;
@@ -15,7 +14,6 @@
 /**
  * Thread-safe wrapper on user-defined org.mockito.configuration.MockitoConfiguration implementation
  */
-@SuppressWarnings("deprecation")//suppressed until ReturnValues are removed
 public class GlobalConfiguration implements IMockitoConfiguration, Serializable {
     private static final long serialVersionUID = -2860353062105505938L;
     
@@ -47,10 +45,6 @@ public static void validate() {
         new GlobalConfiguration();
     }
 
-    public ReturnValues getReturnValues() {
-        return GLOBAL_CONFIGURATION.get().getReturnValues();
-    }
-
     public AnnotationEngine getAnnotationEngine() {
         return GLOBAL_CONFIGURATION.get().getAnnotationEngine();
     }
diff --git a/src/main/java/org/mockito/internal/stubbing/answers/AnswerReturnValuesAdapter.java b/src/main/java/org/mockito/internal/stubbing/answers/AnswerReturnValuesAdapter.java
deleted file mode 100644
index 1d5492ed31..0000000000
--- a/src/main/java/org/mockito/internal/stubbing/answers/AnswerReturnValuesAdapter.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
-package org.mockito.internal.stubbing.answers;
-
-import java.io.Serializable;
-
-import org.mockito.ReturnValues;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-//It's ok to suppress deprecation because this class goes away as soon as ReturnValues disappears in future release
-@SuppressWarnings("deprecation")
-public class AnswerReturnValuesAdapter implements Answer<Object>, Serializable {
-
-    private static final long serialVersionUID = 1418158596876713469L;
-    private final ReturnValues returnValues;
-
-    public AnswerReturnValuesAdapter(ReturnValues returnValues) {
-        this.returnValues = returnValues;
-    }
-
-    public Object answer(InvocationOnMock invocation) throws Throwable {
-        return returnValues.valueFor(invocation);
-    }
-}
\ No newline at end of file
diff --git a/src/main/java/org/mockito/internal/stubbing/defaultanswers/ForwardsInvocations.java b/src/main/java/org/mockito/internal/stubbing/defaultanswers/ForwardsInvocations.java
index df86442619..1916a62ce2 100644
--- a/src/main/java/org/mockito/internal/stubbing/defaultanswers/ForwardsInvocations.java
+++ b/src/main/java/org/mockito/internal/stubbing/defaultanswers/ForwardsInvocations.java
@@ -9,9 +9,6 @@
 import java.lang.reflect.Method;
 
 import org.mockito.exceptions.Reporter;
-import org.mockito.exceptions.base.MockitoException;
-import org.mockito.internal.stubbing.answers.MethodInfo;
-import org.mockito.internal.util.Primitives;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
diff --git a/src/main/java/org/mockito/internal/stubbing/defaultanswers/package.html b/src/main/java/org/mockito/internal/stubbing/defaultanswers/package.html
index 15877151bd..f2dee90a8c 100644
--- a/src/main/java/org/mockito/internal/stubbing/defaultanswers/package.html
+++ b/src/main/java/org/mockito/internal/stubbing/defaultanswers/package.html
@@ -4,5 +4,5 @@
   -->
 
 <body>
-Implementations of ReturnValues
+Implementations of Answer
 </body>
\ No newline at end of file


Test patch: