|
||||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||
Matchers for general info about matchers.MockitoAnnotations.initMocks(Object)Mock
Example:
@Mock(answer = RETURNS_DEEP_STUBS) UserProvider userProvider;
This is not the full list of Answers available in Mockito.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)
Answer can be used to define the return values of unstubbed invocations.
Answer can be used to define the return values of unstubbed invocations.ArgumentCaptor creation on fields.Character argument matchers.
IMockitoConfiguration
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 {@link Mockito#doThrow(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.
IMockitoConfiguration
IMockitoConfiguration
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
See examples in javadoc for MockitoAnnotations class.
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.
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
Mockito library enables mocks creation, verification and stubbing.
Mock,
so that explicit usage of MockitoAnnotations.initMocks(Object) is not necessary.times(0), see Mockito.times(int)
Verifies that interaction did not happen.
VerificationWithTimeout
VerificationWithTimeout.times(int)
Verifies that interaction did not happen within given timeout.
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 can be used to define the return values of unstubbed invocations.
Answer to be used with Mockito.mock(Class, Answer).
Mockito.mock(Class, Answer)
This implementation can be helpful when working with legacy code.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.
doThrow(new RuntimeException()).when(mockedList).clear(); //following throws RuntimeException: mockedList.clear();Also useful when stubbing consecutive calls:doThrow(new RuntimeException("one")).- StubberImpl - Class in org.mockito.internal.stubbing
- StubberImpl() - Constructor for class org.mockito.internal.stubbing.StubberImpl
- stubbingCompleted(Invocation) - Method in interface org.mockito.internal.progress.MockingProgress
- stubbingCompleted(Invocation) - Method in class org.mockito.internal.progress.MockingProgressImpl
- stubbingCompleted(Invocation) - Method in class org.mockito.internal.progress.ThreadSafeMockingProgress
- stubbingStarted() - Method in interface org.mockito.internal.progress.MockingProgress
- stubbingStarted() - Method in class org.mockito.internal.progress.MockingProgressImpl
- stubbingStarted() - Method in class org.mockito.internal.progress.ThreadSafeMockingProgress
- stubInfo() - Method in class org.mockito.internal.invocation.Invocation
- StubInfo - Class in org.mockito.internal.invocation
- StubInfo(PrintableInvocation) - Constructor for class org.mockito.internal.invocation.StubInfo
- stubVoid(T) - Method in class org.mockito.internal.MockitoCore
- stubVoid(T) - Static method in class org.mockito.Mockito
- Deprecated. Use
Mockito.doThrow(Throwable)method for stubbing voids
VerificationWithTimeout
Typically, you won't use this class explicitly.VerificationWithTimeout
Typically, you won't use this class explicitly.
VerificationWithTimeout
verify(mock, timeout(100).times(2)).someMethod("some arg");See examples in javadoc forMockitoclass
Answer
For Example:
stubVoid(mock)
.toAnswer(new Answer() {
public Object answer(InvocationOnMOck invocation) {
Visitor v = (Visitor) invocation.getArguments()[0];
v.visitMock(invocation.getMock());
return null;
}
})
.on().accept(any());
validateMockitoUsage() explicitly validates the framework state to detect invalid use of Mockito.
VerificationMode that allows combining existing verification modes with 'timeout'.VerificationWithTimeout
doThrow(new RuntimeException()) .when(mockedList).clear(); //following throws RuntimeException: mockedList.clear();Read more about those methods:Mockito.doThrow(Throwable)Mockito.doAnswer(Answer)Mockito.doNothing()Mockito.doReturn(Object)See examples in javadoc forMockito
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 | |||||||||