### Question:
SourceFile { public Code code() { if (code == null) { code = newCode(); try (InputStream stream = new FileInputStream(path)) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF8"))) { addText(reader); } } catch (IOException e) { } } return code; } SourceFile(String path);  SourceFile(String path, Code code); String path(); Code code(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }### Answer:
@Test public void readsCodeFromFile() throws FileNotFoundException, UnsupportedEncodingException { String text = RANDOM.string(); Code expected = new Code(); expected.add(text); File file = new File(new File(path), RANDOM.string()); try { try (PrintWriter writer = new PrintWriter(file, "UTF8")) { writer.println(text); } SourceFile sourceFile = new SourceFile(file.getPath()); Code code = sourceFile.code(); Assert.assertEquals("Code", expected, code); } finally { IO.delete(file); } }
@Test public void readsEmptyCodeFromMissingFile() { File file = new File(path); SourceFile sourceFile = new SourceFile(file.getPath()); Code code = sourceFile.code(); Assert.assertEquals("Code", new Code(), code); }