@Test @PrepareForTest(WriteProjectFile.class) public void shouldNotCreateFile() throws Exception { mockStatic(Files.class); when(Files.exists(any())).thenReturn(true); final BufferedWriter bufferedWriter = mock(BufferedWriter.class); when(Files.newBufferedWriter(any(Path.class))).thenReturn(bufferedWriter); final WriteProjectFile command = new WriteProjectFile(); command.setArguments(singletonList(randomUUID().toString())); command.execute(); verify(bufferedWriter, new AtMost(0)).write(any(char[].class), anyInt(), anyInt()); }
@Override public void execute() throws Exception { assertTrue(1 == arguments.size()); final Path projectFilePath = Paths.get(arguments.get(0)); final ObjectMapper mapper = new ObjectMapper(); if (Files.exists(projectFilePath)) { logger.warn("Project file already exists"); return; } try (final BufferedWriter writer = newBufferedWriter(projectFilePath)) { mapper.writerWithDefaultPrettyPrinter().writeValue(writer, project); } }
WriteProjectFile extends AbstractCommand { @Override public void execute() throws Exception { assertTrue(1 == arguments.size()); final Path projectFilePath = Paths.get(arguments.get(0)); final ObjectMapper mapper = new ObjectMapper(); if (Files.exists(projectFilePath)) { logger.warn("Project file already exists"); return; } try (final BufferedWriter writer = newBufferedWriter(projectFilePath)) { mapper.writerWithDefaultPrettyPrinter().writeValue(writer, project); } } }
WriteProjectFile extends AbstractCommand { @Override public void execute() throws Exception { assertTrue(1 == arguments.size()); final Path projectFilePath = Paths.get(arguments.get(0)); final ObjectMapper mapper = new ObjectMapper(); if (Files.exists(projectFilePath)) { logger.warn("Project file already exists"); return; } try (final BufferedWriter writer = newBufferedWriter(projectFilePath)) { mapper.writerWithDefaultPrettyPrinter().writeValue(writer, project); } }  }
WriteProjectFile extends AbstractCommand { @Override public void execute() throws Exception { assertTrue(1 == arguments.size()); final Path projectFilePath = Paths.get(arguments.get(0)); final ObjectMapper mapper = new ObjectMapper(); if (Files.exists(projectFilePath)) { logger.warn("Project file already exists"); return; } try (final BufferedWriter writer = newBufferedWriter(projectFilePath)) { mapper.writerWithDefaultPrettyPrinter().writeValue(writer, project); } }  @Override void execute(); }
WriteProjectFile extends AbstractCommand { @Override public void execute() throws Exception { assertTrue(1 == arguments.size()); final Path projectFilePath = Paths.get(arguments.get(0)); final ObjectMapper mapper = new ObjectMapper(); if (Files.exists(projectFilePath)) { logger.warn("Project file already exists"); return; } try (final BufferedWriter writer = newBufferedWriter(projectFilePath)) { mapper.writerWithDefaultPrettyPrinter().writeValue(writer, project); } }  @Override void execute();  }