I've not done much testing and very minimal in Mockito. When I call delete on a certain object, I get a DeleteResponse. This has a method called getProcessingErrors() which is a set. I can then call .isEmpty() to see if there are errors or not. I'm trying to mock this out.
DeleteResponse deleteResponse = mock(DeleteResponse.class);
when(catalogFramework.delete(any(DeleteRequest.class))).thenReturn(deleteResponse);
when(deleteResponse.getProcessingErrors()).thenReturn(new HashSet<ProcessingDetails>());
PowerMockito.when(deleteResponse.getProcessingErrors().isEmpty()).thenReturn(true);
Error:
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
Boolean cannot be returned by getProcessingErrors()
getProcessingErrors() should return Set
***
If you're unsure why you're getting above error read on.
Due to the nature of the syntax above problem might occur because:
1. This exception *might* occur in wrongly written multi-threaded tests.
Please refer to Mockito FAQ on limitations of concurrency testing.
2. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies -
- with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
Now, from the way I am reading this, it is saying isEmpty cannot return a boolean, but I believe it's cutting out early and just looking at the getProcessingErrors. How can I fix this?