ParFileParser { public static String[] parse(InputStream inputStream) throws FastLdrException { List<String> files = new ArrayList<String>(); try { BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String line = null; while ((line = br.readLine()) != null) { if (line.startsWith("CONTROL")) { files.add(getSubstring(line)); } } } catch (FileNotFoundException e) { throw new FastLdrException(e); } catch (IOException e) { throw new FastLdrException(e); } return files.toArray(new String[files.size()]); }  static String[] parse(InputStream inputStream);  }
@Test public void testParseSingleLine() throws FastLdrException { String[] filePaths = ParFileParser.parse(new ByteArrayInputStream("CONTROL=/home/a/b".getBytes())); assertEquals(1, filePaths.length); assertEquals("/home/a/b", filePaths[0]); }
@Test public void testParseMultipleLines() throws FastLdrException { String[] filePaths = ParFileParser.parse(new ByteArrayInputStream("CONTROL=/home/a/b\nCONTROL=/home/c/d\n" .getBytes())); assertEquals(2, filePaths.length); assertEquals("/home/a/b", filePaths[0]); assertEquals("/home/c/d", filePaths[1]); }
@Test public void testParseWithComments() throws FastLdrException { String[] filePaths = ParFileParser.parse(new ByteArrayInputStream( "CONTROL=/home/a/b\n#CONTROL=/home/c/b\nCONTROL=/home/d/b\n".getBytes())); assertEquals(2, filePaths.length); assertEquals("/home/a/b", filePaths[0]); assertEquals("/home/d/b", filePaths[1]); }