• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 
6 package org.mockito.internal.verification;
7 
8 import static org.mockito.internal.exceptions.Reporter.noMoreInteractionsWanted;
9 import static org.mockito.internal.exceptions.Reporter.noMoreInteractionsWantedInOrder;
10 import static org.mockito.internal.invocation.InvocationsFinder.findFirstUnverified;
11 import static org.mockito.internal.invocation.InvocationsFinder.findFirstUnverifiedInOrder;
12 
13 import java.util.List;
14 
15 import org.mockito.internal.verification.api.VerificationData;
16 import org.mockito.internal.verification.api.VerificationDataInOrder;
17 import org.mockito.internal.verification.api.VerificationInOrderMode;
18 import org.mockito.invocation.Invocation;
19 import org.mockito.verification.VerificationMode;
20 
21 public class NoMoreInteractions implements VerificationMode, VerificationInOrderMode {
22 
23     @SuppressWarnings("unchecked")
verify(VerificationData data)24     public void verify(VerificationData data) {
25         Invocation unverified = findFirstUnverified(data.getAllInvocations());
26         if (unverified != null) {
27             throw noMoreInteractionsWanted(unverified, (List) data.getAllInvocations());
28         }
29     }
30 
verifyInOrder(VerificationDataInOrder data)31     public void verifyInOrder(VerificationDataInOrder data) {
32         List<Invocation> invocations = data.getAllInvocations();
33         Invocation unverified = findFirstUnverifiedInOrder(data.getOrderingContext(), invocations);
34 
35         if (unverified != null) {
36             throw noMoreInteractionsWantedInOrder(unverified);
37         }
38     }
39 
40     @Override
description(String description)41     public VerificationMode description(String description) {
42         return VerificationModeFactory.description(this, description);
43     }
44 }
45