What about using regular class with instance variable:
class MyInputStream {
boolean closeCalled = false;
@Override
public int read() throws IOException {
return -1;
}
@Override
public void close() throws IOException {
closeCalled = true;
super.close();
}
boolean getCloseCalled() {
return closeCalled;
}
};
MyInputStream stream = new MyInputStream();
If you don't want to create your own class consider using any mocking framework, e.g. with Jmokit:
@Test
public void shouldCallClose(final InputStream inputStream) throws Exception {
new Expectations(){{
inputStream.close();
}};
MyClassUnderTest.closingStreamFunc(inputStream);
}