Introduce common directory
[yangtools.git] / common / mockito-configuration / src / main / java / org / mockito / configuration / ArgumentsExtractorVerifier.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.mockito.configuration;
9
10 import org.mockito.exceptions.base.MockitoException;
11 import org.mockito.internal.invocation.InvocationsFinder;
12 import org.mockito.internal.verification.api.VerificationData;
13 import org.mockito.invocation.Invocation;
14 import org.mockito.verification.VerificationMode;
15
16 import java.util.List;
17
18 /**
19  * Verifier that extracts arguments from actual invocation. Useful when deeper validation of arguments is needed.
20  *
21  */
22 public class ArgumentsExtractorVerifier implements VerificationMode {
23                 private Object[] arguments;
24
25                 @Override
26                 public void verify(VerificationData data) {
27                         InvocationsFinder finder = new InvocationsFinder();
28                         List<Invocation> actualInvocations = finder.findInvocations(data.getAllInvocations(), data.getWanted());
29                         if (actualInvocations.size() != 1) {
30                                 throw new MockitoException("This verifier can only be used with 1 invocation, got " + actualInvocations.size());
31                         }
32                         Invocation invocation = actualInvocations.get(0);
33                         arguments = invocation.getArguments();
34                         invocation.markVerified();
35
36                 }
37                 public Object[] getArguments(){
38                         return arguments;
39                 }
40         }