Currently trying to create a mock of a method called containsKey that derives from the java MAP interface, this is how it is defined:
//Creation
Map<String, ProviderServiceKey> providerService
Usage:
[providerService.containsKey(object.method)](https://www.stackoverflow.com/)
Here the mock, that is being recognized but the return of this method is not fully covered:
[new MockUp<java.util.Map<String, ProviderServiceKey>>(){
@Mock
public boolean containsKey(Object key){
return true; //This is not covered
}
}](https://www.stackoverflow.com/)
I tried opening the type hierarchy of the containsKey method in Eclipse, but the thing is a lot of classes are being displayed. (This are the classes that are implementing the Map interface and its methods). With this said there are too many. Is there a way to slim down the search of the correct class that uses the containsKey method as it is being used above?
I believe latest versions of JMockit will warn you (or prohibit) attempts to Mock Collections (including Map). I believe they determined there was no good reason to do so.
If your class-under-test has a Collection of objects, you can either mock the CUT, put a real Collection into the CUT, and potentially fill the collection with additional mocks. Hence, mock the things in the Collection, or mock the thing holding the Collection, but don't mock the Collection itself.