Repository: mockito/mockito
Issue: InOrder.verify with non-mock should perhaps give standard non-mock warning
Labels: please contribute

Minor, but I noticed today when I accidentally passed in a non-mock to an `InOrder.verify` call that it warned me that it can only verify mocks that were passed in during creation of `InOrder`.  While correct, it seems like perhaps using the standard "non-mock" warning would be more helpful as it has better hinting for this situation.  In particular, this seems like it would be useful to newer users of the API who might have a hard time figuring out what they did wrong.

## Mockito.verify

```java
List<?> mock = Mockito.mock(List.class);
Mockito.verify(Mockito.mock.get(5));
```

### Output

```text
Argument passed to verify() should be a mock but is null!
Examples of correct verifications:
    verify(mock).someMethod();
    verify(mock, times(10)).someMethod();
    verify(mock, atLeastOnce()).someMethod();
    not: verify(mock.someMethod());
Also, if you use @Mock annotation don't miss initMocks()
```

## inOrder.verify

```java
List<?> mock = Mockito.mock(List.class);
InOrder inOrder = Mockito.inOrder(mock);
inOrder.verify(mock.get(5));
```

### Output

```text
InOrder can only verify mocks that were passed in during creation of InOrder.
For example:
    InOrder inOrder = inOrder(mockOne);
    inOrder.verify(mockOne).doStuff();
```

## Desired behavior

Note that the current `InOrder` message does not give the hint of how to fix the non-mock that was passed in.  Using the standard non-mock warning in this case seems like a more helpful response.  Alternatively, that the hinting could be included in the `InOrder` output when a non-mock is used.

Issue comments:
PRs welcome 😄 

Pull request review comments:

Patch that resolved the issue:
diff --git a/src/main/java/org/mockito/internal/InOrderImpl.java b/src/main/java/org/mockito/internal/InOrderImpl.java
index 15e861b9f2..db55c62396 100644
--- a/src/main/java/org/mockito/internal/InOrderImpl.java
+++ b/src/main/java/org/mockito/internal/InOrderImpl.java
@@ -4,12 +4,11 @@
  */
 package org.mockito.internal;
 
-import static org.mockito.internal.exceptions.Reporter.inOrderRequiresFamiliarMock;
-
 import java.util.LinkedList;
 import java.util.List;
 
 import org.mockito.InOrder;
+import org.mockito.MockingDetails;
 import org.mockito.exceptions.base.MockitoException;
 import org.mockito.internal.verification.InOrderContextImpl;
 import org.mockito.internal.verification.InOrderWrapper;
@@ -21,6 +20,9 @@
 import org.mockito.invocation.Invocation;
 import org.mockito.verification.VerificationMode;
 
+import static org.mockito.Mockito.mockingDetails;
+import static org.mockito.internal.exceptions.Reporter.*;
+
 /**
  * Allows verifying in order. This class should not be exposed, hence default access.
  */
@@ -43,6 +45,13 @@ public <T> T verify(T mock) {
     }
 
     public <T> T verify(T mock, VerificationMode mode) {
+        if (mock == null) {
+            throw nullPassedToVerify();
+        }
+        MockingDetails mockingDetails = mockingDetails(mock);
+        if (!mockingDetails.isMock()) {
+            throw notAMockPassedToVerify(mock.getClass());
+        }
         if (!mocksToBeVerifiedInOrder.contains(mock)) {
             throw inOrderRequiresFamiliarMock();
         }


Test patch:
diff --git a/src/test/java/org/mockitousage/verification/BasicVerificationInOrderTest.java b/src/test/java/org/mockitousage/verification/BasicVerificationInOrderTest.java
index 834af414c7..f424fab706 100644
--- a/src/test/java/org/mockitousage/verification/BasicVerificationInOrderTest.java
+++ b/src/test/java/org/mockitousage/verification/BasicVerificationInOrderTest.java
@@ -4,6 +4,7 @@
  */
 package org.mockitousage.verification;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.*;
 
@@ -11,6 +12,8 @@
 import org.junit.Test;
 import org.mockito.InOrder;
 import org.mockito.exceptions.base.MockitoException;
+import org.mockito.exceptions.misusing.NotAMockException;
+import org.mockito.exceptions.misusing.NullInsteadOfMockException;
 import org.mockito.exceptions.verification.NoInteractionsWanted;
 import org.mockito.exceptions.verification.VerificationInOrderFailure;
 import org.mockito.exceptions.verification.WantedButNotInvoked;
@@ -273,4 +276,29 @@ public void shouldFailOnVerifyNoInteractions() {
     public void shouldScreamWhenNullPassed() {
         inOrder((Object[]) null);
     }
+
+    @Test
+    public void shouldThrowNullPassedToVerifyException() {
+        try {
+            inOrder.verify(null);
+            fail();
+        } catch (NullInsteadOfMockException e) {
+            assertThat(e)
+                    .hasMessageContaining(
+                            "Argument passed to verify() should be a mock but is null!");
+        }
+    }
+
+    @Test
+    public void shouldThrowNotAMockPassedToVerifyException() {
+        Object object = new Object();
+        try {
+            inOrder.verify(object);
+            fail();
+        } catch (NotAMockException e) {
+            assertThat(e)
+                    .hasMessageContaining(
+                            "Argument passed to verify() is of type Object and is not a mock!");
+        }
+    }
 }