@Test
public void testRedoWithNegativeCmdNumber() throws Exception {

    final ZooKeeper zk = createClient();
    ZooKeeperMain zkMain = new ZooKeeperMain(zk);
    String cmd1 = "redo -1";
    // setup redirect out/err streams to get System.in/err, use this
    // judiciously!
    final PrintStream systemErr = System.err; // get current err
    final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
    System.setErr(new PrintStream(errContent));
    try {
        zkMain.executeLine(cmd1);
        Assert.assertEquals("Command index out of range", errContent
                .toString().trim());
    } finally {
        // revert redirect of out/err streams - important step!
        System.setErr(systemErr);
    }
}