public void checkAssertion() { String expected = String.format("" + "ERROR: picocli.AutoComplete: %s exists. Specify --force to overwrite.%n" + "%s", commandScript.getAbsolutePath(), AUTO_COMPLETE_APP_USAGE); assertTrue(systemErrRule.getLog().startsWith(expected)); } });
@Test public void testISO8601TimeConverterRegisterIfAvailableExceptionHandling() throws Exception { Class<?> c = Class.forName("picocli.CommandLine$BuiltIn$ISO8601TimeConverter"); Object converter = c.newInstance(); Method registerIfAvailable = c.getDeclaredMethod("registerIfAvailable", Map.class, CommandLine.Tracer.class); System.setProperty("picocli.trace", "DEBUG"); CommandLine.Tracer tracer = new CommandLine.Tracer(); registerIfAvailable.invoke(converter, null, tracer); String expected = String.format("[picocli DEBUG] Could not register converter for java.sql.Time: java.lang.NullPointerException%n"); assertEquals(expected, systemErrRule.getLog()); systemErrRule.clearLog(); registerIfAvailable.invoke(null, null, tracer); assertEquals("logged only once", "", systemErrRule.getLog()); }
/** * @deprecated Please use * {@link SystemErrRule#enableLog() new SystemErrRule().enableLog()} * instead of * {@code new StandardErrorStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM)} or * {@link SystemErrRule#enableLog() new SystemErrRule().enableLog()}.{@link SystemErrRule#mute() mute()} * instead of {@code new StandardErrorStreamLog(LogMode.LOG_ONLY)}. * * <p>Creates a rule that records writes to the standard error stream * according to the specified {@code LogMode}. * * @param mode how the rule handles writes to the standard error stream. * @throws java.lang.NullPointerException if {@code mode} is null. */ public StandardErrorStreamLog(LogMode mode) { if (mode == null) throw new NullPointerException("The LogMode is missing."); systemErrRule.enableLog(); if (mode == LOG_ONLY) systemErrRule.mute(); }
public Statement apply(Statement base, Description description) { return systemErrRule.apply(base, description); } }
/** * @deprecated Please use * {@link org.junit.contrib.java.lang.system.SystemErrRule#clearLog()}. * * <p>Clears the log. The log can be used again. */ @Deprecated public void clear() { systemErrRule.clearLog(); }
private StartupErrorRule() { exit.expectSystemExitWithStatus(1); systemErr.enableLog(); systemOut.enableLog(); }
/** * @deprecated Please use * {@link SystemErrRule#enableLog() new SystemErrRule().enableLog()} * instead of * {@code new StandardErrorStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM)} or * {@link SystemErrRule#enableLog() new SystemErrRule().enableLog()}.{@link SystemErrRule#mute() mute()} * instead of {@code new StandardErrorStreamLog(LogMode.LOG_ONLY)}. * * <p>Creates a rule that records writes to the standard error stream * according to the specified {@code LogMode}. * * @param mode how the rule handles writes to the standard error stream. * @throws java.lang.NullPointerException if {@code mode} is null. */ public StandardErrorStreamLog(LogMode mode) { if (mode == null) throw new NullPointerException("The LogMode is missing."); systemErrRule.enableLog(); if (mode == LOG_ONLY) systemErrRule.mute(); }
public Statement apply(Statement base, Description description) { return systemErrRule.apply(base, description); } }
/** * @deprecated Please use * {@link org.junit.contrib.java.lang.system.SystemErrRule#clearLog()}. * * <p>Clears the log. The log can be used again. */ @Deprecated public void clear() { systemErrRule.clearLog(); }
private StartupErrorRule() { exit.expectSystemExitWithStatus(1); systemErr.enableLog(); systemOut.enableLog(); }
public void checkAssertion() { String expected = String.format("Missing required parameter: <commandLineFQCN>%n") + AUTO_COMPLETE_APP_USAGE; assertEquals(expected, systemErrRule.getLog()); } });
@Test public void testRegisterIfAvailableExceptionHandling() throws Exception { Class<?> c = Class.forName("picocli.CommandLine$BuiltIn"); Method registerIfAvailable = c.getDeclaredMethod("registerIfAvailable", Map.class, CommandLine.Tracer.class, String.class, String.class, String.class, Class[].class); System.setProperty("picocli.trace", "DEBUG"); CommandLine.Tracer tracer = new CommandLine.Tracer(); registerIfAvailable.invoke(null, null, tracer, "a.b.c", null, null, null); String expected = String.format("[picocli DEBUG] Could not register converter for a.b.c: java.lang.ClassNotFoundException: a.b.c%n"); assertEquals(expected, systemErrRule.getLog()); systemErrRule.clearLog(); registerIfAvailable.invoke(null, null, tracer, "a.b.c", null, null, null); assertEquals("logged only once", "", systemErrRule.getLog()); }
/** * @deprecated Please use * {@link SystemErrRule#enableLog() new SystemErrRule().enableLog()} * instead of * {@code new StandardErrorStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM)} or * {@link SystemErrRule#enableLog() new SystemErrRule().enableLog()}.{@link SystemErrRule#mute() mute()} * instead of {@code new StandardErrorStreamLog(LogMode.LOG_ONLY)}. * * <p>Creates a rule that records writes to the standard error stream * according to the specified {@code LogMode}. * * @param mode how the rule handles writes to the standard error stream. * @throws java.lang.NullPointerException if {@code mode} is null. */ public StandardErrorStreamLog(LogMode mode) { if (mode == null) throw new NullPointerException("The LogMode is missing."); systemErrRule.enableLog(); if (mode == LOG_ONLY) systemErrRule.mute(); }
public Statement apply(Statement base, Description description) { return systemErrRule.apply(base, description); } }
/** * @deprecated Please use * {@link org.junit.contrib.java.lang.system.SystemErrRule#clearLog()}. * * <p>Clears the log. The log can be used again. */ @Deprecated public void clear() { systemErrRule.clearLog(); }
public void checkAssertion() { assertEquals("", systemErrRule.getLog()); assertNotEquals(0, commandScript.length()); assertTrue(commandScript.delete()); } });
}; for (Runnable r : variations) { assertEquals("", systemErrRule.getLog()); assertEquals("", systemOutRule.getLog()); systemErrRule.clearLog(); systemOutRule.clearLog(); r.run(); assertEquals(expected, systemErrRule.getLog()); assertEquals("", systemOutRule.getLog()); systemErrRule.clearLog(); systemOutRule.clearLog(); assertEquals(expected, baos.toString()); assertEquals("", systemOutRule.getLog()); assertEquals("", systemErrRule.getLog());
@Override public Statement apply(final Statement base, final Description description) { // sys.out -> sys.err -> system exit return systemOut.apply( systemErr.apply( exit.apply(base, description), description), description); }
@Test public void testPrintTreeJavadocOption() throws Exception { final String expected = new String(Files.readAllBytes(Paths.get( getPath("InputMainExpectedInputJavadocComment.txt"))), StandardCharsets.UTF_8) .replaceAll("\\\\r\\\\n", "\\\\n").replaceAll("\r\n", "\n"); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", expected, systemOut.getLog().replaceAll("\\\\r\\\\n", "\\\\n") .replaceAll("\r\n", "\n")); assertEquals("Unexpected system error log", "", systemErr.getLog()); }); Main.main("-j", getPath("InputMainJavadocComment.javadoc")); }
}; for (Runnable r : variations) { assertEquals("", systemErrRule.getLog()); assertEquals("", systemOutRule.getLog()); systemErrRule.clearLog(); systemOutRule.clearLog(); r.run(); assertEquals(expected, systemErrRule.getLog()); assertEquals("", systemOutRule.getLog()); systemErrRule.clearLog(); systemOutRule.clearLog(); assertEquals(expected, baos.toString()); assertEquals("", systemOutRule.getLog()); assertEquals("", systemErrRule.getLog());