Enable checkstyle on objectcache and mockito-config
[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 java.util.List;
11 import org.mockito.exceptions.base.MockitoException;
12 import org.mockito.internal.invocation.InvocationsFinder;
13 import org.mockito.internal.verification.api.VerificationData;
14 import org.mockito.invocation.Invocation;
15 import org.mockito.verification.VerificationMode;
16
17 /**
18  * Verifier that extracts arguments from actual invocation. Useful when deeper validation of arguments is needed.
19  */
20 public class ArgumentsExtractorVerifier implements VerificationMode {
21     private Object[] arguments;
22
23     @Override
24     public void verify(final VerificationData data) {
25         InvocationsFinder finder = new InvocationsFinder();
26         List<Invocation> actualInvocations = finder.findInvocations(data.getAllInvocations(), data.getWanted());
27         if (actualInvocations.size() != 1) {
28             throw new MockitoException("This verifier can only be used with 1 invocation, got "
29                     + actualInvocations.size());
30         }
31         Invocation invocation = actualInvocations.get(0);
32         arguments = invocation.getArguments();
33         invocation.markVerified();
34
35     }
36
37     public Object[] getArguments() {
38         return arguments;
39     }
40 }