BagitManifestFormatter extends ManifestFormatterBase { @Override public ManifestItem parseLine(String line) throws ParseException { Matcher matcher = LINE_PATTERN.matcher(line); if (!matcher.find()) { throw new ParseException("Line doesn't match bagit format: unable to parse line: ->" + line + "<-", 0); } ManifestItem item = new ManifestItem(); item.setContentChecksum(matcher.group(1)); item.setSpaceId(matcher.group(2)); item.setContentId(matcher.group(3)); return item; }  @Override String getHeader(); @Override ManifestItem parseLine(String line);  }
@Test public void testParseLine() throws Exception { String checksum = "checksum"; String spaceId = "spaceid"; String contentId = "contentid"; String line = formatter.formatLine(checksum, spaceId, contentId); ManifestItem item = formatter.parseLine(line); Assert.assertEquals(checksum, item.getContentChecksum()); Assert.assertEquals(contentId, item.getContentId()); Assert.assertEquals(spaceId, item.getSpaceId()); }
@Test public void testParseLineFailure() { String line = "invalid line"; try { formatter.parseLine(line); Assert.fail("parse line method should have failed."); } catch (ParseException e) { Assert.assertTrue("expected failure", true); } }