Class PowerMock


  • public class PowerMock
    extends MemberModifier
    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.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  PowerMock.EasyMockStateCleaner
      Clears the state in LastControl that deals with MocksControl.
    • Constructor Summary

      Constructors 
      Constructor Description
      PowerMock()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static <T> T createMock​(java.lang.Class<T> type)
      Creates a mock object that supports mocking of final and native methods.
      static <T> T createMock​(java.lang.Class<T> type, java.lang.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 <T> T createMock​(java.lang.Class<T> type, java.lang.reflect.Method... methods)
      Creates a mock object that supports mocking of final and native methods.
      static <T> T createMock​(java.lang.Class<T> type, org.easymock.ConstructorArgs constructorArgs, java.lang.reflect.Method... methods)
      Creates a mock object that supports mocking of final and native methods and invokes a specific constructor.
      static <T> T createMockAndExpectNew​(java.lang.Class<T> type, java.lang.Class<?>[] parameterTypes, java.lang.Object... arguments)
      Convenience method for createMock followed by expectNew when PowerMock cannot determine which constructor to use automatically.
      static <T> T createMockAndExpectNew​(java.lang.Class<T> type, java.lang.Object... arguments)
      Convenience method for createMock followed by expectNew.
      static <T> T createNiceMock​(java.lang.Class<T> type)
      Creates a nice mock object that supports mocking of final and native methods.
      static <T> T createNiceMock​(java.lang.Class<T> type, java.lang.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 <T> T createNiceMock​(java.lang.Class<T> type, java.lang.reflect.Method... methods)
      Creates a nice mock object that supports mocking of final and native methods.
      static <T> T createNiceMock​(java.lang.Class<T> type, org.easymock.ConstructorArgs constructorArgs, java.lang.reflect.Method... methods)
      Creates a nice mock object that supports mocking of final and native methods and invokes a specific constructor.
      static <T> T createNiceMockAndExpectNew​(java.lang.Class<T> type, java.lang.Class<?>[] parameterTypes, java.lang.Object... arguments)
      Convenience method for createNiceMock followed by expectNew when PowerMock cannot determine which constructor to use automatically.
      static <T> T createNiceMockAndExpectNew​(java.lang.Class<T> type, java.lang.Object... arguments)
      Convenience method for createNiceMock followed by expectNew.
      static <T> T createNicePartialMock​(java.lang.Class<T> type, java.lang.Class<? super T> where, java.lang.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 <T> T createNicePartialMock​(java.lang.Class<T> type, java.lang.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 <T> T createNicePartialMock​(java.lang.Class<T> type, java.lang.String[] methodNames, java.lang.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 <T> T createNicePartialMock​(java.lang.Class<T> type, java.lang.String methodName, java.lang.Class<?>[] methodParameterTypes, java.lang.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 <T> T createNicePartialMock​(java.lang.Class<T> type, java.lang.String methodName, java.lang.Class<?>[] methodParameterTypes, java.lang.Object[] constructorArguments, java.lang.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 <T> T createNicePartialMock​(java.lang.Class<T> type, java.lang.String methodNameToMock, java.lang.Class<?> firstArgumentType, java.lang.Class<?>... additionalArgumentTypes)
      Nicely mock a single specific method.
      static <T> T createNicePartialMockAndInvokeDefaultConstructor​(java.lang.Class<T> type, java.lang.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 <T> T createNicePartialMockForAllMethodsExcept​(java.lang.Class<T> type, java.lang.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 <T> T createNicePartialMockForAllMethodsExcept​(java.lang.Class<T> type, java.lang.String methodNameToExclude, java.lang.Class<?> firstArgumentType, java.lang.Class<?>... moreTypes)
      Mock all methods of a class except for a specific one nicely.
      static <T> T createPartialMock​(java.lang.Class<T> type, java.lang.Class<? super T> where, java.lang.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 <T> T createPartialMock​(java.lang.Class<T> type, java.lang.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 <T> T createPartialMock​(java.lang.Class<T> type, java.lang.String[] methodNames, java.lang.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 <T> T createPartialMock​(java.lang.Class<T> type, java.lang.String methodName, java.lang.Class<?>[] methodParameterTypes, java.lang.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 <T> T createPartialMock​(java.lang.Class<T> type, java.lang.String methodName, java.lang.Class<?>[] methodParameterTypes, java.lang.Object[] constructorArguments, java.lang.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 <T> T createPartialMock​(java.lang.Class<T> type, java.lang.String methodNameToMock, java.lang.Class<?> firstArgumentType, java.lang.Class<?>... additionalArgumentTypes)
      Mock a single specific method.
      static <T> T createPartialMockAndInvokeDefaultConstructor​(java.lang.Class<T> type, java.lang.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 <T> T createPartialMockForAllMethodsExcept​(java.lang.Class<T> type, java.lang.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 <T> T createPartialMockForAllMethodsExcept​(java.lang.Class<T> type, java.lang.String methodNameToExclude, java.lang.Class<?> firstArgumentType, java.lang.Class<?>... moreTypes)
      Mock all methods of a class except for a specific one.
      private static <T> java.lang.Class<?> createReplicaType​(java.lang.Class<T> type, boolean isStatic, org.easymock.ConstructorArgs constructorArgs)  
      static <T> T createStrictMock​(java.lang.Class<T> type)
      Creates a strict mock object that supports mocking of final and native methods.
      static <T> T createStrictMock​(java.lang.Class<T> type, java.lang.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 <T> T createStrictMock​(java.lang.Class<T> type, java.lang.reflect.Method... methods)
      Creates a strict mock object that supports mocking of final and native methods.
      static <T> T createStrictMock​(java.lang.Class<T> type, org.easymock.ConstructorArgs constructorArgs, java.lang.reflect.Method... methods)
      Creates a strict mock object that supports mocking of final and native methods and invokes a specific constructor.
      static <T> T createStrictMockAndExpectNew​(java.lang.Class<T> type, java.lang.Class<?>[] parameterTypes, java.lang.Object... arguments)
      Convenience method for createStrictMock followed by expectNew when PowerMock cannot determine which constructor to use automatically.
      static <T> T createStrictMockAndExpectNew​(java.lang.Class<T> type, java.lang.Object... arguments)
      Convenience method for createStrictMock followed by expectNew.
      static <T> T createStrictPartialMock​(java.lang.Class<T> type, java.lang.Class<? super T> where, java.lang.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 <T> T createStrictPartialMock​(java.lang.Class<T> type, java.lang.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 <T> T createStrictPartialMock​(java.lang.Class<T> type, java.lang.String[] methodNames, java.lang.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 <T> T createStrictPartialMock​(java.lang.Class<T> type, java.lang.String methodName, java.lang.Class<?>[] methodParameterTypes, java.lang.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 <T> T createStrictPartialMock​(java.lang.Class<T> type, java.lang.String methodName, java.lang.Class<?>[] methodParameterTypes, java.lang.Object[] constructorArguments, java.lang.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 <T> T createStrictPartialMock​(java.lang.Class<T> type, java.lang.String methodNameToMock, java.lang.Class<?> firstArgumentType, java.lang.Class<?>... additionalArgumentTypes)
      Strictly mock a single specific method.
      static <T> T createStrictPartialMockAndInvokeDefaultConstructor​(java.lang.Class<T> type, java.lang.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 <T> T createStrictPartialMockForAllMethodsExcept​(java.lang.Class<T> type, java.lang.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 <T> T createStrictPartialMockForAllMethodsExcept​(java.lang.Class<T> type, java.lang.String methodNameToExclude, java.lang.Class<?> firstArgumentType, java.lang.Class<?>... moreTypes)
      Mock all methods of a class except for a specific one strictly.
      private static <T> T doCreateMock​(java.lang.Class<T> type, org.easymock.ConstructorArgs constructorArgs, org.easymock.IMocksControl control, java.lang.reflect.Method... methods)  
      private static <T> org.easymock.IExpectationSetters<T> doExpectNew​(java.lang.Class<T> type, MockStrategy mockStrategy, java.lang.Class<?>[] parameterTypes, java.lang.Object... arguments)  
      private static <T> org.easymock.IExpectationSetters<T> doExpectPrivate​(java.lang.Object instance, java.lang.reflect.Method methodToExpect, java.lang.Object... arguments)  
      private static <T> T doMock​(java.lang.Class<T> type, boolean isStatic, MockStrategy mockStrategy, org.easymock.ConstructorArgs constructorArgs, java.lang.reflect.Method... methods)  
      (package private) static <T> T doMockSpecific​(java.lang.Class<T> type, MockStrategy mockStrategy, java.lang.String[] methodNamesToMock, org.easymock.ConstructorArgs constructorArgs, java.lang.Class<?>... argumentTypes)  
      static org.easymock.IExpectationSetters<java.lang.Object> expectLastCall()
      This method just delegates to EasyMock class extensions EasyMock.expectLastCall() method.
      static <T> org.easymock.IExpectationSetters<T> expectNew​(java.lang.Class<T> type, java.lang.Class<?>[] parameterTypes, java.lang.Object... arguments)
      Allows specifying expectations on new invocations.
      static <T> org.easymock.IExpectationSetters<T> expectNew​(java.lang.Class<T> type, java.lang.Object... arguments)
      Allows specifying expectations on new invocations.
      static <T> org.easymock.IExpectationSetters<T> expectNew​(java.lang.String fullyQualifiedName, java.lang.Object... arguments)
      Allows specifying expectations on new invocations for private member (inner) classes, local or anonymous classes.
      static <T> org.easymock.IExpectationSetters<T> expectNiceNew​(java.lang.Class<T> type, java.lang.Class<?>[] parameterTypes, java.lang.Object... arguments)
      Allows specifying expectations on new invocations.
      static <T> org.easymock.IExpectationSetters<T> expectNiceNew​(java.lang.Class<T> type, java.lang.Object... arguments)
      Allows specifying expectations on new invocations.
      static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Class<?> clazz, java.lang.reflect.Method method, java.lang.Object... arguments)
      Used to specify expectations on private static methods.
      static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance, java.lang.Object... arguments)
      Used to specify expectations on methods without specifying a method name.
      static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance, java.lang.reflect.Method method, java.lang.Object... arguments)
      Used to specify expectations on private methods.
      static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object... arguments)
      Used to specify expectations on private methods.
      static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance, java.lang.String methodName, java.lang.Class<?> where, java.lang.Class<?>[] parameterTypes, java.lang.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 <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance, java.lang.String methodName, java.lang.Class<?> where, java.lang.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 <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance, java.lang.String methodName, java.lang.Object... arguments)
      Used to specify expectations on methods using the method name.
      static <T> org.easymock.IExpectationSetters<T> expectStrictNew​(java.lang.Class<T> type, java.lang.Class<?>[] parameterTypes, java.lang.Object... arguments)
      Allows specifying expectations on new invocations.
      static <T> org.easymock.IExpectationSetters<T> expectStrictNew​(java.lang.Class<T> type, java.lang.Object... arguments)
      Allows specifying expectations on new invocations.
      private static boolean isEasyMocked​(java.lang.Object mock)
      Test if a object is a mock created by EasyMock or not.
      private static boolean isNiceReplayAndVerifyMode()  
      private static java.lang.Class<?>[] mergeArgumentTypes​(java.lang.Class<?> firstArgumentType, java.lang.Class<?>... additionalArgumentTypes)  
      static void mockStatic​(java.lang.Class<?> type)
      Enable static mocking for a class.
      static void mockStatic​(java.lang.Class<?> type, java.lang.reflect.Method... methods)
      Enable static mocking for a class.
      static void mockStaticNice​(java.lang.Class<?> type)
      Enable nice static mocking for a class.
      static void mockStaticNice​(java.lang.Class<?> type, java.lang.reflect.Method... methods)
      Enable nice static mocking for a class.
      static void mockStaticPartial​(java.lang.Class<?> clazz, java.lang.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​(java.lang.Class<?> clazz, java.lang.String methodNameToMock, java.lang.Class<?> firstArgumentType, java.lang.Class<?>... additionalArgumentTypes)
      Mock a single static method.
      static void mockStaticPartialNice​(java.lang.Class<?> clazz, java.lang.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​(java.lang.Class<?> clazz, java.lang.String methodNameToMock, java.lang.Class<?> firstArgumentType, java.lang.Class<?>... additionalArgumentTypes)
      Mock a single static method (nice).
      static void mockStaticPartialStrict​(java.lang.Class<?> clazz, java.lang.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​(java.lang.Class<?> clazz, java.lang.String methodNameToMock, java.lang.Class<?> firstArgumentType, java.lang.Class<?>... additionalArgumentTypes)
      Mock a single static method (strict).
      static void mockStaticStrict​(java.lang.Class<?> type)
      Enable strict static mocking for a class.
      static void mockStaticStrict​(java.lang.Class<?> type, java.lang.reflect.Method... methods)
      Enable strict static mocking for a class.
      static void niceReplayAndVerify()
      Sometimes it is useful to allow replay and verify on non-mocks.
      private static void replay​(java.lang.Class<?>... types)  
      static void replay​(java.lang.Object... mocks)
      Switches the mocks or classes to replay mode.
      static void replayAll​(java.lang.Object... additionalMocks)
      Replay all classes and mock objects known by PowerMock.
      static void reset​(java.lang.Class<?>... classMocks)
      Reset a list of class mocks.
      static void reset​(java.lang.Object... mocks)
      Reset a list of mock objects or classes.
      static void resetAll​(java.lang.Object... additionalMocks)
      Reset all classes and mock objects known by PowerMock.
      static void suppressConstructor​(java.lang.Class<?>... classes)
      Deprecated.
      static void suppressConstructor​(java.lang.Class<?> clazz, boolean excludePrivateConstructors)
      Deprecated.
      static void suppressConstructor​(java.lang.reflect.Constructor<?>... constructors)
      Deprecated.
      static void suppressField​(java.lang.Class<?>[] classes)
      Deprecated.
      static void suppressField​(java.lang.Class<?> clazz, java.lang.String... fieldNames)
      Deprecated.
      static void suppressField​(java.lang.reflect.Field... fields)
      Deprecated.
      static void suppressMethod​(java.lang.Class<?>[] classes)
      Deprecated.
      static void suppressMethod​(java.lang.Class<?> clazz, boolean excludePrivateMethods)
      Deprecated.
      static void suppressMethod​(java.lang.Class<?> cls, java.lang.Class<?>... additionalClasses)
      Deprecated.
      static void suppressMethod​(java.lang.Class<?> clazz, java.lang.String[] methodNames)
      Deprecated.
      static void suppressMethod​(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>[] parameterTypes)
      Deprecated.
      static void suppressMethod​(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.String... additionalMethodNames)
      Deprecated.
      static void suppressMethod​(java.lang.reflect.Method... methods)
      Deprecated.
      static void suppressSpecificConstructor​(java.lang.Class<?> clazz, java.lang.Class<?>... parameterTypes)
      Deprecated.
      private static java.util.Set<java.lang.reflect.Method> toSet​(java.lang.reflect.Method[] methods)  
      static void verify​(java.lang.Object... objects)
      Switches the mocks or classes to verify mode.
      static void verifyAll()
      Verify all classes and mock objects known by PowerMock.
      private static void verifyClass​(java.lang.Class<?>... types)
      Note: doesn't clear PowerMock state.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NICE_REPLAY_AND_VERIFY_KEY

        private static final java.lang.String NICE_REPLAY_AND_VERIFY_KEY
        See Also:
        Constant Field Values
    • Constructor Detail

      • PowerMock

        public PowerMock()
    • Method Detail

      • createMock

        public static <T> T createMock​(java.lang.Class<T> type,
                                       java.lang.reflect.Method... methods)
        Creates a mock object that supports mocking of final and native methods.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        methods - optionally what methods to mock
        Returns:
        the mock object.
      • createMock

        public static <T> T createMock​(java.lang.Class<T> type)
        Creates a mock object that supports mocking of final and native methods.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        Returns:
        the mock object.
      • createMock

        public static <T> T createMock​(java.lang.Class<T> type,
                                       org.easymock.ConstructorArgs constructorArgs,
                                       java.lang.reflect.Method... methods)
        Creates a mock object that supports mocking of final and native methods and invokes a specific constructor.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        constructorArgs - The constructor arguments that will be used to invoke a special constructor.
        methods - optionally what methods to mock
        Returns:
        the mock object.
      • createMock

        public static <T> T createMock​(java.lang.Class<T> type,
                                       java.lang.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.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        constructorArguments - The constructor arguments that will be used to invoke a certain constructor.
        Returns:
        the mock object.
      • createStrictMock

        public static <T> T createStrictMock​(java.lang.Class<T> type,
                                             java.lang.reflect.Method... methods)
        Creates a strict mock object that supports mocking of final and native methods.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        methods - optionally what methods to mock
        Returns:
        the mock object.
      • createStrictMock

        public static <T> T createStrictMock​(java.lang.Class<T> type)
        Creates a strict mock object that supports mocking of final and native methods.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        Returns:
        the mock object.
      • createNiceMock

        public static <T> T createNiceMock​(java.lang.Class<T> type,
                                           java.lang.reflect.Method... methods)
        Creates a nice mock object that supports mocking of final and native methods.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        methods - optionally what methods to mock
        Returns:
        the mock object.
      • createNiceMock

        public static <T> T createNiceMock​(java.lang.Class<T> type)
        Creates a nice mock object that supports mocking of final and native methods.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        Returns:
        the mock object.
      • createStrictMock

        public static <T> T createStrictMock​(java.lang.Class<T> type,
                                             org.easymock.ConstructorArgs constructorArgs,
                                             java.lang.reflect.Method... methods)
        Creates a strict mock object that supports mocking of final and native methods and invokes a specific constructor.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        constructorArgs - The constructor arguments that will be used to invoke a special constructor.
        methods - optionally what methods to mock
        Returns:
        the mock object.
      • createNiceMock

        public static <T> T createNiceMock​(java.lang.Class<T> type,
                                           org.easymock.ConstructorArgs constructorArgs,
                                           java.lang.reflect.Method... methods)
        Creates a nice mock object that supports mocking of final and native methods and invokes a specific constructor.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        constructorArgs - The constructor arguments that will be used to invoke a special constructor.
        methods - optionally what methods to mock
        Returns:
        the mock object.
      • createStrictMock

        public static <T> T createStrictMock​(java.lang.Class<T> type,
                                             java.lang.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.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        constructorArguments - The constructor arguments that will be used to invoke a certain constructor.
        Returns:
        the mock object.
      • createNiceMock

        public static <T> T createNiceMock​(java.lang.Class<T> type,
                                           java.lang.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.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        constructorArguments - The constructor arguments that will be used to invoke a certain constructor.
        Returns:
        the mock object.
      • mockStatic

        public static void mockStatic​(java.lang.Class<?> type,
                                      java.lang.reflect.Method... methods)
        Enable static mocking for a class.
        Parameters:
        type - the class to enable static mocking
        methods - optionally what methods to mock
      • mockStatic

        public static void mockStatic​(java.lang.Class<?> type)
        Enable static mocking for a class.
        Parameters:
        type - the class to enable static mocking
      • mockStaticStrict

        public static void mockStaticStrict​(java.lang.Class<?> type,
                                            java.lang.reflect.Method... methods)
        Enable strict static mocking for a class.
        Parameters:
        type - the class to enable static mocking
        methods - optionally what methods to mock
      • mockStaticStrict

        public static void mockStaticStrict​(java.lang.Class<?> type)
        Enable strict static mocking for a class.
        Parameters:
        type - the class to enable static mocking
      • mockStaticNice

        public static void mockStaticNice​(java.lang.Class<?> type,
                                          java.lang.reflect.Method... methods)
        Enable nice static mocking for a class.
        Parameters:
        type - the class to enable static mocking
        methods - optionally what methods to mock
      • mockStaticNice

        public static void mockStaticNice​(java.lang.Class<?> type)
        Enable nice static mocking for a class.
        Parameters:
        type - the class to enable static mocking
      • createPartialMockForAllMethodsExcept

        public static <T> T createPartialMockForAllMethodsExcept​(java.lang.Class<T> type,
                                                                 java.lang.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). Note that you cannot uniquely specify a method to exclude using this method if there are several methods with the same name in 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.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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).
        Returns:
        A mock object of type .
      • createNicePartialMockForAllMethodsExcept

        public static <T> T createNicePartialMockForAllMethodsExcept​(java.lang.Class<T> type,
                                                                     java.lang.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). Note that you cannot uniquely specify a method to exclude using this method if there are several methods with the same name in 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.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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).
        Returns:
        A mock object of type .
      • createStrictPartialMockForAllMethodsExcept

        public static <T> T createStrictPartialMockForAllMethodsExcept​(java.lang.Class<T> type,
                                                                       java.lang.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). Note that you cannot uniquely specify a method to exclude using this method if there are several methods with the same name in 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.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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).
        Returns:
        A mock object of type .
      • createPartialMockForAllMethodsExcept

        public static <T> T createPartialMockForAllMethodsExcept​(java.lang.Class<T> type,
                                                                 java.lang.String methodNameToExclude,
                                                                 java.lang.Class<?> firstArgumentType,
                                                                 java.lang.Class<?>... moreTypes)
        Mock all methods of a class except for a specific one. Use this method only if you have several overloaded methods.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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 mock
        moreTypes - Optionally more parameter types that defines the method. Note that this is only needed to separate overloaded methods.
        Returns:
        A mock object of type .
      • createNicePartialMockForAllMethodsExcept

        public static <T> T createNicePartialMockForAllMethodsExcept​(java.lang.Class<T> type,
                                                                     java.lang.String methodNameToExclude,
                                                                     java.lang.Class<?> firstArgumentType,
                                                                     java.lang.Class<?>... moreTypes)
        Mock all methods of a class except for a specific one nicely. Use this method only if you have several overloaded methods.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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 mock
        moreTypes - Optionally more parameter types that defines the method. Note that this is only needed to separate overloaded methods.
        Returns:
        A mock object of type .
      • createStrictPartialMockForAllMethodsExcept

        public static <T> T createStrictPartialMockForAllMethodsExcept​(java.lang.Class<T> type,
                                                                       java.lang.String methodNameToExclude,
                                                                       java.lang.Class<?> firstArgumentType,
                                                                       java.lang.Class<?>... moreTypes)
        Mock all methods of a class except for a specific one strictly. Use this method only if you have several overloaded methods.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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 mock
        moreTypes - Optionally more parameter types that defines the method. Note that this is only needed to separate overloaded methods.
        Returns:
        A mock object of type .
      • createPartialMock

        public static <T> T createPartialMock​(java.lang.Class<T> type,
                                              java.lang.String methodNameToMock,
                                              java.lang.Class<?> firstArgumentType,
                                              java.lang.Class<?>... additionalArgumentTypes)
        Mock a single specific method. Use this to handle overloaded methods.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        type - The type that'll be used to create a mock instance.
        methodNameToMock - The name of the method to mock
        firstArgumentType - The type of the first parameter of the method to mock
        additionalArgumentTypes - Optionally more parameter types that defines the method. Note that this is only needed to separate overloaded methods.
        Returns:
        A mock object of type .
      • createStrictPartialMock

        public static <T> T createStrictPartialMock​(java.lang.Class<T> type,
                                                    java.lang.String methodNameToMock,
                                                    java.lang.Class<?> firstArgumentType,
                                                    java.lang.Class<?>... additionalArgumentTypes)
        Strictly mock a single specific method. Use this to handle overloaded methods.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        type - The type that'll be used to create a mock instance.
        methodNameToMock - The name of the method to mock
        firstArgumentType - The type of the first parameter of the method to mock
        additionalArgumentTypes - Optionally more parameter types that defines the method. Note that this is only needed to separate overloaded methods.
        Returns:
        A mock object of type .
      • createNicePartialMock

        public static <T> T createNicePartialMock​(java.lang.Class<T> type,
                                                  java.lang.String methodNameToMock,
                                                  java.lang.Class<?> firstArgumentType,
                                                  java.lang.Class<?>... additionalArgumentTypes)
        Nicely mock a single specific method. Use this to handle overloaded methods.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        type - The type that'll be used to create a mock instance.
        methodNameToMock - The name of the method to mock
        firstArgumentType - The type of the first parameter of the method to mock
        additionalArgumentTypes - Optionally more parameter types that defines the method. Note that this is only needed to separate overloaded methods.
        Returns:
        A mock object of type .
      • mockStaticPartial

        public static void mockStaticPartial​(java.lang.Class<?> clazz,
                                             java.lang.String methodNameToMock,
                                             java.lang.Class<?> firstArgumentType,
                                             java.lang.Class<?>... additionalArgumentTypes)
        Mock a single static method.
        Parameters:
        clazz - The class where the method is specified in.
        methodNameToMock - The first argument
        firstArgumentType - The first argument type.
        additionalArgumentTypes - Optional additional argument types.
      • mockStaticPartialStrict

        public static void mockStaticPartialStrict​(java.lang.Class<?> clazz,
                                                   java.lang.String methodNameToMock,
                                                   java.lang.Class<?> firstArgumentType,
                                                   java.lang.Class<?>... additionalArgumentTypes)
        Mock a single static method (strict).
        Parameters:
        clazz - The class where the method is specified in.
        methodNameToMock - The first argument
        firstArgumentType - The first argument type.
        additionalArgumentTypes - Optional additional argument types.
      • mockStaticPartialNice

        public static void mockStaticPartialNice​(java.lang.Class<?> clazz,
                                                 java.lang.String methodNameToMock,
                                                 java.lang.Class<?> firstArgumentType,
                                                 java.lang.Class<?>... additionalArgumentTypes)
        Mock a single static method (nice).
        Parameters:
        clazz - The class where the method is specified in.
        methodNameToMock - The first argument
        firstArgumentType - The first argument type.
        additionalArgumentTypes - Optional additional argument types.
      • mockStaticPartial

        public static void mockStaticPartial​(java.lang.Class<?> clazz,
                                             java.lang.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). Note that you cannot uniquely specify a method to mock using this method if there are several methods with the same name in 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.
        Parameters:
        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).
      • mockStaticPartialStrict

        public static void mockStaticPartialStrict​(java.lang.Class<?> clazz,
                                                   java.lang.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). Note that you cannot uniquely specify a method to mock using this method if there are several methods with the same name in 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.
        Parameters:
        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).
      • mockStaticPartialNice

        public static void mockStaticPartialNice​(java.lang.Class<?> clazz,
                                                 java.lang.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). Note that you cannot uniquely specify a method to mock using this method if there are several methods with the same name in 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.
        Parameters:
        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).
      • doMockSpecific

        static <T> T doMockSpecific​(java.lang.Class<T> type,
                                    MockStrategy mockStrategy,
                                    java.lang.String[] methodNamesToMock,
                                    org.easymock.ConstructorArgs constructorArgs,
                                    java.lang.Class<?>... argumentTypes)
      • createPartialMock

        public static <T> T createPartialMock​(java.lang.Class<T> type,
                                              java.lang.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). Note that you cannot uniquely specify a method to mock using this method if there are several methods with the same name in 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.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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).
        Returns:
        A mock object of type .
      • createPartialMock

        public static <T> T createPartialMock​(java.lang.Class<T> type,
                                              java.lang.Class<? super T> where,
                                              java.lang.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). Note that you cannot uniquely specify a method to mock using this method if there are several methods with the same name in 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");
         
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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).
        Returns:
        A mock object of type .
      • createStrictPartialMock

        public static <T> T createStrictPartialMock​(java.lang.Class<T> type,
                                                    java.lang.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). Note that you cannot uniquely specify a method to mock using this method if there are several methods with the same name in 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.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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).
        Returns:
        A mock object of type .
      • createStrictPartialMock

        public static <T> T createStrictPartialMock​(java.lang.Class<T> type,
                                                    java.lang.Class<? super T> where,
                                                    java.lang.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). Note that you cannot uniquely specify a method to mock using this method if there are several methods with the same name in 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");
         
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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).
        Returns:
        A mock object of type .
      • createNicePartialMock

        public static <T> T createNicePartialMock​(java.lang.Class<T> type,
                                                  java.lang.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). Note that you cannot uniquely specify a method to mock using this method if there are several methods with the same name in 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.
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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).
        Returns:
        A mock object of type .
      • createNicePartialMock

        public static <T> T createNicePartialMock​(java.lang.Class<T> type,
                                                  java.lang.Class<? super T> where,
                                                  java.lang.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). Note that you cannot uniquely specify a method to mock using this method if there are several methods with the same name in 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");
         
        Type Parameters:
        T - The type of the mock.
        Parameters:
        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).
        Returns:
        A mock object of type .
      • createPartialMockAndInvokeDefaultConstructor

        public static <T> T createPartialMockAndInvokeDefaultConstructor​(java.lang.Class<T> type,
                                                                         java.lang.String... methodNames)
                                                                  throws java.lang.Exception
        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). The mock object created will support mocking of final methods and invokes the default constructor (even if it's private).
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        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).
        Returns:
        the mock object.
        Throws:
        java.lang.Exception
      • createNicePartialMockAndInvokeDefaultConstructor

        public static <T> T createNicePartialMockAndInvokeDefaultConstructor​(java.lang.Class<T> type,
                                                                             java.lang.String... methodNames)
                                                                      throws java.lang.Exception
        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). The mock object created will support mocking of final methods and invokes the default constructor (even if it's private).
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        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).
        Returns:
        the mock object.
        Throws:
        java.lang.Exception
      • createStrictPartialMockAndInvokeDefaultConstructor

        public static <T> T createStrictPartialMockAndInvokeDefaultConstructor​(java.lang.Class<T> type,
                                                                               java.lang.String... methodNames)
                                                                        throws java.lang.Exception
        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). The mock object created will support mocking of final methods and invokes the default constructor (even if it's private).
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        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).
        Returns:
        the mock object.
        Throws:
        java.lang.Exception
      • createPartialMock

        public static <T> T createPartialMock​(java.lang.Class<T> type,
                                              java.lang.String[] methodNames,
                                              java.lang.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). The mock object created will support mocking of final and native methods and invokes a specific constructor based on the supplied argument values.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        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).
        constructorArguments - The constructor arguments that will be used to invoke a certain constructor. (optional)
        Returns:
        the mock object.
      • createStrictPartialMock

        public static <T> T createStrictPartialMock​(java.lang.Class<T> type,
                                                    java.lang.String[] methodNames,
                                                    java.lang.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). The mock object created will support mocking of final and native methods and invokes a specific constructor based on the supplied argument values.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        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).
        constructorArguments - The constructor arguments that will be used to invoke a certain constructor. (optional)
        Returns:
        the mock object.
      • createNicePartialMock

        public static <T> T createNicePartialMock​(java.lang.Class<T> type,
                                                  java.lang.String[] methodNames,
                                                  java.lang.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). The mock object created will support mocking of final and native methods and invokes a specific constructor based on the supplied argument values.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        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).
        constructorArguments - The constructor arguments that will be used to invoke a certain constructor. (optional)
        Returns:
        the mock object.
      • createPartialMock

        public static <T> T createPartialMock​(java.lang.Class<T> type,
                                              java.lang.String methodName,
                                              java.lang.Class<?>[] methodParameterTypes,
                                              java.lang.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). Use this to handle overloaded methods. The mock object created will support mocking of final and native methods and invokes a specific constructor based on the supplied argument values.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        methodName - 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)
        Returns:
        the mock object.
      • createStrictPartialMock

        public static <T> T createStrictPartialMock​(java.lang.Class<T> type,
                                                    java.lang.String methodName,
                                                    java.lang.Class<?>[] methodParameterTypes,
                                                    java.lang.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). Use this to handle overloaded methods. The mock object created will support mocking of final and native methods and invokes a specific constructor based on the supplied argument values.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        methodName - 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)
        Returns:
        the mock object.
      • createNicePartialMock

        public static <T> T createNicePartialMock​(java.lang.Class<T> type,
                                                  java.lang.String methodName,
                                                  java.lang.Class<?>[] methodParameterTypes,
                                                  java.lang.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). Use this to handle overloaded methods. The mock object created will support mocking of final and native methods and invokes a specific constructor based on the supplied argument values.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        methodName - 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)
        Returns:
        the mock object.
      • createPartialMock

        public static <T> T createPartialMock​(java.lang.Class<T> type,
                                              java.lang.String methodName,
                                              java.lang.Class<?>[] methodParameterTypes,
                                              java.lang.Object[] constructorArguments,
                                              java.lang.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). Use this to handle overloaded methods and overloaded constructors. The mock object created will support mocking of final and native methods and invokes a specific constructor based on the supplied argument values.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        methodName - 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.
        Returns:
        the mock object.
      • createStrictPartialMock

        public static <T> T createStrictPartialMock​(java.lang.Class<T> type,
                                                    java.lang.String methodName,
                                                    java.lang.Class<?>[] methodParameterTypes,
                                                    java.lang.Object[] constructorArguments,
                                                    java.lang.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). Use this to handle overloaded methods and overloaded constructors. The mock object created will support mocking of final and native methods and invokes a specific constructor based on the supplied argument values.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        methodName - 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.
        Returns:
        the mock object.
      • createNicePartialMock

        public static <T> T createNicePartialMock​(java.lang.Class<T> type,
                                                  java.lang.String methodName,
                                                  java.lang.Class<?>[] methodParameterTypes,
                                                  java.lang.Object[] constructorArguments,
                                                  java.lang.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). Use this to handle overloaded methods and overloaded constructors. The mock object created will support mocking of final and native methods and invokes a specific constructor based on the supplied argument values.
        Type Parameters:
        T - the type of the mock object
        Parameters:
        type - the type of the mock object
        methodName - 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.
        Returns:
        the mock object.
      • expectPrivate

        public static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Class<?> clazz,
                                                                            java.lang.reflect.Method method,
                                                                            java.lang.Object... arguments)
                                                                     throws java.lang.Exception
        Used to specify expectations on private static methods. If possible use variant with only method name.
        Throws:
        java.lang.Exception
      • expectPrivate

        public static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance,
                                                                            java.lang.reflect.Method method,
                                                                            java.lang.Object... arguments)
                                                                     throws java.lang.Exception
        Used to specify expectations on private methods. If possible use variant with only method name.
        Throws:
        java.lang.Exception
      • expectPrivate

        public static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance,
                                                                            java.lang.String methodName,
                                                                            java.lang.Class<?>[] parameterTypes,
                                                                            java.lang.Object... arguments)
                                                                     throws java.lang.Exception
        Used to specify expectations on private methods. Use this method to handle overloaded methods.
        Throws:
        java.lang.Exception
      • expectPrivate

        public static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance,
                                                                            java.lang.String methodName,
                                                                            java.lang.Object... arguments)
                                                                     throws java.lang.Exception
        Used to specify expectations on methods using the method name. Works on for example private or package private methods.
        Throws:
        java.lang.Exception
      • expectPrivate

        public static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance,
                                                                            java.lang.Object... arguments)
                                                                     throws java.lang.Exception
        Used to specify expectations on methods without specifying a method name. Works on for example private or package private methods. PowerMock tries to find a unique method to expect based on the argument parameters. If PowerMock is unable to locate a unique method you need to revert to using expectPrivate(Object, String, Object...).
        Throws:
        java.lang.Exception
      • expectPrivate

        public static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance,
                                                                            java.lang.String methodName,
                                                                            java.lang.Class<?> where,
                                                                            java.lang.Class<?>[] parameterTypes,
                                                                            java.lang.Object... arguments)
                                                                     throws java.lang.Exception
        Used to specify expectations on methods using the method name at a specific place in the class hierarchy (specified by the where parameter). Works on for example private or package private methods.

        Use this for overloaded methods.

        Throws:
        java.lang.Exception
      • expectPrivate

        public static <T> org.easymock.IExpectationSetters<T> expectPrivate​(java.lang.Object instance,
                                                                            java.lang.String methodName,
                                                                            java.lang.Class<?> where,
                                                                            java.lang.Object... arguments)
                                                                     throws java.lang.Exception
        Used to specify expectations on methods using the method name at a specific place in the class hierarchy (specified by the where parameter). Works on for example private or package private methods.
        Throws:
        java.lang.Exception
      • expectLastCall

        public static org.easymock.IExpectationSetters<java.lang.Object> expectLastCall()
        This method just delegates to EasyMock class extensions EasyMock.expectLastCall() method.
        Returns:
        The expectation setter.
        See Also:
        EasyMock.expectLastCall()
      • niceReplayAndVerify

        public static void niceReplayAndVerify()
        Sometimes it is useful to allow replay and verify on non-mocks. For example when using partial mocking in some tests and no mocking in other test-methods, but using the same setUp and tearDown.
      • isEasyMocked

        private static boolean isEasyMocked​(java.lang.Object mock)
        Test if a object is a mock created by EasyMock or not.
      • replayAll

        public static void replayAll​(java.lang.Object... additionalMocks)
        Replay all classes and mock objects known by PowerMock. This includes all classes that are prepared for test using the 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.

        Parameters:
        additionalMocks - Mocks not created by the PowerMock API. These are typically those mock objects you have created using pure EasyMock or EasyMock class extensions.
      • resetAll

        public static void resetAll​(java.lang.Object... additionalMocks)
        Reset all classes and mock objects known by PowerMock. This includes all classes that are prepared for test using the 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.

        Parameters:
        additionalMocks - Mocks not created by the PowerMock API. These are typically those mock objects you have created using pure EasyMock or EasyMock class extensions.
      • reset

        public static void reset​(java.lang.Class<?>... classMocks)
        Reset a list of class mocks.
      • reset

        public static void reset​(java.lang.Object... mocks)
        Reset a list of mock objects or classes.
      • replay

        public static void replay​(java.lang.Object... mocks)
        Switches the mocks or classes to replay mode. Note that you must use this method when using PowerMock!
        Parameters:
        mocks - mock objects or classes loaded by PowerMock.
        Throws:
        java.lang.RuntimeException - If something unexpected goes wrong.
      • verify

        public static void verify​(java.lang.Object... objects)
        Switches the mocks or classes to verify mode. Note that you must use this method when using PowerMock!
        Parameters:
        objects - mock objects or classes loaded by PowerMock.
      • createMockAndExpectNew

        public static <T> T createMockAndExpectNew​(java.lang.Class<T> type,
                                                   java.lang.Object... arguments)
                                            throws java.lang.Exception
        Convenience method for createMock followed by expectNew.
        Parameters:
        type - The class that should be mocked.
        arguments - The constructor arguments.
        Returns:
        A mock object of the same type as the mock.
        Throws:
        java.lang.Exception
      • createMockAndExpectNew

        public static <T> T createMockAndExpectNew​(java.lang.Class<T> type,
                                                   java.lang.Class<?>[] parameterTypes,
                                                   java.lang.Object... arguments)
                                            throws java.lang.Exception
        Convenience method for createMock followed by expectNew when PowerMock cannot determine which constructor to use automatically. This happens when you have one constructor taking a primitive type and another one taking the wrapper type of the primitive. For example int and Integer.
        Parameters:
        type - The class that should be mocked.
        parameterTypes - The constructor parameter types.
        arguments - The constructor arguments.
        Returns:
        A mock object of the same type as the mock.
        Throws:
        java.lang.Exception
      • createNiceMockAndExpectNew

        public static <T> T createNiceMockAndExpectNew​(java.lang.Class<T> type,
                                                       java.lang.Object... arguments)
                                                throws java.lang.Exception
        Convenience method for createNiceMock followed by expectNew.
        Parameters:
        type - The class that should be mocked.
        arguments - The constructor arguments.
        Returns:
        A mock object of the same type as the mock.
        Throws:
        java.lang.Exception
      • createNiceMockAndExpectNew

        public static <T> T createNiceMockAndExpectNew​(java.lang.Class<T> type,
                                                       java.lang.Class<?>[] parameterTypes,
                                                       java.lang.Object... arguments)
                                                throws java.lang.Exception
        Convenience method for createNiceMock followed by expectNew when PowerMock cannot determine which constructor to use automatically. This happens when you have one constructor taking a primitive type and another one taking the wrapper type of the primitive. For example int and Integer.
        Parameters:
        type - The class that should be mocked.
        parameterTypes - The constructor parameter types.
        arguments - The constructor arguments.
        Returns:
        A mock object of the same type as the mock.
        Throws:
        java.lang.Exception
      • createStrictMockAndExpectNew

        public static <T> T createStrictMockAndExpectNew​(java.lang.Class<T> type,
                                                         java.lang.Object... arguments)
                                                  throws java.lang.Exception
        Convenience method for createStrictMock followed by expectNew.
        Parameters:
        type - The class that should be mocked.
        arguments - The constructor arguments.
        Returns:
        A mock object of the same type as the mock.
        Throws:
        java.lang.Exception
      • createStrictMockAndExpectNew

        public static <T> T createStrictMockAndExpectNew​(java.lang.Class<T> type,
                                                         java.lang.Class<?>[] parameterTypes,
                                                         java.lang.Object... arguments)
                                                  throws java.lang.Exception
        Convenience method for createStrictMock followed by expectNew when PowerMock cannot determine which constructor to use automatically. This happens when you have one constructor taking a primitive type and another one taking the wrapper type of the primitive. For example int and Integer.
        Parameters:
        type - The class that should be mocked.
        parameterTypes - The constructor parameter types.
        arguments - The constructor arguments.
        Returns:
        A mock object of the same type as the mock.
        Throws:
        java.lang.Exception
      • expectNew

        public static <T> org.easymock.IExpectationSetters<T> expectNew​(java.lang.Class<T> type,
                                                                        java.lang.Class<?>[] parameterTypes,
                                                                        java.lang.Object... arguments)
                                                                 throws java.lang.Exception
        Allows specifying expectations on new invocations. For example you might want to throw an exception or return a mock. Note that you must replay the class when using this method since this behavior is part of the class mock.

        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.

        Throws:
        java.lang.Exception
      • doExpectNew

        private static <T> org.easymock.IExpectationSetters<T> doExpectNew​(java.lang.Class<T> type,
                                                                           MockStrategy mockStrategy,
                                                                           java.lang.Class<?>[] parameterTypes,
                                                                           java.lang.Object... arguments)
                                                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • expectNew

        public static <T> org.easymock.IExpectationSetters<T> expectNew​(java.lang.Class<T> type,
                                                                        java.lang.Object... arguments)
                                                                 throws java.lang.Exception
        Allows specifying expectations on new invocations. For example you might want to throw an exception or return a mock. Note that you must replay the class when using this method since this behavior is part of the class mock.
        Throws:
        java.lang.Exception
      • expectNew

        public static <T> org.easymock.IExpectationSetters<T> expectNew​(java.lang.String fullyQualifiedName,
                                                                        java.lang.Object... arguments)
                                                                 throws java.lang.Exception
        Allows specifying expectations on new invocations for private member (inner) classes, local or anonymous classes. For example you might want to throw an exception or return a mock. Note that you must replay the class when using this method since this behavior is part of the class mock.
        Parameters:
        fullyQualifiedName - The fully-qualified name of the inner/local/anonymous type to expect.
        arguments - Optional number of arguments.
        Throws:
        java.lang.Exception
      • expectStrictNew

        public static <T> org.easymock.IExpectationSetters<T> expectStrictNew​(java.lang.Class<T> type,
                                                                              java.lang.Object... arguments)
                                                                       throws java.lang.Exception
        Allows specifying expectations on new invocations. For example you might want to throw an exception or return a mock.

        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.

        Throws:
        java.lang.Exception
      • expectStrictNew

        public static <T> org.easymock.IExpectationSetters<T> expectStrictNew​(java.lang.Class<T> type,
                                                                              java.lang.Class<?>[] parameterTypes,
                                                                              java.lang.Object... arguments)
                                                                       throws java.lang.Exception
        Allows specifying expectations on new invocations. For example you might want to throw an exception or return a mock. Note that you must replay the class when using this method since this behavior is part of the class mock.

        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.

        Throws:
        java.lang.Exception
      • expectNiceNew

        public static <T> org.easymock.IExpectationSetters<T> expectNiceNew​(java.lang.Class<T> type,
                                                                            java.lang.Object... arguments)
                                                                     throws java.lang.Exception
        Allows specifying expectations on new invocations. For example you might want to throw an exception or return a mock.

        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.

        Throws:
        java.lang.Exception
      • expectNiceNew

        public static <T> org.easymock.IExpectationSetters<T> expectNiceNew​(java.lang.Class<T> type,
                                                                            java.lang.Class<?>[] parameterTypes,
                                                                            java.lang.Object... arguments)
                                                                     throws java.lang.Exception
        Allows specifying expectations on new invocations. For example you might want to throw an exception or return a mock. Note that you must replay the class when using this method since this behavior is part of the class mock.

        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.

        Throws:
        java.lang.Exception
      • suppressConstructor

        @Deprecated
        public static void suppressConstructor​(java.lang.reflect.Constructor<?>... constructors)
        Deprecated.
        Suppress constructor calls on specific constructors only.
      • suppressSpecificConstructor

        @Deprecated
        public static void suppressSpecificConstructor​(java.lang.Class<?> clazz,
                                                       java.lang.Class<?>... parameterTypes)
        Deprecated.
        This method can be used to suppress the code in a specific constructor.
        Parameters:
        clazz - The class where the constructor is located.
        parameterTypes - The parameter types of the constructor to suppress.
      • suppressConstructor

        @Deprecated
        public static void suppressConstructor​(java.lang.Class<?>... classes)
        Deprecated.
        Suppress all constructors in the given class and it's super classes.
        Parameters:
        classes - The classes whose constructors will be suppressed.
      • suppressConstructor

        @Deprecated
        public static void suppressConstructor​(java.lang.Class<?> clazz,
                                               boolean excludePrivateConstructors)
        Deprecated.
        Suppress all constructors in the given class.
        Parameters:
        clazz - The classes whose constructors will be suppressed.
        excludePrivateConstructors - optionally keep code in private constructors
      • suppressField

        @Deprecated
        public static void suppressField​(java.lang.reflect.Field... fields)
        Deprecated.
        Suppress specific fields. This works on both instance methods and static methods. Note that replay and verify are not needed as this is not part of a mock behavior.
      • suppressField

        @Deprecated
        public static void suppressField​(java.lang.Class<?>[] classes)
        Deprecated.
        Suppress all fields for these classes.
      • suppressField

        @Deprecated
        public static void suppressField​(java.lang.Class<?> clazz,
                                         java.lang.String... fieldNames)
        Deprecated.
        Suppress multiple methods for a class.
        Parameters:
        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.
      • suppressMethod

        @Deprecated
        public static void suppressMethod​(java.lang.reflect.Method... methods)
        Deprecated.
        Suppress specific method calls on all types containing this method. This works on both instance methods and static methods. Note that replay and verify are not needed as this is not part of a mock behavior.
      • suppressMethod

        @Deprecated
        public static void suppressMethod​(java.lang.Class<?> cls,
                                          java.lang.Class<?>... additionalClasses)
        Deprecated.
        Suppress all methods for these classes.
        Parameters:
        cls - The first class whose methods will be suppressed.
        additionalClasses - Additional classes whose methods will be suppressed.
      • suppressMethod

        @Deprecated
        public static void suppressMethod​(java.lang.Class<?>[] classes)
        Deprecated.
        Suppress all methods for these classes.
        Parameters:
        classes - Classes whose methods will be suppressed.
      • suppressMethod

        @Deprecated
        public static void suppressMethod​(java.lang.Class<?> clazz,
                                          java.lang.String methodName,
                                          java.lang.String... additionalMethodNames)
        Deprecated.
        Suppress multiple methods for a class.
        Parameters:
        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.
      • suppressMethod

        @Deprecated
        public static void suppressMethod​(java.lang.Class<?> clazz,
                                          java.lang.String[] methodNames)
        Deprecated.
        Suppress multiple methods for a class.
        Parameters:
        clazz - The class whose methods will be suppressed.
        methodNames - Methods to suppress in class clazz.
      • suppressMethod

        @Deprecated
        public static void suppressMethod​(java.lang.Class<?> clazz,
                                          boolean excludePrivateMethods)
        Deprecated.
        Suppress all methods for this class.
        Parameters:
        clazz - The class which methods will be suppressed.
        excludePrivateMethods - optionally not suppress private methods
      • suppressMethod

        @Deprecated
        public static void suppressMethod​(java.lang.Class<?> clazz,
                                          java.lang.String methodName,
                                          java.lang.Class<?>[] parameterTypes)
        Deprecated.
        Suppress a specific method call. Use this for overloaded methods.
      • doMock

        private static <T> T doMock​(java.lang.Class<T> type,
                                    boolean isStatic,
                                    MockStrategy mockStrategy,
                                    org.easymock.ConstructorArgs constructorArgs,
                                    java.lang.reflect.Method... methods)
      • createReplicaType

        private static <T> java.lang.Class<?> createReplicaType​(java.lang.Class<T> type,
                                                                boolean isStatic,
                                                                org.easymock.ConstructorArgs constructorArgs)
      • doCreateMock

        private static <T> T doCreateMock​(java.lang.Class<T> type,
                                          org.easymock.ConstructorArgs constructorArgs,
                                          org.easymock.IMocksControl control,
                                          java.lang.reflect.Method... methods)
      • toSet

        private static java.util.Set<java.lang.reflect.Method> toSet​(java.lang.reflect.Method[] methods)
      • mergeArgumentTypes

        private static java.lang.Class<?>[] mergeArgumentTypes​(java.lang.Class<?> firstArgumentType,
                                                               java.lang.Class<?>... additionalArgumentTypes)
      • doExpectPrivate

        private static <T> org.easymock.IExpectationSetters<T> doExpectPrivate​(java.lang.Object instance,
                                                                               java.lang.reflect.Method methodToExpect,
                                                                               java.lang.Object... arguments)
                                                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • replay

        private static void replay​(java.lang.Class<?>... types)
      • verifyClass

        private static void verifyClass​(java.lang.Class<?>... types)
        Note: doesn't clear PowerMock state.
      • isNiceReplayAndVerifyMode

        private static boolean isNiceReplayAndVerifyMode()