All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.powermock.api.mockito.expectation.PowerMockitoStubber Maven / Gradle / Ivy

/*
 *   Copyright 2016 the original author or authors.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */
package org.powermock.api.mockito.expectation;

import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.mockito.stubbing.Stubber;

import java.lang.reflect.Method;

/**
 * Setup stubbing for private or void methods in final class, final void
 * methods, or static (final) methods.
 */
public interface PowerMockitoStubber extends Stubber {
    
    /**
     * Allows to choose a static method when stubbing in
     * doThrow()|doAnswer()|doNothing()|doReturn() style
     * 

* Example: *

*
     * doThrow(new RuntimeException()).when(StaticList.class);
     * StaticList.clear();
     *
     * //following throws RuntimeException:
     * StaticList.clear();
     * 
*

* Read more about those methods: *

*

* {@link Mockito#doThrow(Class)} *

*

* {@link Mockito#doAnswer(Answer)} *

*

* {@link Mockito#doNothing()} *

*

* {@link Mockito#doReturn(Object)} *

* * @param classMock the mock class * @see Mockito */ void when(Class classMock); /** * Allows to mock a private instance method when stubbing in * doThrow()|doAnswer()|doNothing()|doReturn() style. *

* Example: *

     * doThrow(new RuntimeException()).when(instance, method("myMethod")).withNoArguments();
     * 
*

*

* Read more about those methods: *

*

* {@link Mockito#doThrow(Class)} *

*

* {@link Mockito#doAnswer(Answer)} *

*

* {@link Mockito#doNothing()} *

*

* {@link Mockito#doReturn(Object)} *

* * @param mock the method * @param method private method to be mocked * @see Mockito */ PrivatelyExpectedArguments when(T mock, Method method) throws Exception; /** * Allows to mock a private instance method based on the parameters when * stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style. *

* Example: *

*

*

     * doThrow(new RuntimeException()).when(instance, parameter1, parameter2);
     * 
*

*

* Read more about those methods: *

*

* {@link Mockito#doThrow(Throwable...)} *

*

* {@link Mockito#doAnswer(Answer)} *

*

* {@link Mockito#doNothing()} *

*

* {@link Mockito#doReturn(Object)} *

* * @param mock the Mock * @param arguments array of arguments is used to find suitable method to be mocked. * @see Mockito */ void when(T mock, Object... arguments) throws Exception; /** * Allows to mock a private instance method based on method name and * parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() * style. *

* Example: *

*
     * doThrow(new RuntimeException()).when(instance, "methodName", parameter1, parameter2);
     * 
*

*

* Read more about those methods: *

*

* {@link Mockito#doThrow(Throwable...)} *

*

* {@link Mockito#doAnswer(Answer)} *

*

* {@link Mockito#doNothing()} *

*

* {@link Mockito#doReturn(Object)} *

* * @param mock the Mock * @param methodToExpect name of method which have to mocked * @param arguments array of arguments of methodToExpect * @see Mockito */ void when(T mock, String methodToExpect, Object... arguments) throws Exception; /** * Allows to mock a static private method when stubbing in * doThrow()|doAnswer()|doNothing()|doReturn() style. *

* Example: *

     * doThrow(new RuntimeException()).when(MyClass.class, method("myMethod")).withNoArguments();
     * 
*

*

* Read more about those methods: *

*

* {@link Mockito#doThrow(Throwable...)} *

*

* {@link Mockito#doAnswer(Answer)} *

*

* {@link Mockito#doNothing()} *

*

* {@link Mockito#doReturn(Object)} *

* * @param classMock class owner of private static method * @param method private static method to be mocked * @see Mockito */ PrivatelyExpectedArguments when(Class classMock, Method method) throws Exception; /** * Allows to mock a static private method based on the parameters when * stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style. *

* Example: *

     * doThrow(new RuntimeException()).when(MyClass.class, parameter1, parameter2);
     * 
*

*

* Read more about those methods: *

*

* {@link Mockito#doThrow(Throwable...)} *

*

* {@link Mockito#doAnswer(Answer)} *

*

* {@link Mockito#doNothing()} *

*

* {@link Mockito#doReturn(Object)} *

* * @param classMock class owner of private static method * @param arguments array of arguments is used to find suitable method to be mocked. * @see Mockito */ void when(Class classMock, Object... arguments) throws Exception; /** * Allows to mock a static private method based on method name and * parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() * style. *

* Example: *

     * doThrow(new RuntimeException()).when(MyClass.class, "methodName", parameter1, parameter2);
     * 
*

*

* Read more about those methods: *

*

* {@link Mockito#doThrow(Throwable...)} *

*

* {@link Mockito#doAnswer(Answer)} *

*

* {@link Mockito#doNothing()} *

*

* {@link Mockito#doReturn(Object)} *

* * @param classMock the class owner of static private method * @param methodToExpect name of method which have to mocked * @param arguments array of arguments of methodToExpect * @see Mockito */ void when(Class classMock, String methodToExpect, Object... arguments) throws Exception; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy