spock.mock.MockFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spock-core Show documentation
Show all versions of spock-core Show documentation
Spock is a testing and specification framework for Java and Groovy applications.
What makes it stand out from the crowd is its beautiful and highly expressive specification language.
Thanks to its JUnit runner, Spock is compatible with most IDEs, build tools, and continuous integration servers.
Spock is inspired from JUnit, jMock, RSpec, Groovy, Scala, Vulcans, and other fascinating life forms.
package spock.mock;
import org.spockframework.util.Beta;
import java.util.Map;
/**
* Base interface for Java based mocks see {@link MockingApi} or {@link DetachedMockFactory} for more examples.
*/
public interface MockFactory {
/**
* Creates a mock with the specified type.
*
* Example:
*
*
* def person = Mock(Person) // type is Person.class, name is "person"
*
*
* @param type the interface or class type of the mock
* @param the interface or class type of the mock
*
* @return a mock with the specified type
*/
T Mock(Class type);
/**
* Creates a mock with the specified options and type.
*
* Example:
*
*
* def person = Mock(Person, name: "myPerson") // type is Person.class, name is "myPerson"
*
*
* @param options optional options for creating the mock
* @param type the interface or class type of the mock
* @param the interface or class type of the mock
*
* @return a mock with the specified options and type
*/
@Beta
T Mock(Map options, Class type);
/**
* Creates a stub with the specified type.
*
* Example:
*
*
* def person = Stub(Person) // type is Person.class, name is "person"
*
*
* @param type the interface or class type of the stub
* @param the interface or class type of the stub
*
* @return a stub with the specified type
*/
@Beta
T Stub(Class type);
/**
* Creates a stub with the specified options and type.
*
* Example:
*
*
* def person = Stub(Person, name: "myPerson") // type is Person.class, name is "myPerson"
*
*
* @param options optional options for creating the stub
* @param type the interface or class type of the stub
* @param the interface or class type of the stub
*
* @return a stub with the specified options and type
*/
@Beta
T Stub(Map options, Class type);
/**
* Creates a spy with the specified type.
*
* Example:
*
*
* def person = Spy(Person) // type is Person.class, name is "person"
*
*
* @param type the class type of the spy
* @param the class type of the spy
*
* @return a spy with the specified type
*/
@Beta
T Spy(Class type);
/**
* Creates a spy wrapping a provided instance.
*
* Example:
*
*
* def person = Spy(new Person()) // type is Person.class, name is "person"
*
*
* @param obj the instance to spy
* @param the class type of the spy
*
* @return a spy with the specified type
*/
@Beta
T Spy(T obj);
/**
* Creates a spy with the specified options and type.
*
* Example:
*
*
* def person = Spy(Person, name: "myPerson") // type is Person.class, name is "myPerson"
*
*
* @param options optional options for creating the spy
* @param type the class type of the spy
* @param the class type of the spy
*
* @return a spy with the specified options and type
*/
@Beta
T Spy(Map options, Class type);
}