I am using a BufferedWriter object in my source code
BufferedWriter outputToErrorFile = new BufferedWriter(new FileWriter(file));
outputToErrorFile.append("some string");
I am trying to mock it in my test case as follows:
BufferedWriter mockBufferedWriter = PowerMockito.mock(BufferedWriter.class);
PowerMockito.whenNew(BufferedWriter.class).withAnyArguments().thenReturn(mockBufferedWriter);
PowerMockito.when(mockBufferedWriter.append(Mockito.any(String.class))).thenThrow(new IOException());
However, the BufferedWriter does not get mocked and it always goes into the actual implementation. Is it because that one cannot mock BufferedWriter as it is a concrete class? Does that mean none of the java.io classes can be mocked? Is there a way to mock it, or is there something I am doing wrong?