### Question:
MD5HashFileGenerator implements HashFileGenerator, InitializingBean { @Override public Optional<String> hash(final Optional<URL> url) throws IOException { if (!url.isPresent()) { return Optional.absent(); } logger.debug("Calculating md5 hash, url:{}", url); if (isHotReloadModeOff()) { final String md5 = cache.getIfPresent(url.get()); logger.debug("md5 hash:{}", md5); if (md5 != null) { return Optional.of(md5); } } final InputStream is = url.get().openStream(); final String md5 = getMD5Checksum(is); if (isHotReloadModeOff()) { logger.debug("caching url:{} with hash:{}", url, md5); cache.put(url.get(), md5); } return Optional.fromNullable(md5); }  void afterPropertiesSet(); @Override Optional<String> hash(final Optional<URL> url); @Override Optional<String> hashMulti(final Collection<URL> urls); static String getMD5Checksum(final InputStream is); void setHotReloadMode(boolean hotReloadMode); void setCacheMaxSize(int cacheMaxSize); void setExpireAfterWrite(int expireAfterWrite); void setExpireAfterWriteUnit(String expireAfterWriteUnit); boolean isHotReloadMode(); int getCacheMaxSize(); int getExpireAfterWrite(); String getExpireAfterWriteUnit();  }### Answer:
@Test public void testAbsentUrlReturnsAbsentHash() throws Exception { Assert.assertFalse("absent url results in absent hash", hashFileGenerator.hash(Optional.<URL>absent()).isPresent()); }
@Test public void testReturnedHashMatchesDebugOff() throws Exception { final URL url = getClass().getClassLoader().getResource("templates/template1.soy"); final Optional<String> hash = hashFileGenerator.hash(Optional.of(url)); Assert.assertTrue(hash.isPresent()); Assert.assertEquals("md5 hash should match", "db9e0c4790bafb99c8c8cb9462279a75", hash.get()); }
@Test public void testReturnedHashMatchesDebugOffCacheSound() throws Exception { final URL url = getClass().getClassLoader().getResource("templates/template1.soy"); hashFileGenerator.hash(Optional.of(url)); Assert.assertEquals("a cache size should be 1", 1L, hashFileGenerator.cache.size()); Assert.assertEquals("cache should contain an entry", "db9e0c4790bafb99c8c8cb9462279a75", hashFileGenerator.cache.getIfPresent(url)); }