congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
CommandLine$ExecutionException.getMessage
Code IndexAdd Tabnine to your IDE (free)

How to use
getMessage
method
in
picocli.CommandLine$ExecutionException

Best Java code snippets using picocli.CommandLine$ExecutionException.getMessage (Showing top 20 results out of 315)

origin: remkop/picocli

@Test
public void testCommandMethodsUnexpectedError() throws Exception {
  Method method = CommandMethod1.class.getDeclaredMethod("times", int.class, int.class);
  CommandLine cmd = new CommandLine(method);
  Method execute = CommandLine.class.getDeclaredMethod("execute", CommandLine.class, List.class);
  execute.setAccessible(true);
  try {
    execute.invoke(null, cmd, null);
  } catch (InvocationTargetException ex) {
    ExecutionException actual = (ExecutionException) ex.getCause();
    assertTrue(actual.getMessage(), actual.getMessage().startsWith("Unhandled error while calling command ("));
  }
}
origin: remkop/picocli

@Test
public void testCallWithFactory() {
  Runnable[] variations = new Runnable[] {
      new Runnable() {public void run() {CommandLine.call(MyCallable.class, new InnerClassFactory(this), "-x", "a");}},
      new Runnable() {public void run() {CommandLine.call(MyCallable.class, new InnerClassFactory(this), System.out, "-x", "a");}},
      new Runnable() {public void run() {CommandLine.call(MyCallable.class, new InnerClassFactory(this), System.out, Help.Ansi.OFF, "-x", "a");}},
      new Runnable() {public void run() {CommandLine.call(MyCallable.class, new InnerClassFactory(this), System.out, System.out, Help.Ansi.OFF, "-x", "a");}},
  };
  for (Runnable r : variations) {
    try {
      r.run();
    } catch (ExecutionException ex) {
      assertTrue(ex.getMessage().startsWith("Error while calling command (picocli.CommandLineParseWithHandlersTest$MyCallable"));
      assertTrue(ex.getCause() instanceof IllegalStateException);
      assertEquals("this is a test", ex.getCause().getMessage());
    }
  }
}
origin: remkop/picocli

@SuppressWarnings("deprecation")
private void verifyAllFail(Factory factory, String prefix, String suffix, String[] args) {
  IParseResultHandler[] handlers = new IParseResultHandler[] {
      new RunFirst(), new RunLast(), new RunAll()
  };
  for (IParseResultHandler handler : handlers) {
    String descr = handler.getClass().getSimpleName();
    try {
      new CommandLine(factory.create()).parseWithHandler(handler, System.out, args);
      fail(descr + ": expected exception");
    } catch (ExecutionException ex) {
      String actual = ex.getMessage();
      assertTrue(descr + ": " + actual, actual.startsWith(prefix));
      assertTrue(descr + ": " + actual, actual.endsWith(suffix));
    }
  }
}
origin: info.picocli/picocli

@Test
public void testExecutionExceptionIfRunnableThrowsExecutionException() {
  @Command
  class App implements Runnable {
    @Spec CommandSpec spec;
    public void run() {
      throw new ExecutionException(spec.commandLine(), "abc");
    }
  }
  try {
    CommandLine.run(new App());
  } catch (ExecutionException ex) {
    assertEquals("abc", ex.getMessage());
  }
}
origin: info.picocli/picocli

@Test
public void testExecutionExceptionIfCallableThrowsExecutionException() {
  @Command
  class App implements Callable<Void> {
    @Spec CommandSpec spec;
    public Void call() {
      throw new ExecutionException(spec.commandLine(), "abc");
    }
  }
  try {
    CommandLine.call(new App());
  } catch (ExecutionException ex) {
    assertEquals("abc", ex.getMessage());
  }
}
origin: info.picocli/picocli

@Test
public void testHandlerThrowsExecutionException() {
  @Command
  class App { }
  try {
    new CommandLine(new App()).parseWithHandler(new IParseResultHandler2<Object>() {
      public Object handleParseResult(ParseResult parseResult) throws ExecutionException {
        throw new ExecutionException(new CommandLine(new App()), "xyz");
      }
    }, new String[0]);
  } catch (ExecutionException ex) {
    assertEquals("xyz", ex.getMessage());
  }
}
origin: info.picocli/picocli

