I'm trying to access part of a copy method protected by a try catch using mockito while attempting to get 100% coverage in my junit tests. The class that contains the method I want to access implements cloneable making it difficult to throw ClassNotFoundExceptions.
I've tried to force this exception several different ways through mockito's ability to throw exceptions when calling a method but have always come up with an InvalidUseOfMatchersException.
following is the code i need to access and my best attempt at reaching it, respectively
catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
MyClass dict = mock(MyClass.class);
Object obj1 = new Object();
when(MyClass.copy(anyObject())).thenThrow(ClassNotFoundException.class);
dict.copy(obj1);
I expect to reach the cnfe.printStackTrace() line but cannot.