Repository: mockito/mockito
Issue: Restore depecated Answers.get() method
Labels: bug

Commit da5e750957b494e7fa0548bf1286d67b8b0386d5 removed the deprecated `Answers.get()` method, however the method was only deprecated in the 2.0 BETA line and never made it into a GA release. It would be helpful if the method could remain in the deprecated form in 2.0 to give people an opportunity to move away from it.

(originally raise by a Spring Boot user [here](https://github.com/spring-projects/spring-boot/pull/6323))


Issue comments:
On a related note adding a "as of" to the deprecated description would also be useful:

``` java
/**
 * @deprecated as of 2.0 in favor of using the enum-constant directly. 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> .
 */
```

I would agree with @philwebb that this method had been made deprecated in 2.0 (-beta.2) not in 1.10.x (in fact at first it was [removed](https://github.com/mockito/mockito/commit/34f4436d988f04eaf7635b0497067ee8df7971a6) completely and one month later [restored](https://github.com/mockito/mockito/commit/32dce3ea56fb2891b54be48c16a13d2a9eb0cd33) as deprecated), but what is more important `Answers` started implementing `Answer` then. Because of that when I was fixing that issue in Spring Boot it was hard to keep code compatible with both versions at runtime (for 1.x casting using it as Answer does not work, for never 2.x `get()` is not available). In the end I had to [do](https://github.com/spring-projects/spring-boot/pull/6323/files) ugly casting through `Object` to fool the compiler. With that Spring Boot should work fine (at least with changes related to `Answers` :) ), but there could be other tools (PowerMock?) that after removing this method cannot be easily compatible with both Mockito 1.x and 2.x. IMHO it would be good to keep this method in 2.x and remove in 3.x.

Yes that seems like a good idea. Mind want to open a pull request?


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 5d86e9abdf..3f2ec706a1 100644
--- a/src/main/java/org/mockito/Answers.java
+++ b/src/main/java/org/mockito/Answers.java
@@ -5,11 +5,11 @@
 package org.mockito;
 
 import org.mockito.internal.stubbing.answers.CallsRealMethods;
-import org.mockito.internal.stubbing.defaultanswers.TriesToReturnSelf;
 import org.mockito.internal.stubbing.defaultanswers.GloballyConfiguredAnswer;
 import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
 import org.mockito.internal.stubbing.defaultanswers.ReturnsMocks;
 import org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls;
+import org.mockito.internal.stubbing.defaultanswers.TriesToReturnSelf;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
@@ -24,7 +24,7 @@
  * </code></pre>
  * <b>This is not the full list</b> of Answers available in Mockito. Some interesting answers can be found in org.mockito.stubbing.answers package.
  */
-public enum Answers implements Answer<Object>{
+public enum Answers implements Answer<Object> {
     /**
      * The default configured answer of every mock.
      *
@@ -78,8 +78,7 @@ public enum Answers implements Answer<Object>{
      *
      * @see org.mockito.Mockito#RETURNS_SELF
      */
-    RETURNS_SELF(new TriesToReturnSelf())
-    ;
+    RETURNS_SELF(new TriesToReturnSelf());
 
     private final Answer<Object> implementation;
 
@@ -87,7 +86,16 @@ 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);
-    } 
-}
\ No newline at end of file
+    }
+}


Test patch: