I have a method call like this
class classname
{
void somemethod()
{
InpuStream someImputStream=classname.class.getResourceAsStream("some string");
}
}
Is there any way to mock the method call?
Thanks
You can first introduce a method for returning the input stream
class classname
{
void somemethod()
{
InpuStream someImputStream = getInputStream();
}
protected InputStream getInputStream() {
return classname.class.getResourceAsStream("some string");
}
}
In your test case
classname testObject = org.mockito.Mockito.spy(new classname());
org.mockito.Mockito.when(testObject.getInputStream()).thenReturn(...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With