public class FunctionalMockStatement extends EntityWithParametersStatement
EvoInvocationListener listener = new EvoInvocationListener();
Foo foo = mock(Foo.class, withSettings().invocationListeners(listener));
when(foo.aMethod(any() ...)).thenReturn( v0, v1, ...);
when(foo.anotherMethod(...)).thenReturn( k0, k1, ...);
...
listener.activate();
All these statements will be represented with a single one, where the return value is the instantiated mock "foo", and the input parameters are all the input parameters of all mocked methods (eg v0, k0), in order.
Calls to "listener" are essential during the search (eg when the statement is executed), but will not be part of the final generated JUnit tests (ie not part of toCode())
Initially, a functional mock will have 0 input parameters, and no "when" call. After a test is executed, the input parameter lists will be updated based on what "listener" does report. The number of input parameters might vary several times throughout the lifespan of a test during the search (can both increase and decrease).
This statement cannot be used to mock the SUT, as it would make no sense whatsoever. However, there might be special cases: eg SUT being an abstract class with no concrete implementation. That would need to be handled specially.
Created by Andrea Arcuri on 01/08/15.
AbstractStatement.Executerannotations, parameterAnnotations, parametersassertions, comment, retval, tc| Constructor and Description |
|---|
FunctionalMockStatement(TestCase tc,
Type retvalType,
Class<?> targetClass) |
FunctionalMockStatement(TestCase tc,
VariableReference retval,
Class<?> targetClass) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAssertion(Assertion assertion)
Add a new assertion to statement
|
void |
addMissingInputs(List<VariableReference> inputs) |
static boolean |
canBeFunctionalMocked(Type type) |
void |
changeClassLoader(ClassLoader loader)
Class instances are bound to a class loader - if we want to reexecute a
test on a different classloader we need to be able to change the class of
the reflection object
|
Statement |
copy(TestCase newTestCase,
int offset)
copy
|
boolean |
doesNeedToUpdateInputs()
Check if the last execution of the test case has led a change in the usage of the mock.
|
Throwable |
execute(Scope scope,
PrintStream out)
This method executes the statement under the given scope.
|
void |
fillWithNullRefs() |
GenericAccessibleObject<?> |
getAccessibleObject()
Returns the accessibleObject which is used to generate this kind of
statement E.g.
|
String |
getDeclaringClassName() |
String |
getDescriptor() |
String |
getMethodName() |
List<MethodDescriptor> |
getMockedMethods() |
List<VariableReference> |
getParameters(String id) |
Class<?> |
getTargetClass() |
boolean |
isAssignmentStatement()
Returns true if this statement should be handled as an
AssignmentStatement.
|
boolean |
same(Statement s)
Allows the comparing of Statements between TestCases.
|
String |
toString() |
List<Type> |
updateMockedMethods()
Based on most recent test execution, update the mocking configuration.
|
getConstraints, getNumParameters, getNumParametersOfType, getParameterReferences, getUniqueVariableReferences, getVariableReferences, isBounded, mutateParameter, replace, replaceParameterReferenceaddComment, clone, clone, copyAssertions, exceptionHandler, getAssertionCode, getAssertionReferences, getAssertions, getCode, getCode, getComment, getDeclaredExceptions, getExceptionClass, getPosition, getReturnClass, getReturnType, getReturnValue, getTestCase, hasAssertions, isAccessible, isDeclaredException, isReflectionStatement, isValid, mutate, negate, references, removeAssertion, removeAssertions, setAssertions, setRetvalpublic FunctionalMockStatement(TestCase tc, VariableReference retval, Class<?> targetClass) throws IllegalArgumentException
IllegalArgumentExceptionpublic FunctionalMockStatement(TestCase tc, Type retvalType, Class<?> targetClass) throws IllegalArgumentException
IllegalArgumentExceptionpublic void changeClassLoader(ClassLoader loader)
AbstractStatementchangeClassLoader in interface StatementchangeClassLoader in class AbstractStatementloader - a ClassLoader object.public static boolean canBeFunctionalMocked(Type type)
public Class<?> getTargetClass()
public List<MethodDescriptor> getMockedMethods()
public List<VariableReference> getParameters(String id) throws IllegalArgumentException
IllegalArgumentExceptionpublic boolean doesNeedToUpdateInputs()
public List<Type> updateMockedMethods() throws ConstructionFailedException
ConstructionFailedExceptionpublic void addMissingInputs(List<VariableReference> inputs) throws IllegalArgumentException
IllegalArgumentExceptionpublic void fillWithNullRefs()
public void addAssertion(Assertion assertion)
AbstractStatementaddAssertion in interface StatementaddAssertion in class AbstractStatementassertion - Assertion to be addedpublic Statement copy(TestCase newTestCase, int offset)
Statementcopy
newTestCase - the testcase in which this statement will be insertedoffset - a int.Statement object.public Throwable execute(Scope scope, PrintStream out) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException
Statementscope - the scope under which the statement is executedout - a PrintStream object.InvocationTargetException - if any.IllegalArgumentException - if any.IllegalAccessException - if any.InstantiationException - if any.public GenericAccessibleObject<?> getAccessibleObject()
StatementAccessibleObject object.public boolean isAssignmentStatement()
Statementpublic boolean same(Statement s)
Statements - a Statement object.public String getDescriptor()
getDescriptor in class EntityWithParametersStatementpublic String getDeclaringClassName()
getDeclaringClassName in class EntityWithParametersStatementpublic String getMethodName()
getMethodName in class EntityWithParametersStatementCopyright © 2010–2017 EvoSuite. All rights reserved.