I have the following test file using Mockito framework:
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Spy
private JarExtracter jExt = Mockito.spy(JarExtracter.class);
@Test
public void inputStreamTest() throws IOException {
String path = "/edk.dll";
// Call the method and do the checks
jExt.extract(path);
// Check for error with a null stream
path = "/../edk.dll";
doThrow(IOException.class).when(jExt).extract(path);
jExt.extract(path);
verifyNoMoreInteractions(jExt);
expectedException.expect(IOException.class);
expectedException.expectMessage("Cannot get");
doThrow()
line returns:
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at confusionIndicator.tests.JarExtracterTests.inputStreamTest(JarExtracterTests.java:30)
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();
Hints:
1. missing thenReturn()
2. you are trying to stub a final method, you naughty developer!
3: you are stubbing the behaviour of another mock inside before 'thenReturn' instruction if completed
I tried different approaches to testing this error throwing behaviour, but I just cannot get rid of this error message which makes my test fail. Any help will be substantially appreciated!
Aucun commentaire:
Enregistrer un commentaire