@Test @PrepareForTest({CreateProject.class, File.class}) @SuppressWarnings("unchecked") public void testExecute() throws Exception { final ProjectFile projectFile = new ProjectFile(); final WriteProjectFile writeProjectFile = mock(WriteProjectFile.class); final CreateProject command = spy(new CreateProject()); whenNew(ProjectFile.class).withAnyArguments().thenReturn(projectFile); whenNew(WriteProjectFile.class).withAnyArguments().thenReturn(writeProjectFile); mockStatic(Files.class); when(Files.list(any())).thenReturn(EMPTY_LIST.stream()); when(Files.newInputStream(any())) .thenReturn(new ByteArrayInputStream("hello, world".getBytes())); doNothing().when(command).prepare(any()); command.setPrinter(mock(MessagePrinter.class)); command.execute(); verify(writeProjectFile).execute(); }
@Override public void execute() throws Exception { logger.debug("Starting {} with {}...", this, arguments); final Options options = parse(new Options()); final Path projectPath = getProjectHome(); final String projectPathStr = getProjectHomePath(); final Path projectFilePath = getProjectFile(); final String projectFilePathStr = getProjectFilePath(); final WriteProjectFile writeProjectFile = new WriteProjectFile(); final String projectDirectoryName = getFilename(projectPathStr); if (!options.isForce() && 0 < Files.list(projectPath).count()) { logger.trace("Force: {}", options.isForce()); throw new DirectoryNotEmptyException(projectPath); } final String projectName = System.getProperty("user.name") + "/" + projectDirectoryName; final ProjectFile newProjectFile = newProjectFile(projectName); prepare(newProjectFile); writeProjectFile.setProject(newProjectFile); writeProjectFile.setArguments(singletonList(projectFilePathStr)); writeProjectFile.execute(); printer.println(bind(NL_0, projectPathStr)); try ( final InputStream in = Files.newInputStream(projectFilePath); final Reader reader = new InputStreamReader(in)) { printer.println(bind(NL_1, projectFilePathStr)); printer.println(IoUtils.from(reader)); } }
CreateProject extends AbstractCommand implements Command { @Override public void execute() throws Exception { logger.debug("Starting {} with {}...", this, arguments); final Options options = parse(new Options()); final Path projectPath = getProjectHome(); final String projectPathStr = getProjectHomePath(); final Path projectFilePath = getProjectFile(); final String projectFilePathStr = getProjectFilePath(); final WriteProjectFile writeProjectFile = new WriteProjectFile(); final String projectDirectoryName = getFilename(projectPathStr); if (!options.isForce() && 0 < Files.list(projectPath).count()) { logger.trace("Force: {}", options.isForce()); throw new DirectoryNotEmptyException(projectPath); } final String projectName = System.getProperty("user.name") + "/" + projectDirectoryName; final ProjectFile newProjectFile = newProjectFile(projectName); prepare(newProjectFile); writeProjectFile.setProject(newProjectFile); writeProjectFile.setArguments(singletonList(projectFilePathStr)); writeProjectFile.execute(); printer.println(bind(NL_0, projectPathStr)); try ( final InputStream in = Files.newInputStream(projectFilePath); final Reader reader = new InputStreamReader(in)) { printer.println(bind(NL_1, projectFilePathStr)); printer.println(IoUtils.from(reader)); } } }
CreateProject extends AbstractCommand implements Command { @Override public void execute() throws Exception { logger.debug("Starting {} with {}...", this, arguments); final Options options = parse(new Options()); final Path projectPath = getProjectHome(); final String projectPathStr = getProjectHomePath(); final Path projectFilePath = getProjectFile(); final String projectFilePathStr = getProjectFilePath(); final WriteProjectFile writeProjectFile = new WriteProjectFile(); final String projectDirectoryName = getFilename(projectPathStr); if (!options.isForce() && 0 < Files.list(projectPath).count()) { logger.trace("Force: {}", options.isForce()); throw new DirectoryNotEmptyException(projectPath); } final String projectName = System.getProperty("user.name") + "/" + projectDirectoryName; final ProjectFile newProjectFile = newProjectFile(projectName); prepare(newProjectFile); writeProjectFile.setProject(newProjectFile); writeProjectFile.setArguments(singletonList(projectFilePathStr)); writeProjectFile.execute(); printer.println(bind(NL_0, projectPathStr)); try ( final InputStream in = Files.newInputStream(projectFilePath); final Reader reader = new InputStreamReader(in)) { printer.println(bind(NL_1, projectFilePathStr)); printer.println(IoUtils.from(reader)); } }  }
CreateProject extends AbstractCommand implements Command { @Override public void execute() throws Exception { logger.debug("Starting {} with {}...", this, arguments); final Options options = parse(new Options()); final Path projectPath = getProjectHome(); final String projectPathStr = getProjectHomePath(); final Path projectFilePath = getProjectFile(); final String projectFilePathStr = getProjectFilePath(); final WriteProjectFile writeProjectFile = new WriteProjectFile(); final String projectDirectoryName = getFilename(projectPathStr); if (!options.isForce() && 0 < Files.list(projectPath).count()) { logger.trace("Force: {}", options.isForce()); throw new DirectoryNotEmptyException(projectPath); } final String projectName = System.getProperty("user.name") + "/" + projectDirectoryName; final ProjectFile newProjectFile = newProjectFile(projectName); prepare(newProjectFile); writeProjectFile.setProject(newProjectFile); writeProjectFile.setArguments(singletonList(projectFilePathStr)); writeProjectFile.execute(); printer.println(bind(NL_0, projectPathStr)); try ( final InputStream in = Files.newInputStream(projectFilePath); final Reader reader = new InputStreamReader(in)) { printer.println(bind(NL_1, projectFilePathStr)); printer.println(IoUtils.from(reader)); } }  @Override void execute(); }
CreateProject extends AbstractCommand implements Command { @Override public void execute() throws Exception { logger.debug("Starting {} with {}...", this, arguments); final Options options = parse(new Options()); final Path projectPath = getProjectHome(); final String projectPathStr = getProjectHomePath(); final Path projectFilePath = getProjectFile(); final String projectFilePathStr = getProjectFilePath(); final WriteProjectFile writeProjectFile = new WriteProjectFile(); final String projectDirectoryName = getFilename(projectPathStr); if (!options.isForce() && 0 < Files.list(projectPath).count()) { logger.trace("Force: {}", options.isForce()); throw new DirectoryNotEmptyException(projectPath); } final String projectName = System.getProperty("user.name") + "/" + projectDirectoryName; final ProjectFile newProjectFile = newProjectFile(projectName); prepare(newProjectFile); writeProjectFile.setProject(newProjectFile); writeProjectFile.setArguments(singletonList(projectFilePathStr)); writeProjectFile.execute(); printer.println(bind(NL_0, projectPathStr)); try ( final InputStream in = Files.newInputStream(projectFilePath); final Reader reader = new InputStreamReader(in)) { printer.println(bind(NL_1, projectFilePathStr)); printer.println(IoUtils.from(reader)); } }  @Override void execute();  }