WriteProjectTarget extends AbstractCommand { @Override public void execute() throws Exception { final String buildTarget = project.getProjectFile().getTarget(); final Path buildTargetPath = project.getPath().resolve(buildTarget); final FileWriter fileWriter = new FileWriter(buildTargetPath); fileWriter.accept(contents.get()); }  void setProject(final Project project); @Override void execute();  }
@Test @PrepareForTest(FileWriter.class) public void testExecute() throws Exception { final byte[] content = randomUUID().toString().getBytes(); final OutputStream out = mock(OutputStream.class); mockStatic(Files.class); when(Files.newOutputStream(any())).thenReturn(out); final ProjectFile projectFile = new ProjectFile(); projectFile.setTarget(randomUUID().toString()); final Project project = new Project(randomUUID().toString(), projectFile); final WriteProjectTarget writeProjectTarget = new WriteProjectTarget(); writeProjectTarget.setProject(project); writeProjectTarget.setContents(() -> new ByteArrayInputStream(content)); writeProjectTarget.execute(); verify(out).write(any(), anyInt(), anyInt()); }