FileHashes { String of(File file) { try { return of(new FileInputStream(file)); } catch (IOException e) { throw new IllegalStateException("Fail to compute hash of: " + file.getAbsolutePath(), e); } }    }
@Test public void fail_if_file_does_not_exist() throws IOException { File file = temp.newFile("does_not_exist"); file.delete(); thrown.expect(IllegalStateException.class); thrown.expectMessage("Fail to compute hash of: " + file.getAbsolutePath()); new FileHashes().of(file); }
@Test public void fail_if_stream_is_closed() throws Exception { thrown.expect(IllegalStateException.class); thrown.expectMessage("Fail to compute hash"); InputStream input = mock(InputStream.class); when(input.read(any(byte[].class), anyInt(), anyInt())).thenThrow(new IllegalThreadStateException()); new FileHashes().of(input); }