java - how to throw IOException while reading a file using Mockito? -



java - how to throw IOException while reading a file using Mockito? -

i have throw ioexception using mockito method, reading input stream given below. there way it?

public void somemethod(){ try{ bufferedreader in = new bufferedreader(new inputstreamreader(inputstream)); firstline = in.readline(); }catch(ioexception ioexception){ //do }

i tried mocking like

bufferedreader buffreader = mockito.mock(bufferedreader.class); mockito.dothrow(new ioexception()).when(buffreader).readline();

but didn't work out :(

you're mocking bufferedreader, method doesn't utilize mock. uses own, new bufferedreader. need able inject mock method.

it seems inputstream field of class containing method. mock inputstream instead , create throw ioexception when read() method called (by inputstreamreader).

java unit-testing mocking mockito

Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -