com.fitbur.mockito.internal.invocation.MatchersBinder Maven / Gradle / Ivy
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package com.fitbur.mockito.internal.invocation;
import static com.fitbur.mockito.exceptions.Reporter.invalidUseOfMatchers;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import com.fitbur.mockito.ArgumentMatcher;
import com.fitbur.mockito.exceptions.Reporter;
import com.fitbur.mockito.internal.matchers.LocalizedMatcher;
import com.fitbur.mockito.internal.progress.ArgumentMatcherStorage;
import com.fitbur.mockito.invocation.Invocation;
@SuppressWarnings("unchecked")
public class MatchersBinder implements Serializable {
public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, Invocation invocation) {
List lastMatchers = argumentMatcherStorage.pullLocalizedMatchers();
validateMatchers(invocation, lastMatchers);
List matchers = new LinkedList();
for (LocalizedMatcher m : lastMatchers) {
matchers.add(m.getMatcher());
}
return new InvocationMatcher(invocation, matchers);
}
private void validateMatchers(Invocation invocation, List lastMatchers) {
if (!lastMatchers.isEmpty()) {
int recordedMatchersSize = lastMatchers.size();
int expectedMatchersSize = invocation.getArguments().length;
if (expectedMatchersSize != recordedMatchersSize) {
throw invalidUseOfMatchers(expectedMatchersSize, lastMatchers);
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy