@Test public void testConflictingOptionsTvsS() throws Exception { final File file = temporaryFolder.newFile("file.output"); exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Option '-t' cannot be used with other options." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-s", file.getCanonicalPath(), "-t", getPath("")); }
@Test public void testConflictingOptionsTvsO() throws Exception { final File file = temporaryFolder.newFile("file.output"); exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Option '-t' cannot be used with other options." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-o", file.getCanonicalPath(), "-t", getPath("")); }
@Test public void testPrintSuppressionConflictingOptionsTvsO() throws Exception { final File file = temporaryFolder.newFile("file.output"); exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Option '-s' cannot be used with other options." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-o", file.getCanonicalPath(), "-s", "2:4", getPath("")); }
@Test public void testNonExistentTargetFile() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Files to process must be specified, found 0." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-c", "/google_checks.xml", "NonExistentFile.java"); }
@Test public void testNoConfigSpecified() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Must specify a config XML file." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main(getPath("InputMain.java")); }
@Test public void testPrintSuppressionConflictingOptionsTvsC() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Option '-s' cannot be used with other options." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-c", "/google_checks.xml", getPath(""), "-s", "2:4"); }
@Test public void testZeroTreeWalkerThreadsNumber() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "TreeWalker threads number must be greater than zero" + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-W", "0", "-c", "/google_checks.xml", getPath("InputMain.java")); }
@Test public void testPrintTreeOnMoreThanOneFile() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Printing AST is allowed for only one file." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-t", getPath("")); }
@Test public void testConflictingOptionsTvsF() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Option '-t' cannot be used with other options." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-f", "plain", "-t", getPath("")); }
@Test public void testExcludeRegexpOption() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Files to process must be specified, found 0." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected output log", "", systemErr.getLog()); }); Main.main("-c", "/google_checks.xml", getFilePath(""), "-x", "."); }
@Test public void testPrintSuppressionConflictingOptionsTvsF() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Option '-s' cannot be used with other options." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-f", "plain", "-s", "2:4", getPath("")); }
@Test public void testConflictingOptionsTvsC() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Option '-t' cannot be used with other options." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-c", "/google_checks.xml", "-t", getPath("")); }
@Test public void testZeroCheckerThreadsNumber() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Checker threads number must be greater than zero" + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-C", "0", "-c", "/google_checks.xml", getPath("InputMain.java")); }
@Test public void testPrintSuppressionConflictingOptionsTvsP() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Option '-s' cannot be used with other options." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-p", getPath("InputMainMycheckstyle.properties"), "-s", "2:4", getPath("")); }
@Test public void testConflictingOptionsTvsP() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Option '-t' cannot be used with other options." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-p", getPath("InputMainMycheckstyle.properties"), "-t", getPath("")); }
@Test public void testExcludeOption() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Files to process must be specified, found 0." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-c", "/google_checks.xml", getFilePath(""), "-e", getFilePath("")); }
@Test public void testPrintSuppressionOnMoreThanOneFile() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "Printing xpath suppressions is allowed for " + "only one file." + System.lineSeparator(), systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-s", "2:4", getPath(""), getPath("")); }
@Test public void testMissingFiles() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { final String usage = "Missing required parameter: <files>" + EOL + SHORT_USAGE; assertEquals("Unexpected output log", "", systemOut.getLog()); assertEquals("Unexpected system error log", usage, systemErr.getLog()); }); Main.main(); }
@Test public void testNonExistentOutputFormat() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "", systemOut.getLog()); assertEquals("Unexpected system error log", "Invalid value for option '-f': expected one of [xml, plain] but was 'xmlp'" + EOL + SHORT_USAGE, systemErr.getLog()); }); Main.main("-c", "/google_checks.xml", "-f", "xmlp", getPath("InputMain.java")); }
@Test public void testInvalidCheckerThreadsNumber() throws Exception { exit.expectSystemExitWithStatus(-1); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "", systemOut.getLog()); assertEquals("Unexpected system error log", "Invalid value for option '--checker-threads-number': 'invalid' is not an int" + EOL + SHORT_USAGE, systemErr.getLog()); }); Main.main("-C", "invalid", "-c", "/google_checks.xml", getPath("InputMain.java")); }