I have a class with method impersonate which throws UnsupportedOperationException. So I want to mock only this only method. I know that I can do it with Mockito.spy.
Session session = Mockito.spy(new Session("admin", "adminSpace")); Session imperSession = new Session("test", "testSpace"); when(session.impersonate(any(Credentials.class))).thenReturn(imperSession); But the problem is that Mockito really calls impersonate and UnsupportedOperationException throws the execution. So what can I do here?