|
||||||||||
| 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.
null.
boolean, Boolean or null.
byte, Byte or null.
char, Character or null.
Collection or null.
Matchers.anyCollection().
double, Double or null.
float, Float or null.
null.
List or null.
Matchers.anyList().
long, Long or null.
Map or null.
Matchers.anyMap().
Object or null.
Set or null.
Matchers.anySet().
short, Short or null.
String or null.
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
OngoingStubbingStubberBoolean argument matchers.
Byte argument matchers.
Answer to be used with Mockito.mock(Class, Answer)
ArgumentCaptor creation on fields.Character argument matchers.
BlockJUnit4ClassRunner.String argument that contains the given substring.
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.MockitoAnnotationsdoAnswer() when you want to stub a void method with generic Answer.
Mockito.doAnswer(Answer) style:
doAnswer(answerOne).
- doCallRealMethod() -
Static method in class org.mockito.Mockito
- Use
doCallRealMethod() when you want to call the real implementation of a method.
- DoesNothing - Class in org.mockito.internal.stubbing.answers
-
- DoesNothing() -
Constructor for class org.mockito.internal.stubbing.answers.DoesNothing
-
- doNothing() -
Method in class org.mockito.internal.stubbing.StubberImpl
-
- doNothing() -
Static method in class org.mockito.Mockito
- Use
doNothing() for setting void methods to do nothing.
- doNothing() -
Method in interface org.mockito.stubbing.Stubber
- Use it for stubbing consecutive calls in
Mockito.doNothing() style:
doNothing().
- doReturn(Object) -
Method in class org.mockito.internal.stubbing.StubberImpl
-
- doReturn(Object) -
Static method in class org.mockito.Mockito
- Use
doReturn() in those rare occasions when you cannot use Mockito.when(Object).
- doReturn(Object) -
Method in interface org.mockito.stubbing.Stubber
- Use it for stubbing consecutive calls in
Mockito.doReturn(Object) style.
- doThrow(Throwable) -
Method in class org.mockito.internal.stubbing.StubberImpl
-
- doThrow(Class<? extends Throwable>) -
Method in class org.mockito.internal.stubbing.StubberImpl
-
- doThrow(Throwable) -
Static method in class org.mockito.Mockito
- Use
doThrow() when you want to stub the void method with an exception.
- doThrow(Class<? extends Throwable>) -
Static method in class org.mockito.Mockito
- Use
doThrow() when you want to stub the void method to throw exception of specified class.
- doThrow(Throwable) -
Method in interface org.mockito.stubbing.Stubber
- Use it for stubbing consecutive calls in
Mockito.doThrow(Throwable) style:
doThrow(new RuntimeException("one")).
- doThrow(Class<? extends Throwable>) -
Method in interface org.mockito.stubbing.Stubber
- Use it for stubbing consecutive calls in
Mockito.doThrow(Class extends Throwable>) style:
doThrow(RuntimeException.class).
- doubleThat(Matcher<Double>) -
Static method in class org.mockito.Matchers
- Allows creating custom
Double argument matchers.
String argument that ends with the given suffix.
boolean argument that is equal to the given value.
byte argument that is equal to the given value.
char argument that is equal to the given value.
double argument that is equal to the given value.
float argument that is equal to the given value.
int argument that is equal to the given value.
long argument that is equal to the given value.
short argument that is equal to the given value.
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
Float argument matchers.
ArgumentCaptor.
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
MockitoAnnotationsInOrder object that allows verifying mocks in order.
Integer argument matchers.
Object argument that implements the given class.
null argument.
null argument, not necessary of the given class.
null argument.
null argument.
Long argument matchers.
String argument that matches the given regular expression.
public class ArticleManagerTest extends SampleBaseTestCase {
@Mock private ArticleCalculator calculator;
@Mock(name = "dbMock") private ArticleDatabase database;
@Mock(answer = RETURNS_MOCKS) private UserProvider userProvider;
@Mock(extraInterfaces = {Queue.class, Observer.class}) private articleMonitor;
private ArticleManager manager;
@Before public void setup() {
manager = new ArticleManager(userProvider, database, calculator, articleMonitor);
}
}
public class SampleBaseTestCase {
@Before public void initMocks() {
MockitoAnnotations.initMocks(this);
}
}
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.times(0), see Mockito.times(int)
VerificationWithTimeout
VerificationWithTimeout.times(int)
MethodInvocationReport with a return value.
MethodInvocationReport with a return value.
null argument.
null argument, not necessary of the given class.
VerificationWithTimeout
Answer to be used with Mockito.mock(Class, Answer).
Answer of every mock if the mock was not stubbed.
Answer to be used with Mockito.mock(Class, Answer)
Answer to be used with 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
Short argument matchers.
String argument that starts with the given prefix.
Mockito.doThrow(Throwable) method for stubbing voids
VerificationWithTimeoutVerificationWithTimeout
VerificationWithTimeout
verify(mock, timeout(100).times(2)).someMethod("some arg");
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 | |||||||||