@Test
public void testCommandMethodsUnexpectedError() throws Exception {
  Method method = CommandMethod1.class.getDeclaredMethod("times", int.class, int.class);
  CommandLine cmd = new CommandLine(method);
  Method execute = CommandLine.class.getDeclaredMethod("execute", CommandLine.class, List.class);
  execute.setAccessible(true);
  try {
    execute.invoke(null, cmd, null);
  } catch (InvocationTargetException ex) {
    ExecutionException actual = (ExecutionException) ex.getCause();
    assertTrue(actual.getMessage(), actual.getMessage().startsWith("Unhandled error while calling command ("));
  }
}
origin: info.picocli/picocli

@Test
public void testCall1DefaultExceptionHandlerRethrows() {
  try {
    CommandLine.call(new MyCallable(), "-x abc");
  } catch (ExecutionException ex) {
    String cmd = ex.getCommandLine().getCommand().toString();
    String msg = "Error while calling command (" + cmd + "): java.lang.IllegalStateException: this is a test";
    assertEquals(msg, ex.getMessage());
  }
  assertEquals("", systemErrRule.getLog());
  assertEquals("", systemOutRule.getLog());
}
origin: info.picocli/picocli

@Test
public void testFailingVersionProvider() {
  @Command(versionProvider = FailingVersionProvider.class)
  class App {}
  CommandLine cmd = new CommandLine(new App());
  try {
    cmd.printVersionHelp(System.out);
    fail("Expected exception");
  } catch (ExecutionException ex) {
    assertEquals("Could not get version info from " + cmd.getCommandSpec().versionProvider() + ": java.lang.IllegalStateException: sorry can't give you a version", ex.getMessage());
  }
}
origin: info.picocli/picocli

@Test
public void testCommandMethodsWhereConstructorThrowsException() {
  try {
    CommandLine.invoke("cannotBeCalled", ErroringCommand.class);
  } catch (ExecutionException ex) { // InvocationTargetException when invoking constructor
    assertTrue(ex.getCause() instanceof IllegalStateException);
    assertTrue(ex.getMessage(), ex.getMessage().startsWith("Error while calling command ("));
  }
}
origin: info.picocli/picocli

@Test
public void testCommandMethodsThatThrowsExecutionException() {
  try {
    CommandLine.invoke("throwsExecutionException", StaticMethodCommand.class);
  } catch (ExecutionException ex) {
    assertEquals("abc", ex.getMessage());
  }
}
origin: remkop/picocli

@Test
public void testHandlerThrowsExecutionException2() {
  @Command
  class App { }
  IParseResultHandler2<Void> handler = new IParseResultHandler2<Void>() {
    public Void handleParseResult(ParseResult parseResult) throws ExecutionException {
      throw new ExecutionException(new CommandLine(new App()), "xyz");
    }
  };
  IExceptionHandler2<Void> exceptionHandler = new IExceptionHandler2<Void>() {
    public Void handleParseException(ParameterException ex, String[] args) {
      return null;
    }
    public Void handleExecutionException(ExecutionException ex, ParseResult parseResult) {
      return null;
    }
  };
  try {
    new CommandLine(new App()).parseWithHandlers(handler, exceptionHandler, new String[0]);
  } catch (ExecutionException ex) {
    assertEquals("xyz", ex.getMessage());
  }
}
origin: remkop/picocli

