public class DefaultMockingDetails extends java.lang.Object implements MockingDetails
MockUtil
.Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
toInspect |
Constructor and Description |
---|
DefaultMockingDetails(java.lang.Object toInspect) |
Modifier and Type | Method and Description |
---|---|
private void |
assertGoodMock() |
private InvocationContainerImpl |
getInvocationContainer() |
java.util.Collection<Invocation> |
getInvocations()
All method invocations on this mock.
|
java.lang.Object |
getMock()
Returns the mock object which is associated with this this instance of
MockingDetails . |
MockCreationSettings<?> |
getMockCreationSettings()
Returns various mock settings provided when the mock was created, for example:
mocked class, mock name (if any), any extra interfaces (if any), etc.
|
MockHandler |
getMockHandler()
Returns the
MockHandler associated with this mock object. |
java.util.Collection<Stubbing> |
getStubbings()
Returns stubbings declared on this mock object.
|
boolean |
isMock()
Informs if the object is a mock.
|
boolean |
isSpy()
Informs if the object is a spy.
|
private MockHandler<java.lang.Object> |
mockHandler() |
java.lang.String |
printInvocations()
Returns printing-friendly list of the invocations that occurred with the mock object.
|
public boolean isMock()
MockingDetails
isMock
in interface MockingDetails
public boolean isSpy()
MockingDetails
isSpy
in interface MockingDetails
public java.util.Collection<Invocation> getInvocations()
MockingDetails
This method is useful for framework integrators and for certain edge cases.
Manipulating the collection (e.g. by removing, adding elements) is safe and has no effect on the mock.
Throws meaningful exception when object wrapped by MockingDetails is not a mock.
getInvocations
in interface MockingDetails
private InvocationContainerImpl getInvocationContainer()
public MockCreationSettings<?> getMockCreationSettings()
MockingDetails
MockCreationSettings
.
This method is useful for framework integrators and for certain edge cases.
If null
or non-mock was passed to Mockito.mockingDetails(Object)
then this method will throw with an appropriate exception.
After all, non-mock objects do not have any mock creation settings.
getMockCreationSettings
in interface MockingDetails
public java.util.Collection<Stubbing> getStubbings()
MockingDetails
Mockito.mockingDetails(mock).getStubbings()
What is 'stubbing'?
Stubbing is your when(x).then(y) declaration, e.g. configuring the mock to behave in a specific way,
when specific method with specific arguments is invoked on a mock.
Typically stubbing is configuring mock to return X when method Y is invoked.
Why do you need to access stubbings of a mock?
In a normal workflow of creation clean tests, there is no need for this API.
However, it is useful for advanced users, edge cases or framework integrators.
For example, Mockito internally uses this API to report and detect unused stubbings
that should be removed from test. Unused stubbings are dead code that needs to be removed
(see MockitoHint
).
Manipulating the collection (e.g. by removing, adding elements) is safe and has no effect on the mock.
This method throws meaningful exception when object wrapped by MockingDetails is not a mock.
getStubbings
in interface MockingDetails
public java.lang.String printInvocations()
MockingDetails
MockitoHint
.
You can use this method for debugging, print the output of this method to the console to find out about all interactions with the mock.
Content that is printed is subject to change as we discover better ways of presenting important mock information.
Don't write code that depends on the output of this method.
If you need to know about interactions and stubbings, use MockingDetails.getStubbings()
and MockingDetails.getInvocations()
.
This method was moved from the deprecated and semi-hidden type MockitoDebugger
.
This method throws meaningful exception when object wrapped by MockingDetails is not a mock.
printInvocations
in interface MockingDetails
public MockHandler getMockHandler()
MockingDetails
MockHandler
associated with this mock object.
The handler is the core of mock object method handling.
This method is useful for framework integrators.
For example, other frameworks may use mock handler to simulate method calls on the Mock object.getMockHandler
in interface MockingDetails
public java.lang.Object getMock()
MockingDetails
MockingDetails
.
Basically, it's the object that you have passed to Mockito.mockingDetails(Object)
method.getMock
in interface MockingDetails
private MockHandler<java.lang.Object> mockHandler()
private void assertGoodMock()