DefaultHashEncoderNamingStrategy implements NamingStrategy { public String rename(final String originalName, final InputStream inputStream) throws IOException { notNull(originalName); notNull(inputStream); try (inputStream) { final String baseName = FilenameUtils.getBaseName(originalName); final String path = FilenameUtils.getPath(originalName); final String extension = FilenameUtils.getExtension(originalName); final String hash = getHashStrategy().getHash(inputStream); final StringBuilder sb = new StringBuilder(path).append(baseName).append("-").append(hash); if (!StringUtils.isEmpty(extension)) { sb.append(".").append(extension); } return sb.toString(); } }  String rename(final String originalName, final InputStream inputStream); static final String ALIAS; }
@Test(expected = NullPointerException.class) public void cannotAcceptNullResourceName() throws Exception { namingStrategy.rename(null, WroUtil.EMPTY_STREAM); }
@Test(expected = NullPointerException.class) public void cannotAcceptNullStream() throws Exception { namingStrategy.rename("fileName.js", null); }
@Test public void shouldRenameResourceWithEmptyContent() throws Exception { final String result = namingStrategy.rename("fileName", WroUtil.EMPTY_STREAM); assertEquals("fileName-da39a3ee5e6b4b0d3255bfef95601890afd80709", result); }
@Test public void shouldRenameResourceWithSomeContent() throws Exception { final String result = namingStrategy.rename("anotherFile.js", new ByteArrayInputStream("someContent".getBytes())); assertEquals("anotherFile-99ef8ae827896f2af4032d5dab9298ec86309abf.js", result); }
@Test public void shouldRenameResourceContainedInAFolder() throws Exception { final String result = namingStrategy.rename("folder1/folder2/resource.css", new ByteArrayInputStream("someContent".getBytes())); assertEquals("folder1/folder2/resource-99ef8ae827896f2af4032d5dab9298ec86309abf.css", result); }