/*
   * Regular usage scenario - successful execution of system command.
   */
  @Test
  public void testExecute() throws Exception {
    String command = "java -version";
    tasklet.setCommand(command);
    tasklet.afterPropertiesSet();

    log.info("Executing command: " + command);
    RepeatStatus exitStatus = tasklet.execute(stepExecution.createStepContribution(), null);

    assertEquals(RepeatStatus.FINISHED, exitStatus);
  }
  /*
   * Failed execution scenario - error exit code returned by system command.
   */
  @Test
  public void testExecuteFailure() throws Exception {
    String command = "java org.springframework.batch.sample.tasklet.UnknownClass";
    tasklet.setCommand(command);
    tasklet.setTimeout(200L);
    tasklet.afterPropertiesSet();

    log.info("Executing command: " + command);
    try {
      StepContribution contribution = stepExecution.createStepContribution();
      RepeatStatus exitStatus = tasklet.execute(contribution, null);
      assertEquals(RepeatStatus.FINISHED, exitStatus);
      assertEquals(ExitStatus.FAILED, contribution.getExitStatus());
    } catch (RuntimeException e) {
      // on some platforms the system call does not return
      assertEquals("Execution of system command did not finish within the timeout", e.getMessage());
    }
  }
 public StepContribution createStepContribution() {
   return stepExecution.createStepContribution();
 }