f46c8913fdf127fb2f576a22ef8bd2eb0ac4841b
[netvirt.git] / aclservice / impl / src / test / java / org / opendaylight / netvirt / aclservice / utils / MethodInvocationParamSaver.java
1 /*
2  * Copyright (c) 2016 Red Hat, 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.opendaylight.netvirt.aclservice.utils;
9
10 import java.util.ArrayList;
11 import java.util.Arrays;
12 import java.util.List;
13
14 import org.mockito.invocation.InvocationOnMock;
15 import org.mockito.stubbing.Answer;
16
17 public class  MethodInvocationParamSaver<T> implements Answer<T> {
18
19     private List<List<Object>> invocationParams = new ArrayList<>();
20     private T answer;
21
22     public MethodInvocationParamSaver(T answer) {
23         this.answer = answer;
24     }
25
26     @Override
27     public T answer(InvocationOnMock invocation) throws Throwable {
28         invocationParams.add(Arrays.asList(invocation.getArguments()));
29         return answer;
30     }
31
32     public int getNumOfInvocations() {
33         return invocationParams.size();
34     }
35
36     public List<Object> getInvocationParams(int index) {
37         return invocationParams.get(index);
38     }
39
40 }