|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.powermock.api.support.membermodification.MemberMatcher org.powermock.api.support.membermodification.MemberModifier org.powermock.api.easymock.PowerMock
public class PowerMock
PowerMock extends EasyMock functionality with several new features such as mocking static and private methods, mocking new instances and more. Use PowerMock instead of EasyMock where applicable.
Constructor Summary | |
---|---|
PowerMock()
|
Method Summary | ||
---|---|---|
static
|
createMock(Class<T> type)
Creates a mock object that supports mocking of final and native methods. |
|
static
|
createMock(Class<T> type,
org.easymock.ConstructorArgs constructorArgs,
Method... methods)
Creates a mock object that supports mocking of final and native methods and invokes a specific constructor. |
|
static
|
createMock(Class<T> type,
Method... methods)
Creates a mock object that supports mocking of final and native methods. |
|
static
|
createMock(Class<T> type,
Object... constructorArguments)
Creates a mock object that supports mocking of final and native methods and invokes a specific constructor based on the supplied argument values. |
|
static
|
createMockAndExpectNew(Class<T> type,
Class<?>[] parameterTypes,
Object... arguments)
Convenience method for createMock followed by expectNew when PowerMock cannot determine which constructor to use automatically. |
|
static
|
createMockAndExpectNew(Class<T> type,
Object... arguments)
Convenience method for createMock followed by expectNew. |
|
static
|
createNiceMock(Class<T> type)
Creates a nice mock object that supports mocking of final and native methods. |
|
static
|
createNiceMock(Class<T> type,
org.easymock.ConstructorArgs constructorArgs,
Method... methods)
Creates a nice mock object that supports mocking of final and native methods and invokes a specific constructor. |
|
static
|
createNiceMock(Class<T> type,
Method... methods)
Creates a nice mock object that supports mocking of final and native methods. |
|
static
|
createNiceMock(Class<T> type,
Object... constructorArguments)
Creates a nice mock object that supports mocking of final and native methods and invokes a specific constructor based on the supplied argument values. |
|
static
|
createNiceMockAndExpectNew(Class<T> type,
Class<?>[] parameterTypes,
Object... arguments)
Convenience method for createNiceMock followed by expectNew when PowerMock cannot determine which constructor to use automatically. |
|
static
|
createNiceMockAndExpectNew(Class<T> type,
Object... arguments)
Convenience method for createNiceMock followed by expectNew. |
|
static
|
createNicePartialMock(Class<T> type,
Class<? super T> where,
String... methodNames)
A utility method that may be used to nicely mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createNicePartialMock(Class<T> type,
String... methodNames)
A utility method that may be used to nicely mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createNicePartialMock(Class<T> type,
String[] methodNames,
Object... constructorArguments)
* A utility method that may be used to nicely mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createNicePartialMock(Class<T> type,
String methodName,
Class<?>[] methodParameterTypes,
Object... constructorArguments)
A utility method that may be used to nicely mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createNicePartialMock(Class<T> type,
String methodName,
Class<?>[] methodParameterTypes,
Object[] constructorArguments,
Class<?>[] constructorParameterTypes)
A utility method that may be used to nicely mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createNicePartialMock(Class<T> type,
String methodNameToMock,
Class<?> firstArgumentType,
Class<?>... additionalArgumentTypes)
Nicely mock a single specific method. |
|
static
|
createNicePartialMockAndInvokeDefaultConstructor(Class<T> type,
String... methodNames)
A utility method that may be used to nicely mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createNicePartialMockForAllMethodsExcept(Class<T> type,
String... methodNames)
A utility method that may be used to specify several methods that should not be nicely mocked in an easy manner (by just passing in the method names of the method you wish not to mock). |
|
static
|
createNicePartialMockForAllMethodsExcept(Class<T> type,
String methodNameToExclude,
Class<?> firstArgumentType,
Class<?>... moreTypes)
Mock all methods of a class except for a specific one nicely. |
|
static
|
createPartialMock(Class<T> type,
Class<? super T> where,
String... methodNames)
A utility method that may be used to mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createPartialMock(Class<T> type,
String... methodNames)
A utility method that may be used to mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createPartialMock(Class<T> type,
String[] methodNames,
Object... constructorArguments)
A utility method that may be used to mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createPartialMock(Class<T> type,
String methodName,
Class<?>[] methodParameterTypes,
Object... constructorArguments)
A utility method that may be used to mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createPartialMock(Class<T> type,
String methodName,
Class<?>[] methodParameterTypes,
Object[] constructorArguments,
Class<?>[] constructorParameterTypes)
A utility method that may be used to mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createPartialMock(Class<T> type,
String methodNameToMock,
Class<?> firstArgumentType,
Class<?>... additionalArgumentTypes)
Mock a single specific method. |
|
static
|
createPartialMockAndInvokeDefaultConstructor(Class<T> type,
String... methodNames)
A utility method that may be used to mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createPartialMockForAllMethodsExcept(Class<T> type,
String... methodNames)
A utility method that may be used to specify several methods that should not be mocked in an easy manner (by just passing in the method names of the method you wish not to mock). |
|
static
|
createPartialMockForAllMethodsExcept(Class<T> type,
String methodNameToExclude,
Class<?> firstArgumentType,
Class<?>... moreTypes)
Mock all methods of a class except for a specific one. |
|
static
|
createStrictMock(Class<T> type)
Creates a strict mock object that supports mocking of final and native methods. |
|
static
|
createStrictMock(Class<T> type,
org.easymock.ConstructorArgs constructorArgs,
Method... methods)
Creates a strict mock object that supports mocking of final and native methods and invokes a specific constructor. |
|
static
|
createStrictMock(Class<T> type,
Method... methods)
Creates a strict mock object that supports mocking of final and native methods. |
|
static
|
createStrictMock(Class<T> type,
Object... constructorArguments)
Creates a strict mock object that supports mocking of final and native methods and invokes a specific constructor based on the supplied argument values. |
|
static
|
createStrictMockAndExpectNew(Class<T> type,
Class<?>[] parameterTypes,
Object... arguments)
Convenience method for createStrictMock followed by expectNew when PowerMock cannot determine which constructor to use automatically. |
|
static
|
createStrictMockAndExpectNew(Class<T> type,
Object... arguments)
Convenience method for createStrictMock followed by expectNew. |
|
static
|
createStrictPartialMock(Class<T> type,
Class<? super T> where,
String... methodNames)
A utility method that may be used to strictly mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createStrictPartialMock(Class<T> type,
String... methodNames)
A utility method that may be used to strictly mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createStrictPartialMock(Class<T> type,
String[] methodNames,
Object... constructorArguments)
* A utility method that may be used to strictly mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createStrictPartialMock(Class<T> type,
String methodName,
Class<?>[] methodParameterTypes,
Object... constructorArguments)
A utility method that may be used to strictly mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createStrictPartialMock(Class<T> type,
String methodName,
Class<?>[] methodParameterTypes,
Object[] constructorArguments,
Class<?>[] constructorParameterTypes)
A utility method that may be used to strictly mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createStrictPartialMock(Class<T> type,
String methodNameToMock,
Class<?> firstArgumentType,
Class<?>... additionalArgumentTypes)
Strictly mock a single specific method. |
|
static
|
createStrictPartialMockAndInvokeDefaultConstructor(Class<T> type,
String... methodNames)
A utility method that may be used to strictly mock several methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static
|
createStrictPartialMockForAllMethodsExcept(Class<T> type,
String... methodNames)
A utility method that may be used to specify several methods that should not be strictly mocked in an easy manner (by just passing in the method names of the method you wish not to mock). |
|
static
|
createStrictPartialMockForAllMethodsExcept(Class<T> type,
String methodNameToExclude,
Class<?> firstArgumentType,
Class<?>... moreTypes)
Mock all methods of a class except for a specific one strictly. |
|
static org.easymock.IExpectationSetters<Object> |
expectLastCall()
This method just delegates to EasyMock class extensions EasyMock.expectLastCall() method. |
|
static
|
expectNew(Class<T> type,
Class<?>[] parameterTypes,
Object... arguments)
Allows specifying expectations on new invocations. |
|
static
|
expectNew(Class<T> type,
Object... arguments)
Allows specifying expectations on new invocations. |
|
static
|
expectNew(String fullyQualifiedName,
Object... arguments)
Allows specifying expectations on new invocations for private member (inner) classes, local or anonymous classes. |
|
static
|
expectNiceNew(Class<T> type,
Class<?>[] parameterTypes,
Object... arguments)
Allows specifying expectations on new invocations. |
|
static
|
expectNiceNew(Class<T> type,
Object... arguments)
Allows specifying expectations on new invocations. |
|
static
|
expectPrivate(Class<?> clazz,
Method method,
Object... arguments)
Used to specify expectations on private static methods. |
|
static
|
expectPrivate(Object instance,
Method method,
Object... arguments)
Used to specify expectations on private methods. |
|
static
|
expectPrivate(Object instance,
Object... arguments)
Used to specify expectations on methods without specifying a method name. |
|
static
|
expectPrivate(Object instance,
String methodName,
Class<?>[] parameterTypes,
Object... arguments)
Used to specify expectations on private methods. |
|
static
|
expectPrivate(Object instance,
String methodName,
Class<?> where,
Class<?>[] parameterTypes,
Object... arguments)
Used to specify expectations on methods using the method name at a specific place in the class hierarchy (specified by the where parameter). |
|
static
|
expectPrivate(Object instance,
String methodName,
Class<?> where,
Object... arguments)
Used to specify expectations on methods using the method name at a specific place in the class hierarchy (specified by the where parameter). |
|
static
|
expectPrivate(Object instance,
String methodName,
Object... arguments)
Used to specify expectations on methods using the method name. |
|
static
|
expectStrictNew(Class<T> type,
Class<?>[] parameterTypes,
Object... arguments)
Allows specifying expectations on new invocations. |
|
static
|
expectStrictNew(Class<T> type,
Object... arguments)
Allows specifying expectations on new invocations. |
|
static void |
mockStatic(Class<?> type)
Enable static mocking for a class. |
|
static void |
mockStatic(Class<?> type,
Method... methods)
Enable static mocking for a class. |
|
static void |
mockStaticNice(Class<?> type)
Enable nice static mocking for a class. |
|
static void |
mockStaticNice(Class<?> type,
Method... methods)
Enable nice static mocking for a class. |
|
static void |
mockStaticPartial(Class<?> clazz,
String... methodNames)
A utility method that may be used to mock several static methods in an easy way (by just passing in the method names of the method you wish to mock). |
|
static void |
mockStaticPartial(Class<?> clazz,
String methodNameToMock,
Class<?> firstArgumentType,
Class<?>... additionalArgumentTypes)
Mock a single static method. |
|
static void |
mockStaticPartialNice(Class<?> clazz,
String... methodNames)
A utility method that may be used to mock several static methods (nice) in an easy way (by just passing in the method names of the method you wish to mock). |
|
static void |
mockStaticPartialNice(Class<?> clazz,
String methodNameToMock,
Class<?> firstArgumentType,
Class<?>... additionalArgumentTypes)
Mock a single static method (nice). |
|
static void |
mockStaticPartialStrict(Class<?> clazz,
String... methodNames)
A utility method that may be used to mock several static methods (strict) in an easy way (by just passing in the method names of the method you wish to mock). |
|
static void |
mockStaticPartialStrict(Class<?> clazz,
String methodNameToMock,
Class<?> firstArgumentType,
Class<?>... additionalArgumentTypes)
Mock a single static method (strict). |
|
static void |
mockStaticStrict(Class<?> type)
Enable strict static mocking for a class. |
|
static void |
mockStaticStrict(Class<?> type,
Method... methods)
Enable strict static mocking for a class. |
|
static void |
niceReplayAndVerify()
Sometimes it is useful to allow replay and verify on non-mocks. |
|
static void |
replay(Object... mocks)
Switches the mocks or classes to replay mode. |
|
static void |
replayAll(Object... additionalMocks)
Replay all classes and mock objects known by PowerMock. |
|
static void |
reset(Class<?>... classMocks)
Reset a list of class mocks. |
|
static void |
reset(Object... mocks)
Reset a list of mock objects or classes. |
|
static void |
resetAll(Object... additionalMocks)
Reset all classes and mock objects known by PowerMock. |
|
static void |
suppressConstructor(Class<?>... classes)
Deprecated. Use MemberModifier.suppress(Constructor[]) instead. |
|
static void |
suppressConstructor(Class<?> clazz,
boolean excludePrivateConstructors)
Deprecated. Use MemberModifier.suppress(Constructor[]) instead. |
|
static void |
suppressConstructor(Constructor<?>... constructors)
Deprecated. Use MemberModifier.suppress(Constructor[]) instead. |
|
static void |
suppressField(Class<?>[] classes)
Deprecated. Use MemberModifier.suppress(Field[]) instead. |
|
static void |
suppressField(Class<?> clazz,
String... fieldNames)
Deprecated. Use MemberModifier.suppress(Field) instead. |
|
static void |
suppressField(Field... fields)
Deprecated. Use MemberModifier.suppress(Field[]) instead. |
|
static void |
suppressMethod(Class<?>[] classes)
Deprecated. Use MemberModifier.suppress(Method[]) instead. |
|
static void |
suppressMethod(Class<?> clazz,
boolean excludePrivateMethods)
Deprecated. Use MemberModifier.suppress(Method[]) instead. |
|
static void |
suppressMethod(Class<?> cls,
Class<?>... additionalClasses)
Deprecated. Use MemberModifier.suppress(Method[]) instead. |
|
static void |
suppressMethod(Class<?> clazz,
String[] methodNames)
Deprecated. Use MemberModifier.suppress(Method[]) instead. |
|
static void |
suppressMethod(Class<?> clazz,
String methodName,
Class<?>[] parameterTypes)
Deprecated. Use MemberModifier.suppress(Method) instead. |
|
static void |
suppressMethod(Class<?> clazz,
String methodName,
String... additionalMethodNames)
Deprecated. Use MemberModifier.suppress(Method[]) instead. |
|
static void |
suppressMethod(Method... methods)
Deprecated. Use MemberModifier.suppress(Method[]) instead. |
|
static void |
suppressSpecificConstructor(Class<?> clazz,
Class<?>... parameterTypes)
Deprecated. Use MemberModifier.suppress(Constructor) instead. |
|
static void |
verify(Object... objects)
Switches the mocks or classes to verify mode. |
|
static void |
verifyAll()
Verify all classes and mock objects known by PowerMock. |
Methods inherited from class org.powermock.api.support.membermodification.MemberModifier |
---|
replace, stub, suppress, suppress, suppress, suppress, suppress, suppress, suppress |
Methods inherited from class org.powermock.api.support.membermodification.MemberMatcher |
---|
constructor, constructor, constructors, constructorsDeclaredIn, defaultConstructorIn, everythingDeclaredIn, field, fields, fields, fields, fields, method, method, methods, methods, methods, methodsDeclaredIn |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PowerMock()
Method Detail |
---|
public static <T> T createMock(Class<T> type, Method... methods)
T
- the type of the mock objecttype
- the type of the mock objectmethods
- optionally what methods to mock
public static <T> T createMock(Class<T> type)
T
- the type of the mock objecttype
- the type of the mock object
public static <T> T createMock(Class<T> type, org.easymock.ConstructorArgs constructorArgs, Method... methods)
T
- the type of the mock objecttype
- the type of the mock objectconstructorArgs
- The constructor arguments that will be used to invoke a
special constructor.methods
- optionally what methods to mock
public static <T> T createMock(Class<T> type, Object... constructorArguments)
T
- the type of the mock objecttype
- the type of the mock objectconstructorArguments
- The constructor arguments that will be used to invoke a
certain constructor.
public static <T> T createStrictMock(Class<T> type, Method... methods)
T
- the type of the mock objecttype
- the type of the mock objectmethods
- optionally what methods to mock
public static <T> T createStrictMock(Class<T> type)
T
- the type of the mock objecttype
- the type of the mock object
public static <T> T createNiceMock(Class<T> type, Method... methods)
T
- the type of the mock objecttype
- the type of the mock objectmethods
- optionally what methods to mock
public static <T> T createNiceMock(Class<T> type)
T
- the type of the mock objecttype
- the type of the mock object
public static <T> T createStrictMock(Class<T> type, org.easymock.ConstructorArgs constructorArgs, Method... methods)
T
- the type of the mock objecttype
- the type of the mock objectconstructorArgs
- The constructor arguments that will be used to invoke a
special constructor.methods
- optionally what methods to mock
public static <T> T createNiceMock(Class<T> type, org.easymock.ConstructorArgs constructorArgs, Method... methods)
T
- the type of the mock objecttype
- the type of the mock objectconstructorArgs
- The constructor arguments that will be used to invoke a
special constructor.methods
- optionally what methods to mock
public static <T> T createStrictMock(Class<T> type, Object... constructorArguments)
T
- the type of the mock objecttype
- the type of the mock objectconstructorArguments
- The constructor arguments that will be used to invoke a
certain constructor.
public static <T> T createNiceMock(Class<T> type, Object... constructorArguments)
T
- the type of the mock objecttype
- the type of the mock objectconstructorArguments
- The constructor arguments that will be used to invoke a
certain constructor.
public static void mockStatic(Class<?> type, Method... methods)
type
- the class to enable static mockingmethods
- optionally what methods to mockpublic static void mockStatic(Class<?> type)
type
- the class to enable static mockingpublic static void mockStaticStrict(Class<?> type, Method... methods)
type
- the class to enable static mockingmethods
- optionally what methods to mockpublic static void mockStaticStrict(Class<?> type)
type
- the class to enable static mockingpublic static void mockStaticNice(Class<?> type, Method... methods)
type
- the class to enable static mockingmethods
- optionally what methods to mockpublic static void mockStaticNice(Class<?> type)
type
- the class to enable static mockingpublic static <T> T createPartialMockForAllMethodsExcept(Class<T> type, String... methodNames)
type
. This method will
mock ALL methods that doesn't match the supplied name(s) regardless of
parameter types and signature. If this is not the case you should
fall-back on using the createMock(Class, Method...)
method
instead.
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
public static <T> T createNicePartialMockForAllMethodsExcept(Class<T> type, String... methodNames)
type
. This method
will mock ALL methods that doesn't match the supplied name(s) regardless
of parameter types and signature. If this is not the case you should
fall-back on using the createMock(Class, Method...)
method
instead.
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
public static <T> T createStrictPartialMockForAllMethodsExcept(Class<T> type, String... methodNames)
type
. This method
will mock ALL methods that doesn't match the supplied name(s) regardless
of parameter types and signature. If this is not the case you should
fall-back on using the createMock(Class, Method...)
method
instead.
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
public static <T> T createPartialMockForAllMethodsExcept(Class<T> type, String methodNameToExclude, Class<?> firstArgumentType, Class<?>... moreTypes)
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNameToExclude
- The name of the method not to mock.firstArgumentType
- The type of the first parameter of the method not to mockmoreTypes
- Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
public static <T> T createNicePartialMockForAllMethodsExcept(Class<T> type, String methodNameToExclude, Class<?> firstArgumentType, Class<?>... moreTypes)
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNameToExclude
- The name of the method not to mock.firstArgumentType
- The type of the first parameter of the method not to mockmoreTypes
- Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
public static <T> T createStrictPartialMockForAllMethodsExcept(Class<T> type, String methodNameToExclude, Class<?> firstArgumentType, Class<?>... moreTypes)
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNameToExclude
- The name of the method not to mock.firstArgumentType
- The type of the first parameter of the method not to mockmoreTypes
- Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
public static <T> T createPartialMock(Class<T> type, String methodNameToMock, Class<?> firstArgumentType, Class<?>... additionalArgumentTypes)
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNameToMock
- The name of the method to mockfirstArgumentType
- The type of the first parameter of the method to mockadditionalArgumentTypes
- Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
public static <T> T createStrictPartialMock(Class<T> type, String methodNameToMock, Class<?> firstArgumentType, Class<?>... additionalArgumentTypes)
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNameToMock
- The name of the method to mockfirstArgumentType
- The type of the first parameter of the method to mockadditionalArgumentTypes
- Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
public static <T> T createNicePartialMock(Class<T> type, String methodNameToMock, Class<?> firstArgumentType, Class<?>... additionalArgumentTypes)
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNameToMock
- The name of the method to mockfirstArgumentType
- The type of the first parameter of the method to mockadditionalArgumentTypes
- Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
public static void mockStaticPartial(Class<?> clazz, String methodNameToMock, Class<?> firstArgumentType, Class<?>... additionalArgumentTypes)
clazz
- The class where the method is specified in.methodNameToMock
- The first argumentfirstArgumentType
- The first argument type.additionalArgumentTypes
- Optional additional argument types.public static void mockStaticPartialStrict(Class<?> clazz, String methodNameToMock, Class<?> firstArgumentType, Class<?>... additionalArgumentTypes)
clazz
- The class where the method is specified in.methodNameToMock
- The first argumentfirstArgumentType
- The first argument type.additionalArgumentTypes
- Optional additional argument types.public static void mockStaticPartialNice(Class<?> clazz, String methodNameToMock, Class<?> firstArgumentType, Class<?>... additionalArgumentTypes)
clazz
- The class where the method is specified in.methodNameToMock
- The first argumentfirstArgumentType
- The first argument type.additionalArgumentTypes
- Optional additional argument types.public static void mockStaticPartial(Class<?> clazz, String... methodNames)
type
. This method will mock ALL methods that match the
supplied name regardless of parameter types and signature. If this is the
case you should fall-back on using the
mockStatic(Class, Method...)
method instead.
clazz
- The class that contains the static methods that should be
mocked.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling mockStatic(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).public static void mockStaticPartialStrict(Class<?> clazz, String... methodNames)
type
. This method will mock ALL methods that match the
supplied name regardless of parameter types and signature. If this is the
case you should fall-back on using the
mockStaticStrict(Class, Method...)
method instead.
clazz
- The class that contains the static methods that should be
mocked.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling mockStatic(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).public static void mockStaticPartialNice(Class<?> clazz, String... methodNames)
type
. This method will mock ALL methods that match the
supplied name regardless of parameter types and signature. If this is the
case you should fall-back on using the
mockStaticStrict(Class, Method...)
method instead.
clazz
- The class that contains the static methods that should be
mocked.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling mockStatic(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).public static <T> T createPartialMock(Class<T> type, String... methodNames)
type
.
This method will mock ALL methods that match the supplied name regardless
of parameter types and signature. If this is the case you should
fall-back on using the createMock(Class, Method...)
method
instead.
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
public static <T> T createPartialMock(Class<T> type, Class<? super T> where, String... methodNames)
type
.
This method will mock ALL methods that match the supplied name regardless
of parameter types and signature. If this is the case you should
fall-back on using the createMock(Class, Method...)
method
instead.
With this method you can specify where the class hierarchy the methods are located. This is useful in, for example, situations where class A extends B and both have a method called "mockMe" (A overrides B's mockMe method) and you like to specify the only the "mockMe" method in B should be mocked. "mockMe" in A should be left intact. In this case you should do:
A tested = createPartialMock(A.class, B.class, "mockMe");
T
- The type of the mock.type
- The type that'll be used to create a mock instance.where
- Where in the class hierarchy the methods resides.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
public static <T> T createStrictPartialMock(Class<T> type, String... methodNames)
type
. This method will mock ALL methods that match the
supplied name regardless of parameter types and signature. If this is the
case you should fall-back on using the
createMock(Class, Method...)
method instead.
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
public static <T> T createStrictPartialMock(Class<T> type, Class<? super T> where, String... methodNames)
type
. This method will mock ALL methods that match the
supplied name regardless of parameter types and signature. If this is the
case you should fall-back on using the
createMock(Class, Method...)
method instead.
With this method you can specify where the class hierarchy the methods are located. This is useful in, for example, situations where class A extends B and both have a method called "mockMe" (A overrides B's mockMe method) and you like to specify the only the "mockMe" method in B should be mocked. "mockMe" in A should be left intact. In this case you should do:
A tested = createPartialMockStrict(A.class, B.class, "mockMe");
T
- The type of the mock.type
- The type that'll be used to create a mock instance.where
- Where in the class hierarchy the methods resides.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
public static <T> T createNicePartialMock(Class<T> type, String... methodNames)
type
. This method will mock ALL methods that match the
supplied name regardless of parameter types and signature. If this is the
case you should fall-back on using the
createMock(Class, Method...)
method instead.
T
- The type of the mock.type
- The type that'll be used to create a mock instance.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
public static <T> T createNicePartialMock(Class<T> type, Class<? super T> where, String... methodNames)
type
. This method will mock ALL methods that match the
supplied name regardless of parameter types and signature. If this is the
case you should fall-back on using the
createMock(Class, Method...)
method instead.
With this method you can specify where the class hierarchy the methods are located. This is useful in, for example, situations where class A extends B and both have a method called "mockMe" (A overrides B's mockMe method) and you like to specify the only the "mockMe" method in B should be mocked. "mockMe" in A should be left intact. In this case you should do:
A tested = createPartialMockNice(A.class, B.class, "mockMe");
T
- The type of the mock.type
- The type that'll be used to create a mock instance.where
- Where in the class hierarchy the methods resides.methodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
public static <T> T createPartialMockAndInvokeDefaultConstructor(Class<T> type, String... methodNames) throws Exception
T
- the type of the mock objecttype
- the type of the mock objectmethodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
Exception
public static <T> T createNicePartialMockAndInvokeDefaultConstructor(Class<T> type, String... methodNames) throws Exception
T
- the type of the mock objecttype
- the type of the mock objectmethodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
Exception
public static <T> T createStrictPartialMockAndInvokeDefaultConstructor(Class<T> type, String... methodNames) throws Exception
T
- the type of the mock objecttype
- the type of the mock objectmethodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).
Exception
public static <T> T createPartialMock(Class<T> type, String[] methodNames, Object... constructorArguments)
T
- the type of the mock objecttype
- the type of the mock objectmethodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).constructorArguments
- The constructor arguments that will be used to invoke a
certain constructor. (optional)
public static <T> T createStrictPartialMock(Class<T> type, String[] methodNames, Object... constructorArguments)
T
- the type of the mock objecttype
- the type of the mock objectmethodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).constructorArguments
- The constructor arguments that will be used to invoke a
certain constructor. (optional)
public static <T> T createNicePartialMock(Class<T> type, String[] methodNames, Object... constructorArguments)
T
- the type of the mock objecttype
- the type of the mock objectmethodNames
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).constructorArguments
- The constructor arguments that will be used to invoke a
certain constructor. (optional)
public static <T> T createPartialMock(Class<T> type, String methodName, Class<?>[] methodParameterTypes, Object... constructorArguments)
T
- the type of the mock objecttype
- the type of the mock objectmethodName
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).methodParameterTypes
- Parameter types that defines the method. Note that this is
only needed to separate overloaded methods.constructorArguments
- The constructor arguments that will be used to invoke a
certain constructor. (optional)
public static <T> T createStrictPartialMock(Class<T> type, String methodName, Class<?>[] methodParameterTypes, Object... constructorArguments)
T
- the type of the mock objecttype
- the type of the mock objectmethodName
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).methodParameterTypes
- Parameter types that defines the method. Note that this is
only needed to separate overloaded methods.constructorArguments
- The constructor arguments that will be used to invoke a
certain constructor. (optional)
public static <T> T createNicePartialMock(Class<T> type, String methodName, Class<?>[] methodParameterTypes, Object... constructorArguments)
T
- the type of the mock objecttype
- the type of the mock objectmethodName
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).methodParameterTypes
- Parameter types that defines the method. Note that this is
only needed to separate overloaded methods.constructorArguments
- The constructor arguments that will be used to invoke a
certain constructor. (optional)
public static <T> T createPartialMock(Class<T> type, String methodName, Class<?>[] methodParameterTypes, Object[] constructorArguments, Class<?>[] constructorParameterTypes)
T
- the type of the mock objecttype
- the type of the mock objectmethodName
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).methodParameterTypes
- Parameter types that defines the method. Note that this is
only needed to separate overloaded methods.constructorArguments
- The constructor arguments that will be used to invoke a
certain constructor.constructorParameterTypes
- Parameter types that defines the constructor that should be
invoked. Note that this is only needed to separate overloaded
constructors.
public static <T> T createStrictPartialMock(Class<T> type, String methodName, Class<?>[] methodParameterTypes, Object[] constructorArguments, Class<?>[] constructorParameterTypes)
T
- the type of the mock objecttype
- the type of the mock objectmethodName
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).methodParameterTypes
- Parameter types that defines the method. Note that this is
only needed to separate overloaded methods.constructorArguments
- The constructor arguments that will be used to invoke a
certain constructor.constructorParameterTypes
- Parameter types that defines the constructor that should be
invoked. Note that this is only needed to separate overloaded
constructors.
public static <T> T createNicePartialMock(Class<T> type, String methodName, Class<?>[] methodParameterTypes, Object[] constructorArguments, Class<?>[] constructorParameterTypes)
T
- the type of the mock objecttype
- the type of the mock objectmethodName
- The names of the methods that should be mocked. If
null
, then this method will have the same effect
as just calling createMock(Class, Method...)
with the
second parameter as new Method[0]
(i.e. all
methods in that class will be mocked).methodParameterTypes
- Parameter types that defines the method. Note that this is
only needed to separate overloaded methods.constructorArguments
- The constructor arguments that will be used to invoke a
certain constructor.constructorParameterTypes
- Parameter types that defines the constructor that should be
invoked. Note that this is only needed to separate overloaded
constructors.
public static <T> org.easymock.IExpectationSetters<T> expectPrivate(Class<?> clazz, Method method, Object... arguments) throws Exception
Exception
public static <T> org.easymock.IExpectationSetters<T> expectPrivate(Object instance, Method method, Object... arguments) throws Exception
Exception
public static <T> org.easymock.IExpectationSetters<T> expectPrivate(Object instance, String methodName, Class<?>[] parameterTypes, Object... arguments) throws Exception
Exception
public static <T> org.easymock.IExpectationSetters<T> expectPrivate(Object instance, String methodName, Object... arguments) throws Exception
Exception
public static <T> org.easymock.IExpectationSetters<T> expectPrivate(Object instance, Object... arguments) throws Exception
expectPrivate(Object, String, Object...)
.
Exception
public static <T> org.easymock.IExpectationSetters<T> expectPrivate(Object instance, String methodName, Class<?> where, Class<?>[] parameterTypes, Object... arguments) throws Exception
where
parameter). Works on for example private or package
private methods.
Use this for overloaded methods.
Exception
public static <T> org.easymock.IExpectationSetters<T> expectPrivate(Object instance, String methodName, Class<?> where, Object... arguments) throws Exception
where
parameter). Works on for example private or package
private methods.
Exception
public static org.easymock.IExpectationSetters<Object> expectLastCall()
EasyMock.expectLastCall()
method.
EasyMock.expectLastCall()
public static void niceReplayAndVerify()
public static void replayAll(Object... additionalMocks)
PrepareForTest
or
PrepareOnlyThisForTest
annotations and all classes that have had
their static initializers removed by using the
SuppressStaticInitializationFor
annotation. It also includes all
mock instances created by PowerMock such as those created or used by
createMock(Class, Method...)
,
mockStatic(Class, Method...)
,
expectNew(Class, Object...)
,
createPartialMock(Class, String...)
etc.
To make it easy to pass in additional mocks not created by the PowerMock API you can optionally specify them as additionalMocks . These are typically those mock objects you have created using pure EasyMock or EasyMock class extensions. No additional mocks needs to be specified if you're only using PowerMock API methods.
Note that the additionalMocks are also automatically verified
when invoking the verifyAll()
method.
additionalMocks
- Mocks not created by the PowerMock API. These are typically
those mock objects you have created using pure EasyMock or
EasyMock class extensions.public static void resetAll(Object... additionalMocks)
PrepareForTest
or
PrepareOnlyThisForTest
annotations and all classes that have had
their static initializers removed by using the
SuppressStaticInitializationFor
annotation. It also includes all
mock instances created by PowerMock such as those created or used by
createMock(Class, Method...)
,
mockStatic(Class, Method...)
,
expectNew(Class, Object...)
,
createPartialMock(Class, String...)
etc.
To make it easy to pass in additional mocks not created by the PowerMock API you can optionally specify them as additionalMocks . These are typically those mock objects you have created using pure EasyMock or EasyMock class extensions. No additional mocks needs to be specified if you're only using PowerMock API methods.
additionalMocks
- Mocks not created by the PowerMock API. These are typically
those mock objects you have created using pure EasyMock or
EasyMock class extensions.public static void reset(Class<?>... classMocks)
public static void reset(Object... mocks)
public static void verifyAll()
PrepareForTest
or
PrepareOnlyThisForTest
annotations and all classes that have had
their static initializers removed by using the
SuppressStaticInitializationFor
annotation. It also includes all
mock instances created by PowerMock such as those created or used by
createMock(Class, Method...)
,
mockStatic(Class, Method...)
,
expectNew(Class, Object...)
,
createPartialMock(Class, String...)
etc.
Note that all additionalMocks passed to the
replayAll(Object...)
method are also verified here
automatically.
public static void replay(Object... mocks)
mocks
- mock objects or classes loaded by PowerMock.
Exception
- If something unexpected goes wrong.public static void verify(Object... objects)
objects
- mock objects or classes loaded by PowerMock.public static <T> T createMockAndExpectNew(Class<T> type, Object... arguments) throws Exception
type
- The class that should be mocked.arguments
- The constructor arguments.
Exception
public static <T> T createMockAndExpectNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments) throws Exception
int
and Integer
.
type
- The class that should be mocked.parameterTypes
- The constructor parameter types.arguments
- The constructor arguments.
Exception
public static <T> T createNiceMockAndExpectNew(Class<T> type, Object... arguments) throws Exception
type
- The class that should be mocked.arguments
- The constructor arguments.
Exception
public static <T> T createNiceMockAndExpectNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments) throws Exception
int
and Integer
.
type
- The class that should be mocked.parameterTypes
- The constructor parameter types.arguments
- The constructor arguments.
Exception
public static <T> T createStrictMockAndExpectNew(Class<T> type, Object... arguments) throws Exception
type
- The class that should be mocked.arguments
- The constructor arguments.
Exception
public static <T> T createStrictMockAndExpectNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments) throws Exception
int
and Integer
.
type
- The class that should be mocked.parameterTypes
- The constructor parameter types.arguments
- The constructor arguments.
Exception
public static <T> org.easymock.IExpectationSetters<T> expectNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments) throws Exception
Use this method when you need to specify parameter types for the
constructor when PowerMock cannot determine which constructor to use
automatically. In most cases you should use
expectNew(Class, Object...)
instead.
Exception
public static <T> org.easymock.IExpectationSetters<T> expectNew(Class<T> type, Object... arguments) throws Exception
Exception
public static <T> org.easymock.IExpectationSetters<T> expectNew(String fullyQualifiedName, Object... arguments) throws Exception
fullyQualifiedName
- The fully-qualified name of the inner/local/anonymous type to
expect.arguments
- Optional number of arguments.
Exception
public static <T> org.easymock.IExpectationSetters<T> expectStrictNew(Class<T> type, Object... arguments) throws Exception
This method checks the order of constructor invocations.
Note that you must replay the class when using this method since this behavior is part of the class mock.
Exception
public static <T> org.easymock.IExpectationSetters<T> expectStrictNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments) throws Exception
This method checks the order of constructor invocations.
Use this method when you need to specify parameter types for the
constructor when PowerMock cannot determine which constructor to use
automatically. In most cases you should use
expectNew(Class, Object...)
instead.
Exception
public static <T> org.easymock.IExpectationSetters<T> expectNiceNew(Class<T> type, Object... arguments) throws Exception
This method allows any number of calls to a new constructor without throwing an exception.
Note that you must replay the class when using this method since this behavior is part of the class mock.
Exception
public static <T> org.easymock.IExpectationSetters<T> expectNiceNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments) throws Exception
This method allows any number of calls to a new constructor without throwing an exception.
Use this method when you need to specify parameter types for the
constructor when PowerMock cannot determine which constructor to use
automatically. In most cases you should use
expectNew(Class, Object...)
instead.
Exception
public static void suppressConstructor(Constructor<?>... constructors)
MemberModifier.suppress(Constructor[])
instead.
public static void suppressSpecificConstructor(Class<?> clazz, Class<?>... parameterTypes)
MemberModifier.suppress(Constructor)
instead.
clazz
- The class where the constructor is located.parameterTypes
- The parameter types of the constructor to suppress.public static void suppressConstructor(Class<?>... classes)
MemberModifier.suppress(Constructor[])
instead.
classes
- The classes whose constructors will be suppressed.public static void suppressConstructor(Class<?> clazz, boolean excludePrivateConstructors)
MemberModifier.suppress(Constructor[])
instead.
clazz
- The classes whose constructors will be suppressed.excludePrivateConstructors
- optionally keep code in private constructorspublic static void suppressField(Field... fields)
MemberModifier.suppress(Field[])
instead.
public static void suppressField(Class<?>[] classes)
MemberModifier.suppress(Field[])
instead.
public static void suppressField(Class<?> clazz, String... fieldNames)
MemberModifier.suppress(Field)
instead.
clazz
- The class whose methods will be suppressed.fieldNames
- The names of the methods that'll be suppressed. If field names
are empty, all fields in the supplied class will be
suppressed.public static void suppressMethod(Method... methods)
MemberModifier.suppress(Method[])
instead.
public static void suppressMethod(Class<?> cls, Class<?>... additionalClasses)
MemberModifier.suppress(Method[])
instead.
cls
- The first class whose methods will be suppressed.additionalClasses
- Additional classes whose methods will be suppressed.public static void suppressMethod(Class<?>[] classes)
MemberModifier.suppress(Method[])
instead.
classes
- Classes whose methods will be suppressed.public static void suppressMethod(Class<?> clazz, String methodName, String... additionalMethodNames)
MemberModifier.suppress(Method[])
instead.
clazz
- The class whose methods will be suppressed.methodName
- The first method to be suppress in class clazz
.additionalMethodNames
- Additional methods to suppress in class clazz
.public static void suppressMethod(Class<?> clazz, String[] methodNames)
MemberModifier.suppress(Method[])
instead.
clazz
- The class whose methods will be suppressed.methodNames
- Methods to suppress in class clazz
.public static void suppressMethod(Class<?> clazz, boolean excludePrivateMethods)
MemberModifier.suppress(Method[])
instead.
clazz
- The class which methods will be suppressed.excludePrivateMethods
- optionally not suppress private methodspublic static void suppressMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes)
MemberModifier.suppress(Method)
instead.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |