RunScriptOnNodeAsInitScriptUsingSsh extends SudoAwareInitManager implements RunScriptOnNode { @Override public ExecResponse call() { checkState(ssh != null, "please call init() before invoking call"); try { ssh.connect(); ExecResponse returnVal = doCall(); eventBus.post(new StatementOnNodeCompletion(init, node, returnVal)); return returnVal; } finally { if (ssh != null) ssh.disconnect(); } } @AssistedInject  RunScriptOnNodeAsInitScriptUsingSsh(Function<NodeMetadata, SshClient> sshFactory, EventBus eventBus,
            InitScriptConfigurationForTasks initScriptConfiguration, @Assisted NodeMetadata node,
            @Assisted Statement script, @Assisted RunScriptOptions options); @Override RunScriptOnNodeAsInitScriptUsingSsh init(); @Override ExecResponse call(); static InitScript createInitScript(InitScriptConfigurationForTasks config, String name, Statement script);  }
@Test(expectedExceptions = IllegalStateException.class) public void testWithoutInitThrowsIllegalStateException() { Statement command = exec("doFoo"); NodeMetadata node = new NodeMetadataBuilder().ids("id").status(Status.RUNNING).credentials( LoginCredentials.builder().user("tester").password("notalot").build()).build(); SshClient sshClient = createMock(SshClient.class); replay(sshClient); RunScriptOnNodeAsInitScriptUsingSsh testMe = new RunScriptOnNodeAsInitScriptUsingSsh(Functions .forMap(ImmutableMap.of(node, sshClient)), eventBus, InitScriptConfigurationForTasks.create() .appendIncrementingNumberToAnonymousTaskNames(), node, command, new RunScriptOptions()); testMe.call(); }