@Test public void paste() throws IOException, InterruptedException { final PipedOutputStream outputStream = new PipedOutputStream(); PipedInputStream pipedInputStream = new PipedInputStream(outputStream); String pasteLine1 = "connect" + Config.getLineSeparator() + "admin" + Config.getLineSeparator() + "admin!"; String pasteLine2 = "234" + Config.getLineSeparator() + "exit" + Config.getLineSeparator(); final Console console = getTestConsole(pipedInputStream); console.setConsoleCallback( new AeshConsoleCallback() { boolean password = false; @Override public int execute(ConsoleOperation output) { if (output.getBuffer().equals("admin")) { console.setPrompt(new Prompt("", new Character('\u0000'))); password = true; return 0; } if (password) { assertEquals("admin!234", output.getBuffer()); password = false; } return 0; } }); console.start(); outputStream.write(pasteLine1.getBytes()); outputStream.write(pasteLine2.getBytes()); Thread.sleep(500); console.stop(); }
@Override public CommandResult execute(CommandInvocation commandInvocation) throws IOException { if (help) { commandInvocation.getShell().out().print(commandInvocation.getHelpInfo("cd")); return CommandResult.SUCCESS; } if (arguments == null) { updatePrompt( commandInvocation, commandInvocation .getAeshContext() .getCurrentWorkingDirectory() .newInstance(Config.getHomeDir())); } else { List<Resource> files = arguments.get(0).resolve(commandInvocation.getAeshContext().getCurrentWorkingDirectory()); if (files.get(0).isDirectory()) updatePrompt(commandInvocation, files.get(0)); } return CommandResult.SUCCESS; }