2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mockito;
10 import org.mockito.exceptions.base.MockitoException;
11 import org.mockito.internal.invocation.InvocationsFinder;
12 import org.mockito.internal.verification.VerificationModeFactory;
13 import org.mockito.internal.verification.api.VerificationData;
14 import org.mockito.verification.VerificationMode;
17 * Verifier that extracts arguments from actual invocation. Useful when deeper validation of arguments is needed.
19 public final class ArgumentsExtractorVerifier implements VerificationMode {
20 private Object[] arguments = null;
23 public void verify(final VerificationData data) {
24 final var actualInvocations = InvocationsFinder.findInvocations(data.getAllInvocations(), data.getTarget());
25 final var size = actualInvocations.size();
28 final var invocation = actualInvocations.get(0);
29 arguments = invocation.getArguments();
30 invocation.markVerified();
32 default -> throw new MockitoException("This verifier can only be used with 1 invocation, got " + size);
37 public VerificationMode description(final String description) {
38 return VerificationModeFactory.description(this, description);
42 * Return verified invocation arguments, or {@code null} if not verified.
44 * @return verified invocation arguments, or {@code null} if not verified
46 public Object[] getArguments() {
47 return arguments == null ? null : arguments.clone();