@Test public void canParseAnyFilenameThatStartsWithANumber() throws Exception { FilenameParser parser = new FilenameParser(); assertEquals(1L, parser.extractIdFromFilename("0001_a_filename.txt")); assertEquals(1L, parser.extractIdFromFilename("1_a_filename.txt")); assertEquals(1L, parser.extractIdFromFilename("1 a filename.txt")); assertEquals(1L, parser.extractIdFromFilename("1.txt")); assertEquals(123L, parser.extractIdFromFilename("00123_something.txt")); }
public long extractIdFromFilename(String filename) throws UnrecognisedFilenameException { Matcher matches = pattern.matcher(filename); if (!matches.matches() || matches.groupCount() != 1) throw new UnrecognisedFilenameException("Could not extract a change script number from filename: " + filename); return Long.parseLong(matches.group(1)); }
FilenameParser { public long extractIdFromFilename(String filename) throws UnrecognisedFilenameException { Matcher matches = pattern.matcher(filename); if (!matches.matches() || matches.groupCount() != 1) throw new UnrecognisedFilenameException("Could not extract a change script number from filename: " + filename); return Long.parseLong(matches.group(1)); } }
FilenameParser { public long extractIdFromFilename(String filename) throws UnrecognisedFilenameException { Matcher matches = pattern.matcher(filename); if (!matches.matches() || matches.groupCount() != 1) throw new UnrecognisedFilenameException("Could not extract a change script number from filename: " + filename); return Long.parseLong(matches.group(1)); } FilenameParser(); }
FilenameParser { public long extractIdFromFilename(String filename) throws UnrecognisedFilenameException { Matcher matches = pattern.matcher(filename); if (!matches.matches() || matches.groupCount() != 1) throw new UnrecognisedFilenameException("Could not extract a change script number from filename: " + filename); return Long.parseLong(matches.group(1)); } FilenameParser(); long extractIdFromFilename(String filename); }
FilenameParser { public long extractIdFromFilename(String filename) throws UnrecognisedFilenameException { Matcher matches = pattern.matcher(filename); if (!matches.matches() || matches.groupCount() != 1) throw new UnrecognisedFilenameException("Could not extract a change script number from filename: " + filename); return Long.parseLong(matches.group(1)); } FilenameParser(); long extractIdFromFilename(String filename);  }