@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()); }
@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()); }
@Test public void testMultipleUsageHelpOptions() { setTraceLevel("WARN"); CommandSpec cmd = CommandSpec.create() .add(OptionSpec.builder("-x").type(boolean.class).usageHelp(true).build()) .add(OptionSpec.builder("-h").type(boolean.class).usageHelp(true).build()); assertEquals("", systemErrRule.getLog()); systemErrRule.clearLog(); new CommandLine(cmd); assertEquals("", systemOutRule.getLog()); assertEquals(String.format("[picocli WARN] Multiple options [-x, -h] are marked as 'usageHelp=true'. Usually a command has only one --help option that triggers display of the usage help message. Alternatively, consider using @Command(mixinStandardHelpOptions = true) on your command instead.%n"), systemErrRule.getLog()); }
@Test public void testMultipleVersionHelpOptions() { setTraceLevel("WARN"); CommandSpec cmd = CommandSpec.create() .add(OptionSpec.builder("-x").type(boolean.class).versionHelp(true).build()) .add(OptionSpec.builder("-V").type(boolean.class).versionHelp(true).build()); assertEquals("", systemErrRule.getLog()); systemErrRule.clearLog(); new CommandLine(cmd); assertEquals("", systemOutRule.getLog()); assertEquals(String.format("[picocli WARN] Multiple options [-x, -V] are marked as 'versionHelp=true'. Usually a command has only one --version option that triggers display of the version information. Alternatively, consider using @Command(mixinStandardHelpOptions = true) on your command instead.%n"), systemErrRule.getLog()); }
/** * @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(); }
/** * @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(); }
/** * @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(); }
@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()); }
@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()); }
@Test public void testMultipleUsageHelpOptions() { setTraceLevel("WARN"); CommandSpec cmd = CommandSpec.create() .add(OptionSpec.builder("-x").type(boolean.class).usageHelp(true).build()) .add(OptionSpec.builder("-h").type(boolean.class).usageHelp(true).build()); assertEquals("", systemErrRule.getLog()); systemErrRule.clearLog(); new CommandLine(cmd); assertEquals("", systemOutRule.getLog()); assertEquals(String.format("[picocli WARN] Multiple options [-x, -h] are marked as 'usageHelp=true'. Usually a command has only one --help option that triggers display of the usage help message. Alternatively, consider using @Command(mixinStandardHelpOptions = true) on your command instead.%n"), systemErrRule.getLog()); }
@Test public void testMultipleVersionHelpOptions() { setTraceLevel("WARN"); CommandSpec cmd = CommandSpec.create() .add(OptionSpec.builder("-x").type(boolean.class).versionHelp(true).build()) .add(OptionSpec.builder("-V").type(boolean.class).versionHelp(true).build()); assertEquals("", systemErrRule.getLog()); systemErrRule.clearLog(); new CommandLine(cmd); assertEquals("", systemOutRule.getLog()); assertEquals(String.format("[picocli WARN] Multiple options [-x, -V] are marked as 'versionHelp=true'. Usually a command has only one --version option that triggers display of the version information. Alternatively, consider using @Command(mixinStandardHelpOptions = true) on your command instead.%n"), systemErrRule.getLog()); }