Commands { public ExitCode generate(final Path reportDirectory, final List<Path> resultsDirectories, final boolean clean, final ConfigOptions profile) { final boolean directoryExists = Files.exists(reportDirectory); if (clean && directoryExists) { FileUtils.deleteQuietly(reportDirectory.toFile()); } else if (directoryExists && isDirectoryNotEmpty(reportDirectory)) { LOGGER.error(DIRECTORY_EXISTS_MESSAGE, reportDirectory.toAbsolutePath()); return ExitCode.GENERIC_ERROR; } try { final ReportGenerator generator = new ReportGenerator(createReportConfiguration(profile)); generator.generate(reportDirectory, resultsDirectories); } catch (IOException e) { LOGGER.error("Could not generate report", e); return ExitCode.GENERIC_ERROR; } LOGGER.info("Report successfully generated to {}", reportDirectory); return ExitCode.NO_ERROR; } Commands(final Path allureHome); CommandlineConfig getConfig(final ConfigOptions configOptions); Optional<Path> getConfigFile(final ConfigOptions configOptions); String getConfigFileName(final String profile); ExitCode generate(final Path reportDirectory,
                             final List<Path> resultsDirectories,
                             final boolean clean,
                             final ConfigOptions profile); ExitCode serve(final List<Path> resultsDirectories,
                          final String host,
                          final int port,
                          final ConfigOptions configOptions); ExitCode open(final Path reportDirectory, final String host, final int port); ExitCode listPlugins(final ConfigOptions configOptions);  }
@Test void shouldFailIfDirectoryExists(@TempDir final Path temp) throws Exception { final Path home = Files.createDirectories(temp.resolve("home")); final Path reportPath = Files.createDirectories(temp.resolve("report")); Files.createTempFile(reportPath, "some", ".txt"); final Commands commands = new Commands(home); final ExitCode exitCode = commands.generate(reportPath, null, false, null); assertThat(exitCode) .isEqualTo(ExitCode.GENERIC_ERROR); }
@Test void shouldAllowEmptyReportDirectory(@TempDir final Path temp) throws Exception { final Path home = Files.createDirectories(temp.resolve("home")); createConfig(home, "allure-test.yml"); final ConfigOptions options = mock(ConfigOptions.class); when(options.getProfile()).thenReturn("test"); final Path reportPath = Files.createDirectories(temp.resolve("report")); final Commands commands = new Commands(home); final ExitCode exitCode = commands.generate(reportPath, Collections.emptyList(), false, options); assertThat(exitCode) .isEqualTo(ExitCode.NO_ERROR); }