@Test @PrepareForTest(InstallPackage.class) public void testExecute() throws Exception { final CloneGit cloneGit = mock(CloneGit.class); final FileSet fileSet = mock(FileSet.class); mockStatic(Files.class); when(Files.createDirectories(any())).thenReturn(null); whenNew(CloneGit.class).withAnyArguments().thenReturn(cloneGit); when(cloneGit.getFileSet()).thenReturn(fileSet); final InstallPackage command = new InstallPackage(); command.setPrinter(DummyMessagePrinter.getInstance()); command.setArguments(singletonList(randomUUID().toString() + "/" + randomUUID().toString())); command.execute(); }
@Override public void execute() throws Exception { assertTrue(0 < arguments.size() && arguments.size() < 3); final String packageName = getArgument(0); logger.debug("URL: {}", packageName); final int separatorIndex = packageName.indexOf("/"); assertTrue(0 < separatorIndex, "Invalid argument: " + packageName); final Optional<String> checkout = getOptionalArgument(1); final CloneGit cloneGit = new CloneGit(); logger.trace("CloneGit: {}", cloneGit); cloneGit.setArguments(asList(packageName, checkout.orElse("master"))); cloneGit.execute(); final FileSet fileSet = cloneGit.getFileSet(); logger.debug("FileSet: {}", fileSet.getFiles()); final String publishRepository = append(System.getProperty("user.home"), MODULES_BASE); final Path publishPath = Paths.get(append(publishRepository, packageName)); if (exists(publishPath)) { deleteRecursively(publishPath, ALLOW_INSECURE); } createDirectories(publishPath); fileSet.copyTo(publishPath); printer.println(bind(NL_0, packageName)); printer.println(bind(NL_1, publishPath)); }
InstallPackage extends AbstractCommand { @Override public void execute() throws Exception { assertTrue(0 < arguments.size() && arguments.size() < 3); final String packageName = getArgument(0); logger.debug("URL: {}", packageName); final int separatorIndex = packageName.indexOf("/"); assertTrue(0 < separatorIndex, "Invalid argument: " + packageName); final Optional<String> checkout = getOptionalArgument(1); final CloneGit cloneGit = new CloneGit(); logger.trace("CloneGit: {}", cloneGit); cloneGit.setArguments(asList(packageName, checkout.orElse("master"))); cloneGit.execute(); final FileSet fileSet = cloneGit.getFileSet(); logger.debug("FileSet: {}", fileSet.getFiles()); final String publishRepository = append(System.getProperty("user.home"), MODULES_BASE); final Path publishPath = Paths.get(append(publishRepository, packageName)); if (exists(publishPath)) { deleteRecursively(publishPath, ALLOW_INSECURE); } createDirectories(publishPath); fileSet.copyTo(publishPath); printer.println(bind(NL_0, packageName)); printer.println(bind(NL_1, publishPath)); } }
InstallPackage extends AbstractCommand { @Override public void execute() throws Exception { assertTrue(0 < arguments.size() && arguments.size() < 3); final String packageName = getArgument(0); logger.debug("URL: {}", packageName); final int separatorIndex = packageName.indexOf("/"); assertTrue(0 < separatorIndex, "Invalid argument: " + packageName); final Optional<String> checkout = getOptionalArgument(1); final CloneGit cloneGit = new CloneGit(); logger.trace("CloneGit: {}", cloneGit); cloneGit.setArguments(asList(packageName, checkout.orElse("master"))); cloneGit.execute(); final FileSet fileSet = cloneGit.getFileSet(); logger.debug("FileSet: {}", fileSet.getFiles()); final String publishRepository = append(System.getProperty("user.home"), MODULES_BASE); final Path publishPath = Paths.get(append(publishRepository, packageName)); if (exists(publishPath)) { deleteRecursively(publishPath, ALLOW_INSECURE); } createDirectories(publishPath); fileSet.copyTo(publishPath); printer.println(bind(NL_0, packageName)); printer.println(bind(NL_1, publishPath)); }  }
InstallPackage extends AbstractCommand { @Override public void execute() throws Exception { assertTrue(0 < arguments.size() && arguments.size() < 3); final String packageName = getArgument(0); logger.debug("URL: {}", packageName); final int separatorIndex = packageName.indexOf("/"); assertTrue(0 < separatorIndex, "Invalid argument: " + packageName); final Optional<String> checkout = getOptionalArgument(1); final CloneGit cloneGit = new CloneGit(); logger.trace("CloneGit: {}", cloneGit); cloneGit.setArguments(asList(packageName, checkout.orElse("master"))); cloneGit.execute(); final FileSet fileSet = cloneGit.getFileSet(); logger.debug("FileSet: {}", fileSet.getFiles()); final String publishRepository = append(System.getProperty("user.home"), MODULES_BASE); final Path publishPath = Paths.get(append(publishRepository, packageName)); if (exists(publishPath)) { deleteRecursively(publishPath, ALLOW_INSECURE); } createDirectories(publishPath); fileSet.copyTo(publishPath); printer.println(bind(NL_0, packageName)); printer.println(bind(NL_1, publishPath)); }  @Override void execute(); }
InstallPackage extends AbstractCommand { @Override public void execute() throws Exception { assertTrue(0 < arguments.size() && arguments.size() < 3); final String packageName = getArgument(0); logger.debug("URL: {}", packageName); final int separatorIndex = packageName.indexOf("/"); assertTrue(0 < separatorIndex, "Invalid argument: " + packageName); final Optional<String> checkout = getOptionalArgument(1); final CloneGit cloneGit = new CloneGit(); logger.trace("CloneGit: {}", cloneGit); cloneGit.setArguments(asList(packageName, checkout.orElse("master"))); cloneGit.execute(); final FileSet fileSet = cloneGit.getFileSet(); logger.debug("FileSet: {}", fileSet.getFiles()); final String publishRepository = append(System.getProperty("user.home"), MODULES_BASE); final Path publishPath = Paths.get(append(publishRepository, packageName)); if (exists(publishPath)) { deleteRecursively(publishPath, ALLOW_INSECURE); } createDirectories(publishPath); fileSet.copyTo(publishPath); printer.println(bind(NL_0, packageName)); printer.println(bind(NL_1, publishPath)); }  @Override void execute();  }