BATCH-1705: add try/catch around stdin access

This commit is contained in:
Dave Syer
2011-03-15 09:18:19 +00:00
parent 3e3cfa1dff
commit a2e831cf6d
2 changed files with 34 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.core.launch.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
@@ -136,6 +137,22 @@ public class CommandLineJobRunnerTests {
assertEquals(new JobParameters(), StubJobLauncher.jobParameters);
}
@Test
public void testWithInvalidStdin() throws Throwable {
System.setIn(new InputStream() {
public int available() throws IOException {
throw new IOException("Planned");
}
public int read() {
return -1;
}
});
CommandLineJobRunner.main(new String[] { jobPath, jobName });
assertEquals(0, StubSystemExiter.status);
assertEquals(0, StubJobLauncher.jobParameters.getParameters().size());
}
@Test
public void testWithStdinCommandLine() throws Throwable {
System.setIn(new InputStream() {