Repository: mockito/mockito
Issue: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String
Labels: bug

Exception throws on verifyZeroInteractions when using mock with default answer.
checked on versions 1.10.5-2.0.5
all ok on 1.9.5


Issue comments:
Hi,

Do you have a JUnit test so that we could reproduce.
Also please see the [contributing guide](https://github.com/mockito/mockito/blob/master/CONTRIBUTING.md).

``` java
public class MockitoTest extends Mockito {
    public interface TestMock {
        public boolean m1();
    };

    @Test
    public void test() {
        TestMock test = mock(TestMock.class, new Answer() {
            @Override public Object answer(InvocationOnMock invocation) throws Throwable {
                return false;
            }
        });
        test.m1();
        verifyZeroInteractions(test);
    }
}
```

Hi, sorry for the late reply.

Thanks for the testcase, indeed we missed something there.

For reference the stacktrace is :

```
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
    at org.mockitousage.bugs.ClassCastExOnVerifyZeroInteractionsTest$TestMock$$EnhancerByMockitoWithCGLIB$$91d883c5.toString(<generated>)
    at java.lang.String.valueOf(String.java:2847)
    at java.lang.StringBuilder.append(StringBuilder.java:128)
    at org.mockito.exceptions.Reporter.noMoreInteractionsWanted(Reporter.java:420)
    at org.mockito.internal.verification.NoMoreInteractions.verify(NoMoreInteractions.java:24)
    at org.mockito.internal.MockitoCore.verifyNoMoreInteractions(MockitoCore.java:113)
    at org.mockito.Mockito.verifyZeroInteractions(Mockito.java:1674)
    at org.mockitousage.bugs.ClassCastExOnVerifyZeroInteractionsTest.test(ClassCastExOnVerifyZeroInteractionsTest.java:23)
```

Actually the usage report was improved to include the mock name, however in this usage the default answer always returns `false`. So when the String message is generated there's a CCE because the default answer returns a `boolean`.

On your side the workaround is to return valid values for these `Object` inherited methods.

On mockito side there should be two possible thing to do:
- get the name safely without invoking `toString`
- validate more aggressively answer's result

Hello, I've one doubt, can we do casting for mocking objects?. When I tried to do that I got "java.lang.ClassCastException".

Pull request review comments:

Patch that resolved the issue:
diff --git a/src/org/mockito/exceptions/Reporter.java b/src/org/mockito/exceptions/Reporter.java
index 7ae75886c0..e0b1105daf 100644
--- a/src/org/mockito/exceptions/Reporter.java
+++ b/src/org/mockito/exceptions/Reporter.java
@@ -8,7 +8,13 @@
 import org.mockito.exceptions.base.MockitoAssertionError;
 import org.mockito.exceptions.base.MockitoException;
 import org.mockito.exceptions.misusing.*;
-import org.mockito.exceptions.verification.*;
+import org.mockito.exceptions.verification.NeverWantedButInvoked;
+import org.mockito.exceptions.verification.NoInteractionsWanted;
+import org.mockito.exceptions.verification.SmartNullPointerException;
+import org.mockito.exceptions.verification.TooLittleActualInvocations;
+import org.mockito.exceptions.verification.TooManyActualInvocations;
+import org.mockito.exceptions.verification.VerificationInOrderFailure;
+import org.mockito.exceptions.verification.WantedButNotInvoked;
 import org.mockito.internal.debugging.LocationImpl;
 import org.mockito.internal.exceptions.MockitoLimitations;
 import org.mockito.internal.exceptions.VerificationAwareInvocation;
@@ -22,6 +28,7 @@
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.invocation.Location;
 import org.mockito.listeners.InvocationListener;
+import org.mockito.mock.MockName;
 import org.mockito.mock.SerializableMode;
 
 import java.lang.reflect.Field;
@@ -231,7 +238,7 @@ public void inOrderRequiresFamiliarMock() {
     public void invalidUseOfMatchers(int expectedMatchersCount, List<LocalizedMatcher> recordedMatchers) {
         throw new InvalidUseOfMatchersException(join(
                 "Invalid use of argument matchers!",
-                expectedMatchersCount + " matchers expected, " + recordedMatchers.size()+ " recorded:" +
+                expectedMatchersCount + " matchers expected, " + recordedMatchers.size() + " recorded:" +
                         locationsOf(recordedMatchers),
                 "",
                 "This exception may occur if matchers are combined with raw values:",
@@ -387,7 +394,7 @@ public void tooManyActualInvocationsInOrder(int wantedCount, int actualCount, De
     private String createTooLittleInvocationsMessage(org.mockito.internal.reporting.Discrepancy discrepancy, DescribedInvocation wanted,
                                                      Location lastActualInvocation) {
         String ending =
-                (lastActualInvocation != null)? lastActualInvocation + "\n" : "\n";
+                (lastActualInvocation != null) ? lastActualInvocation + "\n" : "\n";
 
         String message = join(
                 wanted.toString(),
@@ -420,7 +427,7 @@ public void noMoreInteractionsWanted(Invocation undesired, List<VerificationAwar
         throw new NoInteractionsWanted(join(
                 "No interactions wanted here:",
                 new LocationImpl(),
-                "But found this interaction on mock '" + undesired.getMock() + "':",
+                "But found this interaction on mock '" + safelyGetMockName(undesired.getMock()) + "':",
                 undesired.getLocation(),
                 scenario
         ));
@@ -430,7 +437,7 @@ public void noMoreInteractionsWantedInOrder(Invocation undesired) {
         throw new VerificationInOrderFailure(join(
                 "No interactions wanted here:",
                 new LocationImpl(),
-                "But found this interaction on mock '" + undesired.getMock() + "':",
+                "But found this interaction on mock '" + safelyGetMockName(undesired.getMock()) + "':",
                 undesired.getLocation()
         ));
     }
@@ -489,6 +496,18 @@ public void wrongTypeOfReturnValue(String expectedType, String actualType, Strin
         ));
     }
 
+    public void wrongTypeReturnedByDefaultAnswer(Object mock, String expectedType, String actualType, String methodName) {
+        throw new WrongTypeOfReturnValue(join(
+                "Default answer returned a result with the wrong type:",
+                actualType + " cannot be returned by " + methodName + "()",
+                methodName + "() should return " + expectedType,
+                "",
+                "The default answer of " + safelyGetMockName(mock) + " that was configured on the mock is probably incorrectly implemented.",
+                ""
+        ));
+    }
+
+
     public void wantedAtMostX(int maxNumberOfInvocations, int foundSize) {
         throw new MockitoAssertionError(join("Wanted at most " + pluralize(maxNumberOfInvocations) + " but was " + foundSize));
     }
@@ -641,7 +660,7 @@ public void atMostAndNeverShouldNotBeUsedWithTimeout() {
 
     public void fieldInitialisationThrewException(Field field, Throwable details) {
         throw new MockitoException(join(
-                "Cannot instantiate @InjectMocks field named '" + field.getName() + "' of type '" + field.getType() +  "'.",
+                "Cannot instantiate @InjectMocks field named '" + field.getName() + "' of type '" + field.getType() + "'.",
                 "You haven't provided the instance at field declaration so I tried to construct the instance.",
                 "However the constructor or the initialization block threw an exception : " + details.getMessage(),
                 ""), details);
@@ -664,14 +683,21 @@ public void invocationListenerThrewException(InvocationListener listener, Throwa
 
     public void cannotInjectDependency(Field field, Object matchingMock, Exception details) {
         throw new MockitoException(join(
-                "Mockito couldn't inject mock dependency '" + new MockUtil().getMockName(matchingMock) + "' on field ",
+                "Mockito couldn't inject mock dependency '" + safelyGetMockName(matchingMock) + "' on field ",
                 "'" + field + "'",
                 "whose type '" + field.getDeclaringClass().getCanonicalName() + "' was annotated by @InjectMocks in your test.",
-                "Also I failed because: " + details.getCause().getMessage(),
+                "Also I failed because: " + exceptionCauseMessageIfAvailable(details),
                 ""
         ), details);
     }
 
+    private String exceptionCauseMessageIfAvailable(Exception details) {
+        if (details.getCause() == null) {
+            return details.getMessage();
+        }
+        return details.getCause().getMessage();
+    }
+
     public void mockedTypeIsInconsistentWithDelegatedInstanceType(Class mockedType, Object delegatedInstance) {
         throw new MockitoException(join(
                 "Mocked type must be the same as the type of your delegated instance.",
@@ -686,7 +712,7 @@ public void mockedTypeIsInconsistentWithDelegatedInstanceType(Class mockedType,
     public void spyAndDelegateAreMutuallyExclusive() {
         throw new MockitoException(join(
                 "Settings should not define a spy instance and a delegated instance at the same time."
-        )) ;
+        ));
     }
 
     public void invalidArgumentRangeAtIdentityAnswerCreationTime() {
@@ -699,7 +725,7 @@ public void invalidArgumentRangeAtIdentityAnswerCreationTime() {
     public int invalidArgumentPositionRangeAtInvocationTime(InvocationOnMock invocation, boolean willReturnLastParameter, int argumentIndex) {
         throw new MockitoException(
                 join("Invalid argument index for the current invocation of method : ",
-                        " -> " + new MockUtil().getMockName(invocation.getMock()) + "." + invocation.getMethod().getName() + "()",
+                        " -> " + safelyGetMockName(invocation.getMock()) + "." + invocation.getMethod().getName() + "()",
                         "",
                         (willReturnLastParameter ?
                                 "Last parameter wanted" :
@@ -732,7 +758,7 @@ public void wrongTypeOfArgumentToReturn(InvocationOnMock invocation, String expe
         throw new WrongTypeOfReturnValue(join(
                 "The argument of type '" + actualType.getSimpleName() + "' cannot be returned because the following ",
                 "method should return the type '" + expectedType + "'",
-                " -> " + new MockUtil().getMockName(invocation.getMock()) + "." + invocation.getMethod().getName() + "()",
+                " -> " + safelyGetMockName(invocation.getMock()) + "." + invocation.getMethod().getName() + "()",
                 "",
                 "The reason for this error can be :",
                 "1. The wanted argument position is incorrect.",
@@ -765,28 +791,32 @@ public void serializableWontWorkForObjectsThatDontImplementSerializable(Class cl
                 ""
         ));
     }
-    
+
     public void delegatedMethodHasWrongReturnType(Method mockMethod, Method delegateMethod, Object mock, Object delegate) {
-    	throw new MockitoException(join(
-    	        "Methods called on delegated instance must have compatible return types with the mock.",
-    	        "When calling: " + mockMethod + " on mock: " + new MockUtil().getMockName(mock),
-    	        "return type should be: " + mockMethod.getReturnType().getSimpleName() + ", but was: " + delegateMethod.getReturnType().getSimpleName(),
-    	        "Check that the instance passed to delegatesTo() is of the correct type or contains compatible methods",
-    	        "(delegate instance had type: " + delegate.getClass().getSimpleName() + ")"
-    	));
-    }
-
-	public void delegatedMethodDoesNotExistOnDelegate(Method mockMethod, Object mock, Object delegate) {
-		throw new MockitoException(join(
-    	        "Methods called on mock must exist in delegated instance.",
-    	        "When calling: " + mockMethod + " on mock: " + new MockUtil().getMockName(mock),
-    	        "no such method was found.",
-    	        "Check that the instance passed to delegatesTo() is of the correct type or contains compatible methods",
-    	        "(delegate instance had type: " + delegate.getClass().getSimpleName() + ")"
-    	));
-	}
+        throw new MockitoException(join(
+                "Methods called on delegated instance must have compatible return types with the mock.",
+                "When calling: " + mockMethod + " on mock: " + safelyGetMockName(mock),
+                "return type should be: " + mockMethod.getReturnType().getSimpleName() + ", but was: " + delegateMethod.getReturnType().getSimpleName(),
+                "Check that the instance passed to delegatesTo() is of the correct type or contains compatible methods",
+                "(delegate instance had type: " + delegate.getClass().getSimpleName() + ")"
+        ));
+    }
+
+    public void delegatedMethodDoesNotExistOnDelegate(Method mockMethod, Object mock, Object delegate) {
+        throw new MockitoException(join(
+                "Methods called on mock must exist in delegated instance.",
+                "When calling: " + mockMethod + " on mock: " + safelyGetMockName(mock),
+                "no such method was found.",
+                "Check that the instance passed to delegatesTo() is of the correct type or contains compatible methods",
+                "(delegate instance had type: " + delegate.getClass().getSimpleName() + ")"
+        ));
+    }
 
     public void usingConstructorWithFancySerializable(SerializableMode mode) {
         throw new MockitoException("Mocks instantiated with constructor cannot be combined with " + mode + " serialization mode.");
     }
+
+    private MockName safelyGetMockName(Object mock) {
+        return new MockUtil().getMockName(mock);
+    }
 }
diff --git a/src/org/mockito/internal/handler/MockHandlerImpl.java b/src/org/mockito/internal/handler/MockHandlerImpl.java
index a49c1a98b7..00766a0d0d 100644
--- a/src/org/mockito/internal/handler/MockHandlerImpl.java
+++ b/src/org/mockito/internal/handler/MockHandlerImpl.java
@@ -10,7 +10,12 @@
 import org.mockito.internal.invocation.MatchersBinder;
 import org.mockito.internal.progress.MockingProgress;
 import org.mockito.internal.progress.ThreadSafeMockingProgress;
-import org.mockito.internal.stubbing.*;
+import org.mockito.internal.stubbing.InvocationContainer;
+import org.mockito.internal.stubbing.InvocationContainerImpl;
+import org.mockito.internal.stubbing.OngoingStubbingImpl;
+import org.mockito.internal.stubbing.StubbedInvocationMatcher;
+import org.mockito.internal.stubbing.VoidMethodStubbableImpl;
+import org.mockito.internal.stubbing.answers.AnswersValidator;
 import org.mockito.internal.verification.MockAwareVerificationMode;
 import org.mockito.internal.verification.VerificationDataImpl;
 import org.mockito.invocation.Invocation;
@@ -23,9 +28,8 @@
 
 /**
  * Invocation handler set on mock objects.
- * 
- * @param <T>
- *            type of mock object to handle
+ *
+ * @param <T> type of mock object to handle
  */
 class MockHandlerImpl<T> implements InternalMockHandler<T> {
 
@@ -45,7 +49,7 @@ public MockHandlerImpl(MockCreationSettings mockSettings) {
     }
 
     public Object handle(Invocation invocation) throws Throwable {
-		if (invocationContainerImpl.hasAnswersForStubbing()) {
+        if (invocationContainerImpl.hasAnswersForStubbing()) {
             // stubbing voids with stubVoid() or doAnswer() style
             InvocationMatcher invocationMatcher = matchersBinder.bindMatchers(
                     mockingProgress.getArgumentMatcherStorage(),
@@ -90,7 +94,8 @@ public Object handle(Invocation invocation) throws Throwable {
             stubbedInvocation.captureArgumentsFrom(invocation);
             return stubbedInvocation.answer(invocation);
         } else {
-             Object ret = mockSettings.getDefaultAnswer().answer(invocation);
+            Object ret = mockSettings.getDefaultAnswer().answer(invocation);
+            new AnswersValidator().validateDefaultAnswerReturnedValue(invocation, ret);
 
             // redo setting invocation for potential stubbing in case of partial
             // mocks / spies.
@@ -100,7 +105,7 @@ public Object handle(Invocation invocation) throws Throwable {
             invocationContainerImpl.resetInvocationForPotentialStubbing(invocationMatcher);
             return ret;
         }
-	}
+    }
 
     public VoidMethodStubbable<T> voidMethodStubbable(T mock) {
         return new VoidMethodStubbableImpl<T>(mock, invocationContainerImpl);
diff --git a/src/org/mockito/internal/invocation/InvocationImpl.java b/src/org/mockito/internal/invocation/InvocationImpl.java
index 19193fa165..dc77a57e25 100644
--- a/src/org/mockito/internal/invocation/InvocationImpl.java
+++ b/src/org/mockito/internal/invocation/InvocationImpl.java
@@ -105,6 +105,10 @@ public Object[] getRawArguments() {
         return this.rawArguments;
     }
 
+    public Class<?> getRawReturnType() {
+        return method.getReturnType();
+    }
+
     public Object callRealMethod() throws Throwable {
         if (method.isAbstract()) {
             new Reporter().cannotCallAbstractRealMethod();
@@ -131,4 +135,4 @@ public boolean isIgnoredForVerification() {
     public void ignoreForVerification() {
         isIgnoredForVerification = true;
     }
-}
\ No newline at end of file
+}
diff --git a/src/org/mockito/internal/stubbing/answers/AnswersValidator.java b/src/org/mockito/internal/stubbing/answers/AnswersValidator.java
index 57adb3881c..66bbf54c58 100644
--- a/src/org/mockito/internal/stubbing/answers/AnswersValidator.java
+++ b/src/org/mockito/internal/stubbing/answers/AnswersValidator.java
@@ -11,21 +11,21 @@
 public class AnswersValidator {
 
     private final Reporter reporter = new Reporter();
-    
+
     public void validate(Answer<?> answer, Invocation invocation) {
         MethodInfo methodInfo = new MethodInfo(invocation);
         if (answer instanceof ThrowsException) {
             validateException((ThrowsException) answer, methodInfo);
         }
-        
+
         if (answer instanceof Returns) {
             validateReturnValue((Returns) answer, methodInfo);
         }
-        
+
         if (answer instanceof DoesNothing) {
             validateDoNothing((DoesNothing) answer, methodInfo);
         }
-        
+
         if (answer instanceof CallsRealMethods) {
             validateMockingConcreteClass((CallsRealMethods) answer, methodInfo);
         }
@@ -42,8 +42,8 @@ private void validateReturnArgIdentity(ReturnsArgumentAt returnsArgumentAt, Invo
         MethodInfo methodInfo = new MethodInfo(invocation);
         if (!methodInfo.isValidReturnType(returnsArgumentAt.returnedTypeOnSignature(invocation))) {
             new Reporter().wrongTypeOfArgumentToReturn(invocation, methodInfo.printMethodReturnType(),
-                                                       returnsArgumentAt.returnedTypeOnSignature(invocation),
-                                                       returnsArgumentAt.wantedArgumentPosition());
+                    returnsArgumentAt.returnedTypeOnSignature(invocation),
+                    returnsArgumentAt.wantedArgumentPosition());
         }
 
     }
@@ -64,10 +64,10 @@ private void validateReturnValue(Returns answer, MethodInfo methodInfo) {
         if (methodInfo.isVoid()) {
             reporter.cannotStubVoidMethodWithAReturnValue(methodInfo.getMethodName());
         }
-        
+
         if (answer.returnsNull() && methodInfo.returnsPrimitive()) {
             reporter.wrongTypeOfReturnValue(methodInfo.printMethodReturnType(), "null", methodInfo.getMethodName());
-        } 
+        }
 
         if (!answer.returnsNull() && !methodInfo.isValidReturnType(answer.getReturnType())) {
             reporter.wrongTypeOfReturnValue(methodInfo.printMethodReturnType(), answer.printReturnType(), methodInfo.getMethodName());
@@ -79,13 +79,24 @@ private void validateException(ThrowsException answer, MethodInfo methodInfo) {
         if (throwable == null) {
             reporter.cannotStubWithNullThrowable();
         }
-        
+
         if (throwable instanceof RuntimeException || throwable instanceof Error) {
             return;
         }
-        
+
         if (!methodInfo.isValidException(throwable)) {
             reporter.checkedExceptionInvalid(throwable);
         }
     }
-}
\ No newline at end of file
+
+    public void validateDefaultAnswerReturnedValue(Invocation invocation, Object returnedValue) {
+        MethodInfo methodInfo = new MethodInfo(invocation);
+        if (returnedValue != null && !methodInfo.isValidReturnType(returnedValue.getClass())) {
+            reporter.wrongTypeReturnedByDefaultAnswer(
+                    invocation.getMock(),
+                    methodInfo.printMethodReturnType(),
+                    returnedValue.getClass().getSimpleName(),
+                    methodInfo.getMethodName());
+        }
+    }
+}
diff --git a/src/org/mockito/invocation/Invocation.java b/src/org/mockito/invocation/Invocation.java
index 0146697309..7c1bdd5576 100644
--- a/src/org/mockito/invocation/Invocation.java
+++ b/src/org/mockito/invocation/Invocation.java
@@ -41,6 +41,14 @@ public interface Invocation extends InvocationOnMock, DescribedInvocation {
      */
     Object[] getRawArguments();
 
+    /**
+     * Returns unprocessed arguments whereas {@link #getArguments()} returns
+     * arguments already processed (e.g. varargs expended, etc.).
+     *
+     * @return unprocessed arguments, exactly as provided to this invocation.
+     */
+    Class getRawReturnType();
+
     /**
      * Marks this invocation as verified so that it will not cause verification error at
      * {@link org.mockito.Mockito#verifyNoMoreInteractions(Object...)}


Test patch:
diff --git a/test/org/mockito/exceptions/ReporterTest.java b/test/org/mockito/exceptions/ReporterTest.java
index e006852784..3253ad819d 100644
--- a/test/org/mockito/exceptions/ReporterTest.java
+++ b/test/org/mockito/exceptions/ReporterTest.java
@@ -6,21 +6,81 @@
 package org.mockito.exceptions;
 
 import org.junit.Test;
+import org.mockito.Mockito;
 import org.mockito.exceptions.base.MockitoException;
+import org.mockito.exceptions.verification.NoInteractionsWanted;
 import org.mockito.exceptions.verification.TooLittleActualInvocations;
+import org.mockito.exceptions.verification.VerificationInOrderFailure;
+import org.mockito.internal.exceptions.VerificationAwareInvocation;
 import org.mockito.internal.invocation.InvocationBuilder;
-import org.mockito.internal.reporting.*;
+import org.mockito.internal.stubbing.answers.Returns;
+import org.mockito.invocation.Invocation;
+import org.mockitousage.IMethods;
 import org.mockitoutil.TestBase;
 
+import java.lang.reflect.Field;
+import java.util.Collections;
+
+import static org.mockito.Mockito.mock;
+
 public class ReporterTest extends TestBase {
 
-    @Test(expected=TooLittleActualInvocations.class)
-    public void shouldLetPassingNullLastActualStackTrace() throws Exception {
+    @Test(expected = TooLittleActualInvocations.class)
+    public void should_let_passing_null_last_actual_stack_trace() throws Exception {
         new Reporter().tooLittleActualInvocations(new org.mockito.internal.reporting.Discrepancy(1, 2), new InvocationBuilder().toInvocation(), null);
     }
-    
-    @Test(expected=MockitoException.class)
-    public void shouldThrowCorrectExceptionForNullInvocationListener() throws Exception {
-    	new Reporter().invocationListenerDoesNotAcceptNullParameters();
+
+    @Test(expected = MockitoException.class)
+    public void should_throw_correct_exception_for_null_invocation_listener() throws Exception {
+        new Reporter().invocationListenerDoesNotAcceptNullParameters();
+    }
+
+    @Test(expected = NoInteractionsWanted.class)
+    public void can_use_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_no_more_interaction_wanted() throws Exception {
+        Invocation invocation_with_bogus_default_answer = new InvocationBuilder().mock(mock(IMethods.class, new Returns(false))).toInvocation();
+        new Reporter().noMoreInteractionsWanted(invocation_with_bogus_default_answer, Collections.<VerificationAwareInvocation>emptyList());
+    }
+
+    @Test(expected = VerificationInOrderFailure.class)
+    public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_no_more_interaction_wanted_in_order() throws Exception {
+        Invocation invocation_with_bogus_default_answer = new InvocationBuilder().mock(mock(IMethods.class, new Returns(false))).toInvocation();
+        new Reporter().noMoreInteractionsWantedInOrder(invocation_with_bogus_default_answer);
+    }
+
+    @Test(expected = MockitoException.class)
+    public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_invalid_argument_position() throws Exception {
+        Invocation invocation_with_bogus_default_answer = new InvocationBuilder().mock(mock(IMethods.class, new Returns(false))).toInvocation();
+        new Reporter().invalidArgumentPositionRangeAtInvocationTime(invocation_with_bogus_default_answer, true, 0);
+    }
+
+    @Test(expected = MockitoException.class)
+    public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_wrong_argument_to_return() throws Exception {
+        Invocation invocation_with_bogus_default_answer = new InvocationBuilder().mock(mock(IMethods.class, new Returns(false))).toInvocation();
+        new Reporter().wrongTypeOfArgumentToReturn(invocation_with_bogus_default_answer, "", String.class, 0);
+    }
+
+    @Test(expected = MockitoException.class)
+    public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_dont_exists() throws Exception {
+        Invocation dumb_invocation = new InvocationBuilder().toInvocation();
+        IMethods mock_with_bogus_default_answer = mock(IMethods.class, new Returns(false));
+        new Reporter().delegatedMethodDoesNotExistOnDelegate(dumb_invocation.getMethod(), mock_with_bogus_default_answer, String.class);
+    }
+
+    @Test(expected = MockitoException.class)
+    public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_has_wrong_return_type() throws Exception {
+        Invocation dumb_invocation = new InvocationBuilder().toInvocation();
+        IMethods mock_with_bogus_default_answer = mock(IMethods.class, new Returns(false));
+        new Reporter().delegatedMethodHasWrongReturnType(dumb_invocation.getMethod(), dumb_invocation.getMethod(), mock_with_bogus_default_answer, String.class);
     }
+
+    @Test(expected = MockitoException.class)
+    public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_injection_failure() throws Exception {
+        IMethods mock_with_bogus_default_answer = mock(IMethods.class, new Returns(false));
+        new Reporter().cannotInjectDependency(someField(), mock_with_bogus_default_answer, new Exception());
+    }
+
+    private Field someField() {
+        return Mockito.class.getDeclaredFields()[0];
+    }
+
 }
diff --git a/test/org/mockito/internal/handler/MockHandlerImplTest.java b/test/org/mockito/internal/handler/MockHandlerImplTest.java
index 8999fb4e55..104c4be6b5 100644
--- a/test/org/mockito/internal/handler/MockHandlerImplTest.java
+++ b/test/org/mockito/internal/handler/MockHandlerImplTest.java
@@ -8,6 +8,7 @@
 import org.junit.Test;
 import org.mockito.exceptions.base.MockitoException;
 import org.mockito.exceptions.misusing.InvalidUseOfMatchersException;
+import org.mockito.exceptions.misusing.WrongTypeOfReturnValue;
 import org.mockito.internal.creation.MockSettingsImpl;
 import org.mockito.internal.invocation.InvocationBuilder;
 import org.mockito.internal.invocation.InvocationImpl;
@@ -16,6 +17,7 @@
 import org.mockito.internal.progress.ArgumentMatcherStorage;
 import org.mockito.internal.stubbing.InvocationContainerImpl;
 import org.mockito.internal.stubbing.StubbedInvocationMatcher;
+import org.mockito.internal.stubbing.answers.Returns;
 import org.mockito.internal.verification.VerificationModeFactory;
 import org.mockito.invocation.Invocation;
 import org.mockito.listeners.InvocationListener;
@@ -29,79 +31,88 @@
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 
-@SuppressWarnings({ "unchecked", "serial" })
+@SuppressWarnings({"unchecked", "serial"})
 public class MockHandlerImplTest extends TestBase {
 
-	private StubbedInvocationMatcher stubbedInvocationMatcher = mock(StubbedInvocationMatcher.class);
-	private Invocation invocation = mock(InvocationImpl.class);
+    private StubbedInvocationMatcher stubbedInvocationMatcher = mock(StubbedInvocationMatcher.class);
+    private Invocation invocation = mock(InvocationImpl.class);
 
 
-	@Test
-	public void shouldRemoveVerificationModeEvenWhenInvalidMatchers() throws Throwable {
-		// given
-		Invocation invocation = new InvocationBuilder().toInvocation();
-		@SuppressWarnings("rawtypes")
+    @Test
+    public void should_remove_verification_mode_even_when_invalid_matchers() throws Throwable {
+        // given
+        Invocation invocation = new InvocationBuilder().toInvocation();
+        @SuppressWarnings("rawtypes")
         MockHandlerImpl<?> handler = new MockHandlerImpl(new MockSettingsImpl());
-		handler.mockingProgress.verificationStarted(VerificationModeFactory.atLeastOnce());
-		handler.matchersBinder = new MatchersBinder() {
-			public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, Invocation invocation) {
-				throw new InvalidUseOfMatchersException();
-			}
-		};
-
-		try {
-			// when
-			handler.handle(invocation);
-
-			// then
-			fail();
-		} catch (InvalidUseOfMatchersException e) {
-		}
-
-		assertNull(handler.mockingProgress.pullVerificationMode());
-	}
-
-
-
-
-	@Test(expected = MockitoException.class)
-	public void shouldThrowMockitoExceptionWhenInvocationHandlerThrowsAnything() throws Throwable {
-		// given
-		InvocationListener throwingListener = mock(InvocationListener.class);
-		doThrow(new Throwable()).when(throwingListener).reportInvocation(any(MethodInvocationReport.class));
-		MockHandlerImpl<?> handler = createCorrectlyStubbedHandler(throwingListener);
-
-		// when
-		handler.handle(invocation);
-	}
-
-
-
-	private MockHandlerImpl<?> createCorrectlyStubbedHandler(InvocationListener throwingListener) {
-		MockHandlerImpl<?> handler = createHandlerWithListeners(throwingListener);
-		stubOrdinaryInvocationWithGivenReturnValue(handler);
-		return handler;
-	}
-
-	private void stubOrdinaryInvocationWithGivenReturnValue(MockHandlerImpl<?> handler) {
-		stubOrdinaryInvocationWithInvocationMatcher(handler, stubbedInvocationMatcher);
-	}
-
-
-
-	private void stubOrdinaryInvocationWithInvocationMatcher(MockHandlerImpl<?> handler, StubbedInvocationMatcher value) {
-		handler.invocationContainerImpl = mock(InvocationContainerImpl.class);
-		given(handler.invocationContainerImpl.findAnswerFor(any(InvocationImpl.class))).willReturn(value);
-	}
-
-
-
-
-	private MockHandlerImpl<?> createHandlerWithListeners(InvocationListener... listener) {
-		@SuppressWarnings("rawtypes")
+        handler.mockingProgress.verificationStarted(VerificationModeFactory.atLeastOnce());
+        handler.matchersBinder = new MatchersBinder() {
+            public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, Invocation invocation) {
+                throw new InvalidUseOfMatchersException();
+            }
+        };
+
+        try {
+            // when
+            handler.handle(invocation);
+
+            // then
+            fail();
+        } catch (InvalidUseOfMatchersException ignored) {
+        }
+
+        assertNull(handler.mockingProgress.pullVerificationMode());
+    }
+
+
+    @Test(expected = MockitoException.class)
+    public void should_throw_mockito_exception_when_invocation_handler_throws_anything() throws Throwable {
+        // given
+        InvocationListener throwingListener = mock(InvocationListener.class);
+        doThrow(new Throwable()).when(throwingListener).reportInvocation(any(MethodInvocationReport.class));
+        MockHandlerImpl<?> handler = create_correctly_stubbed_handler(throwingListener);
+
+        // when
+        handler.handle(invocation);
+    }
+
+    @Test(expected = WrongTypeOfReturnValue.class)
+    public void should_report_bogus_default_answer() throws Throwable {
+        MockSettingsImpl mockSettings = mock(MockSettingsImpl.class);
+        MockHandlerImpl<?> handler = new MockHandlerImpl(mockSettings);
+        given(mockSettings.getDefaultAnswer()).willReturn(new Returns(AWrongType.WRONG_TYPE));
+
+        @SuppressWarnings("unused") // otherwise cast is not done
+        String there_should_not_be_a_CCE_here = (String) handler.handle(
+                new InvocationBuilder().method(Object.class.getDeclaredMethod("toString")).toInvocation()
+        );
+    }
+
+    private MockHandlerImpl<?> create_correctly_stubbed_handler(InvocationListener throwingListener) {
+        MockHandlerImpl<?> handler = create_handler_with_listeners(throwingListener);
+        stub_ordinary_invocation_with_given_return_value(handler);
+        return handler;
+    }
+
+    private void stub_ordinary_invocation_with_given_return_value(MockHandlerImpl<?> handler) {
+        stub_ordinary_invocation_with_invocation_matcher(handler, stubbedInvocationMatcher);
+    }
+
+
+    private void stub_ordinary_invocation_with_invocation_matcher(MockHandlerImpl<?> handler, StubbedInvocationMatcher value) {
+        handler.invocationContainerImpl = mock(InvocationContainerImpl.class);
+        given(handler.invocationContainerImpl.findAnswerFor(any(InvocationImpl.class))).willReturn(value);
+    }
+
+
+    private MockHandlerImpl<?> create_handler_with_listeners(InvocationListener... listener) {
+        @SuppressWarnings("rawtypes")
         MockHandlerImpl<?> handler = new MockHandlerImpl(mock(MockSettingsImpl.class));
-		handler.matchersBinder = mock(MatchersBinder.class);
-		given(handler.getMockSettings().getInvocationListeners()).willReturn(Arrays.asList(listener));
-		return handler;
-	}
+        handler.matchersBinder = mock(MatchersBinder.class);
+        given(handler.getMockSettings().getInvocationListeners()).willReturn(Arrays.asList(listener));
+        return handler;
+    }
+
+    private static class AWrongType {
+        public static final AWrongType WRONG_TYPE = new AWrongType();
+    }
 }
diff --git a/test/org/mockito/internal/stubbing/answers/AnswersValidatorTest.java b/test/org/mockito/internal/stubbing/answers/AnswersValidatorTest.java
index 914535fbb8..04b5917575 100644
--- a/test/org/mockito/internal/stubbing/answers/AnswersValidatorTest.java
+++ b/test/org/mockito/internal/stubbing/answers/AnswersValidatorTest.java
@@ -1,7 +1,7 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
+/*
+ * Copyright (c) 2007 Mockito contributors
+ * This program is made available under the terms of the MIT License.
+ */
 package org.mockito.internal.stubbing.answers;
 
 import org.junit.Test;
@@ -30,7 +30,7 @@ public void should_validate_null_throwable() throws Throwable {
         try {
             validator.validate(new ThrowsException(null), new InvocationBuilder().toInvocation());
             fail();
-        } catch (MockitoException e) {}
+        } catch (MockitoException expected) {}
     }
 
     @Test
@@ -42,28 +42,28 @@ public void should_pass_proper_checked_exception() throws Throwable {
     public void should_fail_invalid_checked_exception() throws Throwable {
         validator.validate(new ThrowsException(new IOException()), invocation);
     }
-    
+
     @Test
     public void should_pass_RuntimeExceptions() throws Throwable {
         validator.validate(new ThrowsException(new Error()), invocation);
         validator.validate(new ThrowsException(new RuntimeException()), invocation);
     }
-    
+
     @Test(expected = MockitoException.class)
     public void should_fail_when_return_Value_is_set_for_void_method() throws Throwable {
         validator.validate(new Returns("one"), new InvocationBuilder().method("voidMethod").toInvocation());
     }
-    
+
     @Test(expected = MockitoException.class)
     public void should_fail_when_non_void_method_does_nothing() throws Throwable {
         validator.validate(new DoesNothing(), new InvocationBuilder().simpleMethod().toInvocation());
     }
-    
+
     @Test
     public void should_allow_void_return_for_void_method() throws Throwable {
         validator.validate(new DoesNothing(), new InvocationBuilder().method("voidMethod").toInvocation());
     }
-    
+
     @Test
     public void should_allow_correct_type_of_return_value() throws Throwable {
         validator.validate(new Returns("one"), new InvocationBuilder().simpleMethod().toInvocation());
@@ -75,12 +75,12 @@ public void should_allow_correct_type_of_return_value() throws Throwable {
         validator.validate(new Returns(null), new InvocationBuilder().method("objectReturningMethodNoArgs").toInvocation());
         validator.validate(new Returns(1), new InvocationBuilder().method("objectReturningMethodNoArgs").toInvocation());
     }
-    
+
     @Test(expected = MockitoException.class)
     public void should_fail_on_return_type_mismatch() throws Throwable {
         validator.validate(new Returns("String"), new InvocationBuilder().method("booleanReturningMethod").toInvocation());
     }
-    
+
     @Test(expected = MockitoException.class)
     public void should_fail_on_wrong_primitive() throws Throwable {
         validator.validate(new Returns(1), new InvocationBuilder().method("doubleReturningMethod").toInvocation());
@@ -90,7 +90,7 @@ public void should_fail_on_wrong_primitive() throws Throwable {
     public void should_fail_on_null_with_primitive() throws Throwable {
         validator.validate(new Returns(null), new InvocationBuilder().method("booleanReturningMethod").toInvocation());
     }
-    
+
     @Test
     public void should_fail_when_calling_real_method_on_interface() throws Throwable {
         //given
@@ -100,9 +100,9 @@ public void should_fail_when_calling_real_method_on_interface() throws Throwable
             validator.validate(new CallsRealMethods(), invocationOnInterface);
             //then
             fail();
-        } catch (MockitoException e) {}
+        } catch (MockitoException expected) {}
     }
-            
+
     @Test
     public void should_be_OK_when_calling_real_method_on_concrete_class() throws Throwable {
         //given
@@ -194,4 +194,31 @@ public void should_fail_if_argument_type_of_signature_is_incompatible_with_retur
         }
     }
 
-}
\ No newline at end of file
+    @Test
+    public void should_fail_if_returned_value_of_answer_is_incompatible_with_return_type() throws Throwable {
+        try {
+            validator.validateDefaultAnswerReturnedValue(
+                    new InvocationBuilder().method("toString").toInvocation(),
+                    AWrongType.WRONG_TYPE
+            );
+            fail();
+        } catch (WrongTypeOfReturnValue e) {
+            assertThat(e.getMessage())
+                    .containsIgnoringCase("Default answer returned a result with the wrong type")
+                    .containsIgnoringCase("AWrongType cannot be returned by toString()")
+                    .containsIgnoringCase("toString() should return String");
+        }
+    }
+
+    @Test
+    public void should_not_fail_if_returned_value_of_answer_is_null() throws Throwable {
+        validator.validateDefaultAnswerReturnedValue(
+                new InvocationBuilder().method("toString").toInvocation(),
+                null
+        );
+    }
+
+    private static class AWrongType {
+        public static final AWrongType WRONG_TYPE = new AWrongType();
+    }
+}
diff --git a/test/org/mockito/internal/verification/NoMoreInteractionsTest.java b/test/org/mockito/internal/verification/NoMoreInteractionsTest.java
index 4b52575d6e..e8c9303075 100644
--- a/test/org/mockito/internal/verification/NoMoreInteractionsTest.java
+++ b/test/org/mockito/internal/verification/NoMoreInteractionsTest.java
@@ -1,35 +1,37 @@
-/*
- * Copyright (c) 2007 Mockito contributors
- * This program is made available under the terms of the MIT License.
- */
+/*
+ * Copyright (c) 2007 Mockito contributors
+ * This program is made available under the terms of the MIT License.
+ */
 package org.mockito.internal.verification;
 
-import static java.util.Arrays.*;
-
-import org.fest.assertions.Assertions;
+import org.fest.assertions.Assertions;
 import org.junit.Test;
-import org.mockito.exceptions.verification.NoInteractionsWanted;
+import org.mockito.exceptions.verification.NoInteractionsWanted;
 import org.mockito.exceptions.verification.VerificationInOrderFailure;
-import org.mockito.internal.creation.MockSettingsImpl;
+import org.mockito.internal.creation.MockSettingsImpl;
 import org.mockito.internal.invocation.InvocationBuilder;
-import org.mockito.internal.invocation.InvocationMatcher;
-import org.mockito.internal.progress.ThreadSafeMockingProgress;
-import org.mockito.internal.stubbing.InvocationContainerImpl;
+import org.mockito.internal.invocation.InvocationMatcher;
+import org.mockito.internal.progress.ThreadSafeMockingProgress;
+import org.mockito.internal.stubbing.InvocationContainerImpl;
 import org.mockito.internal.verification.api.VerificationDataInOrderImpl;
 import org.mockito.invocation.Invocation;
+import org.mockitousage.IMethods;
 import org.mockitoutil.TestBase;
 
+import static java.util.Arrays.asList;
+import static org.mockito.Mockito.mock;
+
 public class NoMoreInteractionsTest extends TestBase {
 
     InOrderContextImpl context = new InOrderContextImpl();
-    
+
     @Test
     public void shouldVerifyInOrder() {
         //given
         NoMoreInteractions n = new NoMoreInteractions();
         Invocation i = new InvocationBuilder().toInvocation();
         assertFalse(context.isVerified(i));
-        
+
         try {
             //when
             n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i), null));
@@ -37,7 +39,7 @@ public void shouldVerifyInOrder() {
             fail();
         } catch(VerificationInOrderFailure e) {}
     }
-    
+
     @Test
     public void shouldVerifyInOrderAndPass() {
         //given
@@ -45,12 +47,12 @@ public void shouldVerifyInOrderAndPass() {
         Invocation i = new InvocationBuilder().toInvocation();
         context.markVerified(i);
         assertTrue(context.isVerified(i));
-        
+
         //when
         n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i), null));
         //then no exception is thrown
     }
-    
+
     @Test
     public void shouldVerifyInOrderMultipleInvoctions() {
         //given
@@ -77,43 +79,43 @@ public void shouldVerifyInOrderMultipleInvoctionsAndThrow() {
             n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i, i2), null));
             fail();
         } catch (VerificationInOrderFailure e) {}
-    }
-
-    @Test
-    public void noMoreInteractionsExceptionMessageShouldDescribeMock() {
-        //given
-        NoMoreInteractions n = new NoMoreInteractions();
-        String mock = "a mock";
-        InvocationMatcher i = new InvocationBuilder().mock(mock).toInvocationMatcher();
-
-        InvocationContainerImpl invocations =
-            new InvocationContainerImpl(new ThreadSafeMockingProgress(), new MockSettingsImpl());
-        invocations.setInvocationForPotentialStubbing(i);
-
-        try {
-            //when
-            n.verify(new VerificationDataImpl(invocations, null));
-            //then
-            fail();
-        } catch (NoInteractionsWanted e) {
-            Assertions.assertThat(e.toString()).contains(mock.toString());
-        }
-    }
-
-    @Test
-    public void noMoreInteractionsInOrderExceptionMessageShouldDescribeMock() {
-        //given
-        NoMoreInteractions n = new NoMoreInteractions();
-        String mock = "a mock";
-        Invocation i = new InvocationBuilder().mock(mock).toInvocation();
-
-        try {
-            //when
-            n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i), null));
-            //then
-            fail();
-        } catch (VerificationInOrderFailure e) {
-            Assertions.assertThat(e.toString()).contains(mock.toString());
-        }
     }
-}
\ No newline at end of file
+
+    @Test
+    public void noMoreInteractionsExceptionMessageShouldDescribeMock() {
+        //given
+        NoMoreInteractions n = new NoMoreInteractions();
+        IMethods mock = mock(IMethods.class, "a mock");
+        InvocationMatcher i = new InvocationBuilder().mock(mock).toInvocationMatcher();
+
+        InvocationContainerImpl invocations =
+            new InvocationContainerImpl(new ThreadSafeMockingProgress(), new MockSettingsImpl());
+        invocations.setInvocationForPotentialStubbing(i);
+
+        try {
+            //when
+            n.verify(new VerificationDataImpl(invocations, null));
+            //then
+            fail();
+        } catch (NoInteractionsWanted e) {
+            Assertions.assertThat(e.toString()).contains(mock.toString());
+        }
+    }
+
+    @Test
+    public void noMoreInteractionsInOrderExceptionMessageShouldDescribeMock() {
+        //given
+        NoMoreInteractions n = new NoMoreInteractions();
+        IMethods mock = mock(IMethods.class, "a mock");
+        Invocation i = new InvocationBuilder().mock(mock).toInvocation();
+
+        try {
+            //when
+            n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i), null));
+            //then
+            fail();
+        } catch (VerificationInOrderFailure e) {
+            Assertions.assertThat(e.toString()).contains(mock.toString());
+        }
+    }
+}
diff --git a/test/org/mockitousage/bugs/ClassCastExOnVerifyZeroInteractionsTest.java b/test/org/mockitousage/bugs/ClassCastExOnVerifyZeroInteractionsTest.java
new file mode 100644
index 0000000000..6b6cc85395
--- /dev/null
+++ b/test/org/mockitousage/bugs/ClassCastExOnVerifyZeroInteractionsTest.java
@@ -0,0 +1,38 @@
+package org.mockitousage.bugs;
+
+import org.junit.Test;
+import org.mockito.exceptions.misusing.WrongTypeOfReturnValue;
+import org.mockito.exceptions.verification.NoInteractionsWanted;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+public class ClassCastExOnVerifyZeroInteractionsTest {
+    public interface TestMock {
+        boolean m1();
+    }
+
+    @Test(expected = NoInteractionsWanted.class)
+    public void should_not_throw_ClassCastException_when_mock_verification_fails() {
+        TestMock test = mock(TestMock.class, new Answer() {
+            public Object answer(InvocationOnMock invocation) throws Throwable {
+                return false;
+            }
+        });
+        test.m1();
+        verifyZeroInteractions(test);
+    }
+
+    @Test(expected = WrongTypeOfReturnValue.class)
+    public void should_report_bogus_default_answer() throws Exception {
+        TestMock test = mock(TestMock.class, new Answer() {
+            public Object answer(InvocationOnMock invocation) throws Throwable {
+                return false;
+            }
+        });
+
+        test.toString();
+    }
+}
diff --git a/test/org/mockitousage/verification/DescriptiveMessagesWhenVerificationFailsTest.java b/test/org/mockitousage/verification/DescriptiveMessagesWhenVerificationFailsTest.java
index 44a074ef5c..f30540edbf 100644
--- a/test/org/mockitousage/verification/DescriptiveMessagesWhenVerificationFailsTest.java
+++ b/test/org/mockitousage/verification/DescriptiveMessagesWhenVerificationFailsTest.java
@@ -33,7 +33,7 @@ public class DescriptiveMessagesWhenVerificationFailsTest extends TestBase {
 
     @Before
     public void setup() {
-        mock = Mockito.mock(IMethods.class);
+        mock = Mockito.mock(IMethods.class, "iMethods");
     }
 
     @Test
@@ -85,8 +85,8 @@ public void should_print_actual_and_wanted_in_line() {
                     "iMethods.varargs(1, 1000);";
 
             assertContains(wanted, e.getMessage());
-            
-            String actual = 
+
+            String actual =
                     "\n" +
                     "Actual invocation has different arguments:" +
                     "\n" +
@@ -95,7 +95,7 @@ public void should_print_actual_and_wanted_in_line() {
             assertContains(actual, e.getMessage());
         }
     }
-    
+
     @Test
     public void should_print_actual_and_wanted_in_multiple_lines() {
         mock.varargs("this is very long string", "this is another very long string");
@@ -296,11 +296,11 @@ public void should_print_null_arguments() throws Exception {
             assertContains("simpleMethod(null, null);", e.getMessage());
         }
     }
-    
+
     @Test
     public void should_say_never_wanted_but_invoked() throws Exception {
         mock.simpleMethod(1);
-    
+
         verify(mock, never()).simpleMethod(2);
         try {
             verify(mock, never()).simpleMethod(1);
@@ -310,12 +310,12 @@ public void should_say_never_wanted_but_invoked() throws Exception {
             assertContains("But invoked here:", e.getMessage());
         }
     }
-    
+
     @Test
     public void should_show_right_actual_method() throws Exception {
         mock.simpleMethod(9191);
         mock.simpleMethod("foo");
-    
+
         try {
             verify(mock).simpleMethod("bar");
             fail();
@@ -326,11 +326,11 @@ public void should_show_right_actual_method() throws Exception {
     }
 
     @Mock private IMethods iHavefunkyName;
-    
+
     @Test
     public void should_print_field_name_when_annotations_used() throws Exception {
         iHavefunkyName.simpleMethod(10);
-    
+
         try {
             verify(iHavefunkyName).simpleMethod(20);
             fail();
@@ -339,12 +339,12 @@ public void should_print_field_name_when_annotations_used() throws Exception {
             assertContains("iHavefunkyName.simpleMethod(10)", e.getMessage());
         }
     }
-    
+
     @Test
     public void should_print_interactions_on_mock_when_ordinary_verification_fail() throws Exception {
         mock.otherMethod();
         mock.booleanReturningMethod();
-        
+
         try {
             verify(mock).simpleMethod();
             fail();
@@ -353,8 +353,8 @@ public void should_print_interactions_on_mock_when_ordinary_verification_fail()
         }
     }
 
-    @Mock private IMethods veeeeeeeeeeeeeeeeeeeeeeeerylongNameMock; 
-    
+    @Mock private IMethods veeeeeeeeeeeeeeeeeeeeeeeerylongNameMock;
+
     @Test
     public void should_never_break_method_string_when_no_args_in_method() throws Exception {
         try {
@@ -430,5 +430,4 @@ public void test2() {
     public interface AnInterface {
         void foo(int i);
     }
-    
-}
\ No newline at end of file
+}