### Question:
LibraryIdentifier { public static LibraryIdentifier fromFilename(String filename) { String fileNameWithOutExt = new File(filename).getName().replaceFirst("[.][^.]+$", ""); Pattern versionPattern = Pattern.compile("-[0-9]+(?:.[0-9]+(?:.[0-9]+)?)?(?:-[0-9]+)?$"); Matcher m = versionPattern.matcher(fileNameWithOutExt); String sName = null; String sVersion = null; if (m.find()) { sName = fileNameWithOutExt.substring(0, m.start()); sVersion = m.group().substring(1); return new LibraryIdentifier(sName, sVersion); } else { sName = fileNameWithOutExt; return new LibraryIdentifier(sName, (LibraryVersion) null); } } LibraryIdentifier(String name);  LibraryIdentifier(String name, String version);  LibraryIdentifier(String name, LibraryVersion version); static LibraryIdentifier fromFilename(String filename); LibraryVersion getVersion(); String getName(); @Override String toString(); boolean equals(LibraryIdentifier i); @Override boolean equals(Object o); @Override int hashCode(); static final String MANIFEST_LIBRARY_NAME_ATTRIBUTE; static final String MANIFEST_LIBRARY_VERSION_ATTRIBUTE; }### Answer:
@Test public void testFromFilename() { try { LibraryIdentifier testFull = LibraryIdentifier .fromFilename("service/i5.las2peer.services.testService-4.2.jar"); Assert.assertEquals("i5.las2peer.services.testService", testFull.getName()); Assert.assertEquals("4.2", testFull.getVersion().toString()); LibraryIdentifier testTripleVersion = LibraryIdentifier .fromFilename("i5.las2peer.services.testService-4.2.0.jar"); Assert.assertEquals("i5.las2peer.services.testService", testTripleVersion.getName()); Assert.assertEquals("4.2.0", testTripleVersion.getVersion().toString()); LibraryIdentifier testDoubleVersion = LibraryIdentifier .fromFilename("i5.las2peer.services.testService-4.2.jar"); Assert.assertEquals("i5.las2peer.services.testService", testDoubleVersion.getName()); Assert.assertEquals("4.2", testDoubleVersion.getVersion().toString()); LibraryIdentifier testSingleVersion = LibraryIdentifier .fromFilename("i5.las2peer.services.testService-4.jar"); Assert.assertEquals("i5.las2peer.services.testService", testSingleVersion.getName()); Assert.assertEquals("4", testSingleVersion.getVersion().toString()); LibraryIdentifier testNoVersion = LibraryIdentifier.fromFilename("i5.las2peer.services.testService.jar"); Assert.assertEquals("i5.las2peer.services.testService", testNoVersion.getName()); Assert.assertNull(testNoVersion.getVersion()); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.toString()); } }