I'm trying to mock OutputStream to throw an Exception while writing, but mocked object is not initialized, and that's why I got NPE. The piece of code:
@Mocked
OutputStreamWriter writer;
@Test
void testWriteFailureWithoutRetries() throws IOException {
new Expectations() {{
writer.write(anyString);
result = new IOException();
}};
...
}
In Expectations block, the writer object is null. I use jMockit 1.44, jUnit 5.4.2
UPD: problem was solved by rolling jUnit version back to 5.3.2, but probably there is a better solution?