mockit.internal.expectations.invocation.InvocationResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmockit Show documentation
Show all versions of jmockit Show documentation
JMockit is a Java toolkit for developer (unit/integration) testing.
It contains mocking APIs and other tools, supporting both JUnit and TestNG.
The mocking APIs allow all kinds of Java code, without testability restrictions, to be tested
in isolation from selected dependencies.
/*
* Copyright (c) 2006-2011 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.internal.expectations.invocation;
import java.util.*;
abstract class InvocationResult
{
InvocationResult next;
abstract Object produceResult(
Object invokedObject, ExpectedInvocation invocation, InvocationConstraints constraints, Object[] args)
throws Throwable;
static final class ReturnValueResult extends InvocationResult
{
private final Object returnValue;
ReturnValueResult(Object returnValue) { this.returnValue = returnValue; }
@Override
Object produceResult(
Object invokedObject, ExpectedInvocation invocation, InvocationConstraints constraints, Object[] args)
{
return returnValue;
}
}
static final class ThrowableResult extends InvocationResult
{
private final Throwable throwable;
ThrowableResult(Throwable throwable) { this.throwable = throwable; }
@Override
Object produceResult(
Object invokedObject, ExpectedInvocation invocation, InvocationConstraints constraints, Object[] args)
throws Throwable
{
throwable.fillInStackTrace();
throw throwable;
}
}
static final class DeferredReturnValues extends InvocationResult
{
private final Iterator> values;
DeferredReturnValues(Iterator> values) { this.values = values; }
@Override
Object produceResult(
Object invokedObject, ExpectedInvocation invocation, InvocationConstraints constraints, Object[] args)
throws Throwable
{
return values.hasNext() ? values.next() : null;
}
}
static final class DeferredResults extends InvocationResult
{
private final Iterator> values;
DeferredResults(Iterator> values) { this.values = values; }
@Override
Object produceResult(
Object invokedObject, ExpectedInvocation invocation, InvocationConstraints constraints, Object[] args)
throws Throwable
{
Object nextValue = values.hasNext() ? values.next() : null;
if (nextValue instanceof Throwable) {
Throwable t = (Throwable) nextValue;
t.fillInStackTrace();
throw t;
}
return nextValue;
}
}
}