Package org.powermock.core.spi

Examples of org.powermock.core.spi.MethodInvocationControl


    if (!shouldMockMethod(methodName, sig)) {
      return PROCEED;
    }
    Object returnValue = null;

    MethodInvocationControl methodInvocationControl = null;
    Class<?> objectType = null;

    if (object instanceof Class<?>) {
      objectType = (Class<?>) object;
      methodInvocationControl = MockRepository.getStaticMethodInvocationControl(objectType);
    } else {
      final Class<? extends Object> type = object.getClass();
      objectType = WhiteboxImpl.getUnmockedType(type);
      methodInvocationControl = MockRepository.getInstanceMethodInvocationControl(object);
    }

    /*
     * if invocationControl is null or the method is not mocked, invoke
     * original method or suppress the method code otherwise invoke the
     * invocation handler.
     */
    Method method = null;
    try {
      method = WhiteboxImpl.getBestMethodCandidate(objectType, methodName, sig, true);
    } catch (MethodNotFoundException e) {
      /*
       * Dirty hack to get around issue 110
       * (http://code.google.com/p/powermock/issues/detail?id=110). Review
       * this! What we do here is to try to find a reflective method on
       * class. This has begun to fail since version 1.2 when we supported
       * mocking static methods in system classes.
       */
      try {
        method = WhiteboxImpl.getMethod(Class.class, methodName, sig);
      } catch (MethodNotFoundException e2) {
        throw e;
      }
    }
    if (methodInvocationControl != null && methodInvocationControl.isMocked(method) && shouldMockThisCall()) {
      returnValue = methodInvocationControl.invoke(object, method, args);
      if (returnValue == SUPPRESS) {
        returnValue = TypeUtils.getDefaultValue(returnTypeAsString);
      }
    } else if (MockRepository.hasMethodProxy(method)) {
      /*
 
View Full Code Here


    /**
     * Reset a list of class mocks.
     */
    public static synchronized void reset(Class<?>... classMocks) {
        for (Class<?> type : classMocks) {
            final MethodInvocationControl invocationHandler = MockRepository.getStaticMethodInvocationControl(type);
            if (invocationHandler != null) {
                invocationHandler.reset();
            }
            NewInvocationControl<?> newInvocationControl = MockRepository.getNewInstanceControl(type);
            if (newInvocationControl != null) {
                try {
                    newInvocationControl.reset();
View Full Code Here

        try {
            for (Object mock : mocks) {
                if (mock instanceof Class<?>) {
                    reset((Class<?>) mock);
                } else {
                    MethodInvocationControl invocationControl = MockRepository.getInstanceMethodInvocationControl(mock);
                    if (invocationControl != null) {
                        invocationControl.reset();
                    } else {
                        if (isNiceReplayAndVerifyMode() && !isEasyMocked(mock)) {
                            // ignore non-mock
                        } else {
                            /*
 
View Full Code Here

        try {
            for (Object mock : mocks) {
                if (mock instanceof Class<?>) {
                    replay((Class<?>) mock);
                } else {
                    MethodInvocationControl invocationControl = MockRepository.getInstanceMethodInvocationControl(mock);
                    if (invocationControl != null) {
                        invocationControl.replay();
                    } else {
                        if (isNiceReplayAndVerifyMode() && !isEasyMocked(mock)) {
                            // ignore non-mock
                        } else {
                            /*
 
View Full Code Here

    public static synchronized void verify(Object... objects) {
        for (Object mock : objects) {
            if (mock instanceof Class<?>) {
                verifyClass((Class<?>) mock);
            } else {
                MethodInvocationControl invocationControl = MockRepository.getInstanceMethodInvocationControl(mock);
                if (invocationControl != null) {
                    invocationControl.verify();
                } else {
                    if (isNiceReplayAndVerifyMode() && !isEasyMocked(mock)) {
                        // ignore non-mock
                    } else {
                        /*
 
View Full Code Here

        return (IExpectationSetters<T>) org.easymock.EasyMock.expectLastCall();
    }

    private static synchronized void replay(Class<?>... types) {
        for (Class<?> type : types) {
            final MethodInvocationControl invocationHandler = MockRepository.getStaticMethodInvocationControl(type);
            if (invocationHandler != null) {
                invocationHandler.replay();
            }

            NewInvocationControl<?> newInvocationControl = MockRepository.getNewInstanceControl(type);
            if (newInvocationControl != null) {
                newInvocationControl.replay();
View Full Code Here

    /**
     * Note: doesn't clear PowerMock state.
     */
    private static synchronized void verifyClass(Class<?>... types) {
        for (Class<?> type : types) {
            final MethodInvocationControl invocationHandler = MockRepository.getStaticMethodInvocationControl(type);
            if (invocationHandler != null) {
                invocationHandler.verify();
            }
            NewInvocationControl<?> newInvocationControl = MockRepository.getNewInstanceControl(type);
            if (newInvocationControl != null) {
                try {
                    newInvocationControl.verify();
View Full Code Here

        if (!shouldMockMethod(methodName, sig)) {
            return PROCEED;
        }
        Object returnValue = null;

        MethodInvocationControl methodInvocationControl;
        Class<?> objectType;

        if (object instanceof Class<?>) {
            objectType = (Class<?>) object;
            methodInvocationControl = MockRepository.getStaticMethodInvocationControl(objectType);
        } else {
            final Class<?> type = object.getClass();
            objectType = WhiteboxImpl.getUnmockedType(type);
            methodInvocationControl = MockRepository.getInstanceMethodInvocationControl(object);
        }

    /*
         * if invocationControl is null or the method is not mocked, invoke
     * original method or suppress the method code otherwise invoke the
     * invocation handler.
     */
        Method method;
        try {
            method = WhiteboxImpl.getBestMethodCandidate(objectType, methodName, sig, true);
        } catch (MethodNotFoundException e) {
      /*
       * Dirty hack to get around issue 110
       * (http://code.google.com/p/powermock/issues/detail?id=110). Review
       * this! What we do here is to try to find a reflective method on
       * class. This has begun to fail since version 1.2 when we supported
       * mocking static methods in system classes.
       */
            try {
                method = WhiteboxImpl.getMethod(Class.class, methodName, sig);
            } catch (MethodNotFoundException e2) {
                throw e;
            }
        }

        // Fix for Issue http://code.google.com/p/powermock/issues/detail?id=88
        // For some reason the method call to equals() on final methods is
        // intercepted and during the further processing in Mockito the same
        // equals() method is called on the same instance. A StackOverflowError
        // is the result. The following fix changes this by checking if the
        // method to be called is a final equals() method. In that case the
        // original method is called by returning PROCEED.
        if (    // The following describes the equals method.
                method.getName().equals("equals")
                        && method.getParameterTypes().length == 1
                        && method.getParameterTypes()[0] == Object.class
                        && Modifier.isFinal(method.getModifiers())) {
            returnValue = PROCEED;
        } else {

            if (methodInvocationControl != null && methodInvocationControl.isMocked(method) && shouldMockThisCall()) {
                returnValue = methodInvocationControl.invoke(object, method, args);
                if (returnValue == SUPPRESS) {
                    returnValue = TypeUtils.getDefaultValue(returnTypeAsString);
                }
            } else if (MockRepository.hasMethodProxy(method)) {
                /*
 
View Full Code Here

TOP

Related Classes of org.powermock.core.spi.MethodInvocationControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.