### Question:
RealSourceFiles implements Reality<String, SourceFile> { @Override public void add(String path, SourceFile sourceFile) { File file = getUpdatableFile(path); try (PrintWriter writer = new PrintWriter(file, "UTF8")) { writer.print(sourceFile.code().text()); } catch (IOException e) { throw new RuntimeException(e); } } RealSourceFiles(File baseDir, String generatedSourceDir, String manualSourceDir,
      String codeDir, SourceCodeManagementSystem scm); @Override Collection<String> getIds(); @Override SourceFile get(String id); @Override void add(String path, SourceFile sourceFile); @Override void remove(String path); @Override void update(String path, SourceFile oldSourceFile, SourceFile newSourceFile);  }### Answer:
@Test public void addsFile() throws IOException { File file = randomFile(aSourceSetDir(), codeDir, ""); Code code = new Code(); code.add("public class C { }"); SourceFile sourceFile = new SourceFile(file.getCanonicalPath(), code); assertFalse("Sanity check", file.exists()); reality.add(file.getPath(), sourceFile); assertTrue("File is not created", file.exists()); assertEquals("File contents", code.text(), textOf(file)); }
@Test public void preparesReadOnlyFileForUpdate() throws Exception { File file = randomFile(aSourceSetDir(), codeDir, ""); Code code = new Code(); code.add("public class C { }"); SourceFile sourceFile = new SourceFile(file.getCanonicalPath(), code); file.setReadOnly(); reality.add(file.getPath(), sourceFile); verify(scm).prepareForUpdate(eq(file)); }