/** * The given response will be used the first time the cmdRegex matches, and not again. * (However if concurrent executions are happening, multiple may match and use this generator). */ public static void setCustomOneOffResponse(String cmdRegex, CustomResponse response) { setCustomOneOffResponse(cmdRegex, checkNotNull(response, "response").toGenerator()); }
@Test public void testCustomOneOffResponse() throws Exception { RecordingSshTool.setCustomOneOffResponse(".*mycmd.*", new CustomResponse(1, "mystdout", "mystderr")); ExecResult result1 = execScript(machine, "mycmd"); ExecResult result2 = execScript(machine, "mycmd"); assertEquals(result1, new ExecResult(1, "mystdout", "mystderr")); assertEquals(result2, new ExecResult(0, "", "")); }