Class DefaultMockingDetails
- All Implemented Interfaces:
MockingDetails
MockUtil.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAll method invocations on this mock.getMock()Returns the mock object which is associated with this this instance ofMockingDetails.Returns various mock settings provided when the mock was created, for example: mocked class, mock name (if any), any extra interfaces (if any), etc.Returns theMockHandlerassociated with this mock object.Returns stubbings declared on this mock object.booleanisMock()Informs if the object is a mock.booleanisSpy()Informs if the object is a spy.Returns printing-friendly list of the invocations that occurred with the mock object.
-
Constructor Details
-
DefaultMockingDetails
-
-
Method Details
-
isMock
public boolean isMock()Description copied from interface:MockingDetailsInforms if the object is a mock. isMock() for null input returns false.- Specified by:
isMockin interfaceMockingDetails- Returns:
- true if the object is a mock or a spy (spy is a different kind of mock, but it is still a mock).
-
isSpy
public boolean isSpy()Description copied from interface:MockingDetailsInforms if the object is a spy. isSpy() for null input returns false.- Specified by:
isSpyin interfaceMockingDetails- Returns:
- true if the object is a spy.
-
getInvocations
Description copied from interface:MockingDetailsAll method invocations on this mock. Can be empty - it means there were no interactions with the mock.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.
- Specified by:
getInvocationsin interfaceMockingDetails
-
getMockCreationSettings
Description copied from interface:MockingDetailsReturns various mock settings provided when the mock was created, for example: mocked class, mock name (if any), any extra interfaces (if any), etc. See alsoMockCreationSettings.This method is useful for framework integrators and for certain edge cases.
If
nullor non-mock was passed toMockito.mockingDetails(Object)then this method will throw with an appropriate exception. After all, non-mock objects do not have any mock creation settings.- Specified by:
getMockCreationSettingsin interfaceMockingDetails
-
getStubbings
Description copied from interface:MockingDetailsReturns stubbings declared on this mock object.
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.Mockito.mockingDetails(mock).getStubbings()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.
- Specified by:
getStubbingsin interfaceMockingDetails
-
printInvocations
Description copied from interface:MockingDetailsReturns printing-friendly list of the invocations that occurred with the mock object. Additionally, this method prints stubbing information, including unused stubbings. For more information about unused stubbing detection seeMockitoHint.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()andMockingDetails.getInvocations().This method throws meaningful exception when object wrapped by MockingDetails is not a mock.
- Specified by:
printInvocationsin interfaceMockingDetails
-
getMockHandler
Description copied from interface:MockingDetailsReturns theMockHandlerassociated 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.- Specified by:
getMockHandlerin interfaceMockingDetails- Returns:
- mock handler instance of this mock
-
getMock
Description copied from interface:MockingDetailsReturns the mock object which is associated with this this instance ofMockingDetails. Basically, it's the object that you have passed toMockito.mockingDetails(Object)method.- Specified by:
getMockin interfaceMockingDetails- Returns:
- the mock object of this mocking details instance
-