Java 类org.mockito.invocation.DescribedInvocation 实例源码
项目:whakamatautau-util
文件:EventCollector.java
private EventCollector(Class<Target> targetClass, EventCombiner<Target, Event> combiner,
Collection<Predicate<? super Event>> filters) {
this.combiner = Objects.requireNonNull(combiner, "Event combiner cannot be null!");
this.eventFilters = ImmutableList.copyOf(filters);
this.eventHandlers = selectEventHandlers(filters);
List<DescribedInvocation> invocations = new ArrayList<>();
MockSettings settings = Mockito.withSettings()
.invocationListeners(report -> invocations.add(report.getInvocation()));
this.target = Mockito.mock(targetClass, settings);
combiner.accept(Mockito.doAnswer(this::answer).when(target));
if (invocations.size() != 1)
throw new IllegalStateException("Single listener interaction was expected! But actual: " + invocations);
this.invocation = invocations.get(0);
}
项目:astor
文件:Reporter.java
public void wantedButNotInvoked(DescribedInvocation wanted, List<? extends DescribedInvocation> invocations) {
String allInvocations;
if (invocations.isEmpty()) {
allInvocations = "Actually, there were zero interactions with this mock.\n";
} else {
StringBuilder sb = new StringBuilder("\nHowever, there were other interactions with this mock:\n");
for (DescribedInvocation i : invocations) {
sb.append(i.toString())
.append("\n")
.append(i.getLocation())
.append("\n\n");
}
allInvocations = sb.toString();
}
String message = createWantedButNotInvokedMessage(wanted);
throw new WantedButNotInvoked(message + allInvocations);
}
项目:evosuite
文件:EvoInvocationListener.java
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
if(! active){
return;
}
DescribedInvocation di = methodInvocationReport.getInvocation();
MethodDescriptor md = null;
if(di instanceof InvocationOnMock){
InvocationOnMock impl = (InvocationOnMock) di;
Method method = impl.getMethod();
md = new MethodDescriptor(method, retvalType);
} else {
//hopefully it should never happen
md = getMethodDescriptor_old(di);
}
if(md.getMethodName().equals("finalize")){
//ignore it, otherwise if we mock it, we ll end up in a lot of side effects... :(
return;
}
if(onlyMockAbstractMethods() && !md.getGenericMethod().isAbstract()) {
return;
}
synchronized (map){
MethodDescriptor current = map.get(md.getID());
if(current == null){
current = md;
}
current.increaseCounter();
map.put(md.getID(),current);
}
}
项目:evosuite
文件:EvoInvocationListener.java
@Deprecated
private MethodDescriptor getMethodDescriptor_old(DescribedInvocation di) {
/*
Current Mockito API seems quite limited. Here, to know what
was called, it looks like the only way is to parse the results
of toString.
We can identify primitive types and String, but likely not the
exact type of input objects. This is a problem if methods are overloaded
and having same number of input parameters :(
*/
String description = di.toString();
int openingP = description.indexOf('(');
assert openingP >= 0;
String[] leftTokens = description.substring(0,openingP).split("\\.");
String className = ""; //TODO
String methodName = leftTokens[leftTokens.length-1];
int closingP = description.lastIndexOf(')');
String[] inputTokens = description.substring(openingP+1, closingP).split(",");
String mockitoMatchers = "";
if(inputTokens.length > 0) {
/*
TODO: For now it does not seem really feasible to infer the correct types.
Left a feature request on Mockito mailing list, let's see if it ll be done
*/
mockitoMatchers += "any()";
for (int i=1; i<inputTokens.length; i++) {
mockitoMatchers += " , any()";
}
}
return new MethodDescriptor(className,methodName,mockitoMatchers);
}
项目:astor
文件:Reporter.java
private String createWantedButNotInvokedMessage(DescribedInvocation wanted) {
return join(
"Wanted but not invoked:",
wanted.toString(),
new LocationImpl(),
""
);
}
项目:astor
文件:Reporter.java
public void wantedButNotInvokedInOrder(DescribedInvocation wanted, DescribedInvocation previous) {
throw new VerificationInOrderFailure(join(
"Verification in order failure",
"Wanted but not invoked:",
wanted.toString(),
new LocationImpl(),
"Wanted anywhere AFTER following interaction:",
previous.toString(),
previous.getLocation(),
""
));
}
项目:astor
文件:Reporter.java
private String createTooManyInvocationsMessage(int wantedCount, int actualCount, DescribedInvocation wanted,
Location firstUndesired) {
return join(
wanted.toString(),
"Wanted " + pluralize(wantedCount) + ":",
new LocationImpl(),
"But was " + pluralize(actualCount) + ". Undesired invocation:",
firstUndesired,
""
);
}
项目:astor
文件:Reporter.java
public void neverWantedButInvoked(DescribedInvocation wanted, Location firstUndesired) {
throw new NeverWantedButInvoked(join(
wanted.toString(),
"Never wanted here:",
new LocationImpl(),
"But invoked here:",
firstUndesired,
""
));
}
项目:astor
文件:Reporter.java
private String createTooLittleInvocationsMessage(org.mockito.internal.reporting.Discrepancy discrepancy, DescribedInvocation wanted,
Location lastActualInvocation) {
String ending =
(lastActualInvocation != null)? lastActualInvocation + "\n" : "\n";
String message = join(
wanted.toString(),
"Wanted " + discrepancy.getPluralizedWantedCount() + ":",
new LocationImpl(),
"But was " + discrepancy.getPluralizedActualCount() + ":",
ending
);
return message;
}
项目:astor
文件:Reporter.java
public void tooLittleActualInvocationsInOrder(org.mockito.internal.reporting.Discrepancy discrepancy, DescribedInvocation wanted, Location lastActualLocation) {
String message = createTooLittleInvocationsMessage(discrepancy, wanted, lastActualLocation);
throw new VerificationInOrderFailure(join(
"Verification in order failure:" + message
));
}
项目:mockito-async
文件:Await.java
public static MockSettings async(MockSettings settings) {
return settings.invocationListeners(new InvocationListener() {
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
DescribedInvocation invocation = methodInvocationReport.getInvocation();
if (invocation instanceof InvocationOnMock) {
Object mock = ((InvocationOnMock) invocation).getMock();
synchronized (mock) {
mock.notifyAll();
}
}
}
});
}
项目:astor
文件:Reporter.java
public void wantedButNotInvoked(DescribedInvocation wanted) {
throw new WantedButNotInvoked(createWantedButNotInvokedMessage(wanted));
}
项目:astor
文件:Reporter.java
public void tooManyActualInvocations(int wantedCount, int actualCount, DescribedInvocation wanted, Location firstUndesired) {
String message = createTooManyInvocationsMessage(wantedCount, actualCount, wanted, firstUndesired);
throw new TooManyActualInvocations(message);
}
项目:astor
文件:Reporter.java
public void tooManyActualInvocationsInOrder(int wantedCount, int actualCount, DescribedInvocation wanted, Location firstUndesired) {
String message = createTooManyInvocationsMessage(wantedCount, actualCount, wanted, firstUndesired);
throw new VerificationInOrderFailure(join(
"Verification in order failure:" + message
));
}
项目:astor
文件:Reporter.java
public void tooLittleActualInvocations(org.mockito.internal.reporting.Discrepancy discrepancy, DescribedInvocation wanted, Location lastActualLocation) {
String message = createTooLittleInvocationsMessage(discrepancy, wanted, lastActualLocation);
throw new TooLittleActualInvocations(message);
}
项目:astor
文件:StubInfoImpl.java
public StubInfoImpl(DescribedInvocation stubbedAt) {
this.stubbedAt = stubbedAt;
}
项目:astor
文件:StubbedInvocationMatcher.java
public void markStubUsed(DescribedInvocation usedAt) {
this.usedAt = usedAt;
}
项目:astor
文件:NotifiedMethodInvocationReport.java
public DescribedInvocation getInvocation() {
return invocation;
}
项目:astor
文件:VerboseMockInvocationLogger.java
private void printInvocation(DescribedInvocation invocation) {
printStream.println(invocation.toString());
// printStream.println("Handling method call on a mock/spy.");
printlnIndented("invoked: " + invocation.getLocation().toString());
}
项目:astor
文件:MissingInvocationCheckerTest.java
@Override
public void wantedButNotInvoked(DescribedInvocation wanted, List<? extends DescribedInvocation> invocations) {
this.wanted = wanted;
}
项目:astor
文件:MissingInvocationInOrderCheckerTest.java
@Override public void wantedButNotInvokedInOrder(DescribedInvocation wanted, DescribedInvocation previous) {
this.wanted = wanted;
this.previous = previous;
}
项目:astor
文件:MissingInvocationInOrderCheckerTest.java
@Override public void wantedButNotInvoked(DescribedInvocation wanted) {
this.wanted = wanted;
}
项目:astor
文件:NumberOfInvocationsCheckerTest.java
@Override public void tooLittleActualInvocations(org.mockito.internal.reporting.Discrepancy discrepancy, DescribedInvocation wanted, Location lastActualLocation) {
this.wantedCount = discrepancy.getWantedCount();
this.actualCount = discrepancy.getActualCount();
this.wanted = wanted;
this.location = lastActualLocation;
}
项目:astor
文件:NumberOfInvocationsCheckerTest.java
@Override public void tooManyActualInvocations(int wantedCount, int actualCount, DescribedInvocation wanted, Location firstUndesired) {
this.wantedCount = wantedCount;
this.actualCount = actualCount;
this.wanted = wanted;
this.location = firstUndesired;
}
项目:astor
文件:NumberOfInvocationsCheckerTest.java
@Override
public void neverWantedButInvoked(DescribedInvocation wanted, Location firstUndesired) {
this.wanted = wanted;
this.location = firstUndesired;
}
项目:astor
文件:MethodInvocationReport.java
/**
* The return type is deprecated, please assign the return value from this method
* to the {@link DescribedInvocation} type. Sorry for inconvenience but we had to move
* {@link PrintableInvocation} to better place to keep the API consistency.
*
* @return Information on the method call, never {@code null}
*/
DescribedInvocation getInvocation();