|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectse.mockachino.Mockachino
public class Mockachino
This is the main entry point of all your mocking needs.
All operations delegates to a singleton MockUtil
.
MockUtil
object directly.
Consider statically import these classes to reduce verbosity of tests:
import static se.mockachino.Mockachino.*; import static se.mockachino.matchers.Matchers.*; import static se.mockachino.Settings.*;See
MatchersBase
for available matchers
and
see Matchers
for useful matcher shortcuts.
See Settings
for how to mock classes with various settings.
Field Summary | |
---|---|
static MockPoint |
BIG_BANG
|
static MockPoint |
BIG_CRUNCH
|
static CallHandler |
DEEP_MOCK
|
static CallHandler |
DEFAULT_VALUES
|
static PrimitiveInvocationHandler |
PRIMITIVE_VALUES
|
Constructor Summary | |
---|---|
Mockachino()
|
Method Summary | ||
---|---|---|
static BetweenVerifyContext |
after(MockPoint start)
Verify that calls happened at or after a point in time. |
|
static BetweenVerifyContext |
before(MockPoint end)
Verify that calls happened at or before a point in time. |
|
static BetweenVerifyContext |
between(MockPoint start,
MockPoint end)
Verify that calls happened between (inclusive) two points in time. |
|
static boolean |
canMock(java.lang.Class clazz)
Checks if a class is mockable by Mockachino. |
|
static MockPoint |
getCurrentPoint()
Gets the current point on time on the call history. |
|
static
|
getData(T mock)
Get the metadata for mock. |
|
static
|
mock(
Creates a new mock with a default handler and default settings. |
|
static
|
mock(
Creates a new mock with specified settings. |
|
static
|
mock(java.lang.Class<T> clazz)
Creates a new mock with a default handler and default settings. |
|
static
|
mock(java.lang.Class<T> clazz,
MockSettings settings)
Creates a new mock with specified settings. |
|
static java.lang.Object |
mockType(java.lang.reflect.Type type,
MockSettings mockSettings)
|
|
static SimpleAlias |
newAlias()
|
|
static OrderingContext |
newOrdering()
Creates a new ordering context which is used to verify method calls in order. |
|
static ObserverAdder |
observeWith(CallHandler observer)
Adds an observer to a specific method call. |
|
static void |
setupMocks(java.lang.Object obj)
|
|
static
|
spy(T impl)
Creates a new mock with class impl.getClass() with the impl as a default handler. |
|
static
|
spy(T impl,
MockSettings settings)
Creates a new mock with class impl.getClass() with the impl as a default handler, and the specified settings. |
|
static Stubber |
stubAnswer(CallHandler answer)
Stubs a method call with a specific answer strategy. |
|
static Stubber |
stubReturn(java.lang.Object... returnValues)
|
|
static Stubber |
stubReturn(java.lang.Object returnValue)
Stubs a method call to return a specific value. |
|
static Stubber |
stubThrow(java.lang.Throwable e)
Stubs a method call to throw an exception. |
|
static VerifyRangeStart |
verifyAtLeast(int min)
Verifies that a method call is called at least a specific number of times. |
|
static VerifyRangeStart |
verifyAtMost(int max)
Verifies that a method call is called at most a specific number of times. |
|
static VerifyRangeStart |
verifyExactly(int count)
Verifies that a method call is called an exact number of times. |
|
static VerifyRangeStart |
verifyNever()
Verifies that a method call is never called. |
|
static VerifyRangeStart |
verifyOnce()
Verifies that a method call is only called exactly once. |
|
static VerifyRangeStart |
verifyRange(int min,
int max)
Verifies that a method call is called between min and max times, inclusive. |
|
static
|
when(T mockInvocation)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final PrimitiveInvocationHandler PRIMITIVE_VALUES
public static final CallHandler DEFAULT_VALUES
public static final CallHandler DEEP_MOCK
public static final MockPoint BIG_BANG
public static final MockPoint BIG_CRUNCH
Constructor Detail |
---|
public Mockachino()
Method Detail |
---|
public static <T> T mock(java.lang.Class<T> clazz)
clazz
- the interface or class to mock
public static <T> T mock(type)
type
- the type literal of the interface or class to mock
public static <T> T mock(java.lang.Class<T> clazz, MockSettings settings)
clazz
- the interface or class to mock
public static <T> T mock(type, MockSettings settings)
type
- the type literal of the interface or class to mock
public static <T> T spy(T impl)
impl
- the object to spy on
public static <T> T spy(T impl, MockSettings settings)
impl
- the object to spy on
public static OrderingContext newOrdering()
OrderingContext context = Mockachino.newOrdering(); context.verifyAtLeast(3).on(mock).method();
public static VerifyRangeStart verifyRange(int min, int max)
Mockachino.verifyRange(1, 2).on(mock).method();
min
- minimum amount of matching method callsmax
- maximum amount of matching method calls
public static VerifyRangeStart verifyExactly(int count)
Mockachino.verifyExactly(3).on(mock).method();
count
- number of times the method should be called
public static VerifyRangeStart verifyNever()
Mockachino.verifyNever().on(mock).method();
public static VerifyRangeStart verifyOnce()
Mockachino.verifyOnce().on(mock).method();
public static VerifyRangeStart verifyAtLeast(int min)
Mockachino.verifyAtLeast(3).on(mock).method();
min
- number of times the method should be called
public static VerifyRangeStart verifyAtMost(int max)
Mockachino.verifyAtMost(3).on(mock).method();
max
- number of times the method should be called
public static Stubber stubThrow(java.lang.Throwable e)
Mockachino.stubThrow(myException).on(mock).method();
e
- the exception to throw
public static Stubber stubReturn(java.lang.Object returnValue)
Mockachino.stubReturn(value).on(mock).method();Note that the type of the value must match the return type of the method call. This is checked at runtime and will throw a UsageError if they don't match.
returnValue
- the returnValue to return when the method is called.
public static Stubber stubReturn(java.lang.Object... returnValues)
public static Stubber stubAnswer(CallHandler answer)
Mockachino.stubAnswer(answer).on(mock).method();All matching method calls will invoke the getValue()-method on the answer-object.
answer
- the answer to use
public static ObserverAdder observeWith(CallHandler observer)
Mockachino.observeWith(observer).on(mock).method();
observer
- the observer to use
public static MockPoint getCurrentPoint()
public static BetweenVerifyContext between(MockPoint start, MockPoint end)
Mockachino.between(start, end).verifyAtLeast(1).on(mock).method();
start
- end
-
public static BetweenVerifyContext after(MockPoint start)
Mockachino.after(start).verifyAtLeast(1).on(mock).method();
start
-
public static BetweenVerifyContext before(MockPoint end)
Mockachino.before(end).verifyAtLeast(1).on(mock).method();
end
-
public static boolean canMock(java.lang.Class clazz)
clazz
-
public static void setupMocks(java.lang.Object obj)
public static <T> MockData<T> getData(T mock)
mock
- the mock object
public static SimpleAlias newAlias()
public static <T>when(T mockInvocation)
public static java.lang.Object mockType(java.lang.reflect.Type type, MockSettings mockSettings)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |