V2LibraryAliasGenerator implements NameGenerator<Library> { @Override public String generate(Library library) throws MisoNamingException, IOException { if (!isDetailedLibrary(library)) { throw new MisoNamingException("Can only generate an alias for detailed libraries"); } DetailedSample tissue = getParent(SampleTissue.class, (DetailedSample) library.getSample()); String partialAlias = tissue.getAlias() + "_LB"; int next = siblingNumberGenerator.getFirstAvailableSiblingNumber(LibraryImpl.class, partialAlias); String siblingNumber = zeroPad(next, 2); return partialAlias + siblingNumber; }  void setSiblingNumberGenerator(SiblingNumberGenerator siblingNumberGenerator); @Override String generate(Library library);  }
@Test public void testGenerate() throws Exception { Library lib = constructHierarchy("0123", "04"); mockFirstAvailableSiblingNumber(7); assertEquals("TEST_0123_04_LB07", sut.generate(lib)); }
@Test public void testGenerateForShortIdentityNumber() throws Exception { Library lib = constructHierarchy("123", "05"); mockFirstAvailableSiblingNumber(8); assertEquals("TEST_123_05_LB08", sut.generate(lib)); }
@Test public void testGenerateForLongIdentityNumber() throws Exception { Library lib = constructHierarchy("012345", "06"); mockFirstAvailableSiblingNumber(12); assertEquals("TEST_012345_06_LB12", sut.generate(lib)); }
@Test public void testGenerateForLongLibraryNumber() throws Exception { Library lib = constructHierarchy("0123", "07"); mockFirstAvailableSiblingNumber(1234); assertEquals("TEST_0123_07_LB1234", sut.generate(lib)); }