|
19 | 19 |
|
20 | 20 | import static org.junit.Assert.assertEquals; |
21 | 21 | import static org.junit.Assert.assertFalse; |
| 22 | +import static org.junit.Assert.assertNotNull; |
22 | 23 | import static org.junit.Assert.assertNull; |
23 | 24 | import static org.junit.Assert.assertTrue; |
24 | 25 | import static org.junit.Assert.fail; |
25 | 26 |
|
26 | 27 | import java.io.File; |
| 28 | +import java.io.FileInputStream; |
27 | 29 | import java.net.URL; |
28 | 30 | import java.util.Calendar; |
29 | 31 | import java.util.Date; |
@@ -159,13 +161,23 @@ public void testURLPattern() throws Exception |
159 | 161 | @Test |
160 | 162 | public void testExistingFilePattern() throws Exception |
161 | 163 | { |
162 | | - final Options options = PatternOptionBuilder.parsePattern("f<"); |
| 164 | + final Options options = PatternOptionBuilder.parsePattern("g<"); |
163 | 165 | final CommandLineParser parser = new PosixParser(); |
164 | | - final CommandLine line = parser.parse(options, new String[] { "-f", "test.properties" }); |
| 166 | + final CommandLine line = parser.parse(options, new String[] { "-g", "src/test/resources/existing-readable.file" }); |
| 167 | + |
| 168 | + final Object parsedReadableFileStream = line.getOptionObject("g"); |
| 169 | + |
| 170 | + assertNotNull("option g not parsed", parsedReadableFileStream); |
| 171 | + assertTrue("option g not FileInputStream", parsedReadableFileStream instanceof FileInputStream); |
| 172 | + } |
165 | 173 |
|
166 | | - assertEquals("f value", new File("test.properties"), line.getOptionObject("f")); |
| 174 | + @Test |
| 175 | + public void testExistingFilePatternFileNotExist() throws Exception { |
| 176 | + final Options options = PatternOptionBuilder.parsePattern("f<"); |
| 177 | + final CommandLineParser parser = new PosixParser(); |
| 178 | + final CommandLine line = parser.parse(options, new String[] { "-f", "non-existing.file" }); |
167 | 179 |
|
168 | | - // todo test if an error is returned if the file doesn't exists (when it's implemented) |
| 180 | + assertNull("option f parsed", line.getOptionObject("f")); |
169 | 181 | } |
170 | 182 |
|
171 | 183 | @Test |
|
0 commit comments