Sto provando a simulare un metodo per vedere se gestisco correttamente un'eccezione. Questo è quanto posso ottenere.Eccezione di Mockito in doThrow che sembra corretta
interfaccia:
interface SampleManager {
void deleteVariome(String specimenId, String analysisId) throws Exception;
// ...
}
unit test:
// ...
SampleManger sampleManager = mock(SampleManager.class);
// below is line 753
doThrow(Exception.class).when(sampleManager).deleteVariome(sample1.getId(), analysisId);
risultato:
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at ...server.ArchiveManagerImplUTest.deleteVariomeFails(ArchiveManagerImplUTest.java:753)
E.g. thenReturn() may be missing.
Examples of correct stubbing:
when(mock.isOk()).thenReturn(true);
when(mock.isOk()).thenThrow(exception);
doThrow(exception).when(mock).someVoidMethod(); <-- this looks a log like what I did!
Hints:
1. missing thenReturn()
2. you are trying to stub a final method, you naughty developer! <-- I have a lot of other mocks of this interface in this test that work.
No, da Mockito 1.9.0 in poi, è possibile fornire la classe di eccezione, e che funzionerà come previsto.Tuttavia, anche se l'OP utilizza una vecchia versione di Mockito, non otterrebbero il sintomo che stanno descrivendo qui. Credo che il problema sia qualcosa di diverso. –
Grazie David. Non lo sapevo. Lascerò qui la mia risposta in modo che altri possano essere consapevoli del tuo commento. –