use of org.apache.hadoop.fs.shell.Command in project hadoop by apache.
the class TestFsShell method testExceptionNullMessage.
@Test
public void testExceptionNullMessage() throws Exception {
final String cmdName = "-cmdExNullMsg";
final Command cmd = Mockito.mock(Command.class);
Mockito.when(cmd.run(Mockito.anyVararg())).thenThrow(new IllegalArgumentException());
Mockito.when(cmd.getUsage()).thenReturn(cmdName);
final CommandFactory cmdFactory = Mockito.mock(CommandFactory.class);
final String[] names = { cmdName };
Mockito.when(cmdFactory.getNames()).thenReturn(names);
Mockito.when(cmdFactory.getInstance(cmdName)).thenReturn(cmd);
FsShell shell = new FsShell(new Configuration());
shell.commandFactory = cmdFactory;
try (GenericTestUtils.SystemErrCapturer capture = new GenericTestUtils.SystemErrCapturer()) {
ToolRunner.run(shell, new String[] { cmdName });
Assert.assertThat(capture.getOutput(), StringContains.containsString(cmdName + ": Null exception message"));
}
}
use of org.apache.hadoop.fs.shell.Command in project hadoop by apache.
the class FsShell method displayError.
private void displayError(String cmd, String message) {
for (String line : message.split("\n")) {
System.err.println(cmd + ": " + line);
if (cmd.charAt(0) != '-') {
Command instance = null;
instance = commandFactory.getInstance("-" + cmd);
if (instance != null) {
System.err.println("Did you mean -" + cmd + "? This command " + "begins with a dash.");
}
}
}
}
Aggregations