ExceptionPersister { void closeStream(Closeable closeable) { try { if(closeable != null) { closeable.close(); } } catch (IOException ex) { utils.logIssue("Could not close exception storage file.", ex); } } ExceptionPersister(Context context); Map<String, StoredException> loadAll(); void store(StoredException storedException);  }
@Test public void testCloseStream() throws IOException { InputStream mockInputStream = mock(InputStream.class); ExceptionPersister exceptionPersister = new ExceptionPersister(null); exceptionPersister.closeStream(mockInputStream); verify(mockInputStream).close(); }
@Test public void testcloseStreamException() throws IOException { OutputStream mockOutputStream = mock(OutputStream.class); Utils mockUtils = mock(Utils.class); Exception exceptionToThrow = new IOException("Unit Testing"); doThrow(exceptionToThrow).when(mockOutputStream).close(); ExceptionPersister exceptionPersister = new ExceptionPersister(null); exceptionPersister.utils = mockUtils; exceptionPersister.closeStream(mockOutputStream); verify(mockUtils).logIssue(eq("Could not close exception storage file."), eq(exceptionToThrow)); }