@Test public void throwsWhenFilenameDoesNotStartWithANumber() throws Exception { FilenameParser parser = new FilenameParser(); try { parser.extractIdFromFilename("blah blah blah"); fail("expected exception"); } catch (UnrecognisedFilenameException e) { assertEquals("Could not extract a change script number from filename: blah blah blah", e.getMessage() ); } }
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);  }