2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.transport.modbus.test;
15 import java.util.ArrayList;
16 import java.util.function.LongSupplier;
18 import org.mockito.invocation.InvocationOnMock;
19 import org.mockito.stubbing.Answer;
22 * @author Sami Salonen - Initial contribution
26 public class ResultCaptor<T> implements Answer<T> {
28 private ArrayList<T> results = new ArrayList<>();
29 private LongSupplier longSupplier;
31 public ResultCaptor(LongSupplier longSupplier) {
32 this.longSupplier = longSupplier;
35 public ArrayList<T> getAllReturnValues() {
39 @SuppressWarnings("unchecked")
41 public T answer(InvocationOnMock invocationOnMock) throws Throwable {
42 T result = (T) invocationOnMock.callRealMethod();
43 synchronized (this.results) {
46 long wait = longSupplier.getAsLong();