|
||||||||||
PREV NEXT | FRAMES NO FRAMES |
Matchers
for general info about matchers.Answers
WARNING Those answers no longer are used by the framework!!! Please use Answers
See Mockito
for more information.
Matchers.anyCollection()
.
Matchers.anyList()
.
Matchers.anyMap()
.
Matchers.anySet()
.
ArgumentCaptor.forClass(Class)
to create captors
This is required to avoid NullPointerExceptions when autoUnboxing primitive types. See issue 99.
Example:
ArgumentCaptor<Person> argument = ArgumentCaptor.forClass(Person.class); verify(mock).doSomething(argument.capture()); assertEquals("John", argument.getValue().getName());
VerificationWithTimeout
VerificationWithTimeout
VerificationWithTimeout
To avoid compilation erros upon upgrade the method is deprecated and it throws a "friendly reminder" exception.
In future release we will remove timeout(x).atMost(y) from the API.
Do you want to find out more? See issue 235
OngoingStubbing
Stubber
Mockito.mock(Class, Answer)
ArgumentCaptor
creation on fields.BlockJUnit4ClassRunner
.AnnotationEngine.process(Class, Object)
method instead that is more robust
Creates mock, ArgumentCaptor or wraps field instance in spy object. Only if of correct annotation type.
Mock
or @Captor
.MockitoAnnotations
Answer
.
Mockito.doAnswer(Answer)
style:
Mockito.doNothing()
style:
Mockito.when(Object)
.
Mockito.doReturn(Object)
style.
Mockito.doThrow(Throwable)
style:
Mockito.doThrow(Class extends Throwable>)
style:
OngoingInjecter
that do nothing if a candidate couldn't be found
an OngoingInjecter
that will try to inject the candidate trying first the property setter then if not possible try the field access
OngoingStubbing.getMock()
IMockitoConfiguration.getDefaultAnswer()
Steps:
1. Leave the implementation of getReturnValues() method empty - it's not going to be used anyway.
2. Implement getDefaultAnswer() instead.
In rare cases your code might not compile with recent deprecation & changes. Very sorry for inconvenience but it had to be done in order to keep framework consistent.
See javadoc ReturnValues
for info why this method was deprecated
Allows configuring the default return values of unstubbed invocations
See javadoc for IMockitoConfiguration
Stubber.when(Object)
Mockito.when(Object)
Mock
, @Spy
, @Captor
, @InjectMocks
MockitoAnnotations
See Mockito.mock(Class, Answer)
Why it is deprecated? ReturnValues is being replaced by Answer for better consistency & interoperability of the framework. Answer interface has been in Mockito for a while and it has the same responsibility as ReturnValues. There's no point in mainting exactly the same interfaces.
Creates mock with a specified strategy for its return values. It's quite advanced feature and typically you don't need it to write decent tests. However it can be helpful when working with legacy systems.
Obviously return values are used only when you don't stub the method call.
Foo mock = mock(Foo.class, Mockito.RETURNS_SMART_NULLS); Foo mockTwo = mock(Foo.class, new YourOwnReturnValues());
See examples in javadoc for Mockito
class
Mock
,
so that explicit usage of MockitoAnnotations.initMocks(Object)
is not necessary.Mockito.times(int)
VerificationWithTimeout
VerificationWithTimeout.times(int)
MethodInvocationReport
with a return value.
MethodInvocationReport
with a return value.
VerificationWithTimeout
Mockito.mock(Class, Answer)
Mockito.mock(Class, Answer)
Mockito.mock(Class, Answer)
Mockito.mock(Class, Answer)
Answer
interface
In rare cases your code might not compile with recent deprecation & changes. Very sorry for inconvenience but it had to be done in order to keep framework consistent.
Why it is deprecated? ReturnValues is being replaced by Answer for better consistency & interoperability of the framework. Answer interface has been in Mockito for a while and it has the same responsibility as ReturnValues. There's no point in mainting exactly the same interfaces.
Configures return values for an unstubbed invocation
Can be used in Mockito.mock(Class, ReturnValues)
BeanPropertySetter
Mockito.doThrow(Throwable)
method for stubbing voids
VerificationWithTimeout
VerificationWithTimeout
VerificationWithTimeout
Answer
VerificationMode
that allows combining existing verification modes with 'timeout'.VerificationWithTimeout
OngoingStubbing.then(Answer)
OngoingStubbing.thenAnswer(Answer)
Stubber.doAnswer(Answer)
Mockito.doAnswer(Answer)
OngoingStubbing.thenCallRealMethod()
Mockito.doCallRealMethod()
Mockito.doNothing()
Stubber.doNothing()
OngoingStubbing.thenReturn(Object)
OngoingStubbing.thenReturn(Object, Object[])
Stubber.doReturn(Object)
Mockito.doReturn(Object)
OngoingStubbing.thenThrow(Throwable...)
OngoingStubbing.thenThrow(Class[])
Stubber.doThrow(Throwable)
Stubber.doThrow(Class)
Mockito.doThrow(Throwable)
Mockito.doThrow(Throwable)
|
||||||||||
PREV NEXT | FRAMES NO FRAMES |