@Test
public void testRunWithFactory() {
  Runnable[] variations = new Runnable[] {
      new Runnable() {public void run() {CommandLine.run(MyRunnable.class, new InnerClassFactory(this), "-x", "a");}},
      new Runnable() {public void run() {CommandLine.run(MyRunnable.class, new InnerClassFactory(this), System.out, "-x", "a");}},
      new Runnable() {public void run() {CommandLine.run(MyRunnable.class, new InnerClassFactory(this), System.out, Help.Ansi.OFF, "-x", "a");}},
      new Runnable() {public void run() {CommandLine.run(MyRunnable.class, new InnerClassFactory(this), System.out, System.out, Help.Ansi.OFF, "-x", "a");}},
  };
  for (Runnable r : variations) {
    try {
      r.run();
    } catch (ExecutionException ex) {
      assertTrue(ex.getMessage(), ex.getMessage().startsWith("Error while running command (picocli.CommandLineParseWithHandlersTest$MyRunnable"));
      assertTrue(ex.getCause() instanceof IllegalStateException);
      assertEquals("this is a test", ex.getCause().getMessage());
    }
  }
}
origin: remkop/picocli

@Test
public void testExecutionExceptionIfRunnableThrowsExecutionException() {
  @Command
  class App implements Runnable {
    @Spec CommandSpec spec;
    public void run() {
      throw new ExecutionException(spec.commandLine(), "abc");
    }
  }
  try {
    CommandLine.run(new App());
  } catch (ExecutionException ex) {
    assertEquals("abc", ex.getMessage());
  }
}
origin: remkop/picocli

@Test
public void testExecutionExceptionIfCallableThrowsExecutionException() {
  @Command
  class App implements Callable<Void> {
    @Spec CommandSpec spec;
    public Void call() {
      throw new ExecutionException(spec.commandLine(), "abc");
    }
  }
  try {
    CommandLine.call(new App());
  } catch (ExecutionException ex) {
    assertEquals("abc", ex.getMessage());
  }
}
origin: remkop/picocli

@Test
public void testHandlerThrowsExecutionException() {
  @Command
  class App { }
  try {
    new CommandLine(new App()).parseWithHandler(new IParseResultHandler2<Object>() {
      public Object handleParseResult(ParseResult parseResult) throws ExecutionException {
        throw new ExecutionException(new CommandLine(new App()), "xyz");
      }
    }, new String[0]);
  } catch (ExecutionException ex) {
    assertEquals("xyz", ex.getMessage());
  }
}
origin: remkop/picocli

@Test
public void testFailingVersionProvider() {
  @Command(versionProvider = FailingVersionProvider.class)
  class App {}
  CommandLine cmd = new CommandLine(new App());
  try {
    cmd.printVersionHelp(System.out);
    fail("Expected exception");
  } catch (ExecutionException ex) {
    assertEquals("Could not get version info from " + cmd.getCommandSpec().versionProvider() + ": java.lang.IllegalStateException: sorry can't give you a version", ex.getMessage());
  }
}
origin: remkop/picocli

@Test
public void testCall1DefaultExceptionHandlerRethrows() {
  try {
    CommandLine.call(new MyCallable(), "-x abc");
  } catch (ExecutionException ex) {
    String cmd = ex.getCommandLine().getCommand().toString();
    String msg = "Error while calling command (" + cmd + "): java.lang.IllegalStateException: this is a test";
    assertEquals(msg, ex.getMessage());
  }
  assertEquals("", systemErrRule.getLog());
  assertEquals("", systemOutRule.getLog());
}
origin: remkop/picocli

@Test
public void testCommandMethodsWhereConstructorThrowsException() {
  try {
    CommandLine.invoke("cannotBeCalled", ErroringCommand.class);
  } catch (ExecutionException ex) { // InvocationTargetException when invoking constructor
    assertTrue(ex.getCause() instanceof IllegalStateException);
    assertTrue(ex.getMessage(), ex.getMessage().startsWith("Error while calling command ("));
  }
}
origin: remkop/picocli

@Test
public void testCommandMethodsThatThrowsExecutionException() {
  try {
    CommandLine.invoke("throwsExecutionException", StaticMethodCommand.class);
  } catch (ExecutionException ex) {
    assertEquals("abc", ex.getMessage());
  }
}
picocliCommandLine$ExecutionExceptiongetMessage

Popular methods of CommandLine$ExecutionException

  • <init>
  • getCause
  • getCommandLine
  • printStackTrace

Popular in Java

  • Reading from database using SQL prepared statement
  • onRequestPermissionsResult (Fragment)
  • startActivity (Activity)
  • addToBackStack (FragmentTransaction)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now