}
public void testCachedException() throws Exception
{
MockTemplateLoader loader = new MockTemplateLoader();
TemplateCache cache = new TemplateCache(loader, new StrongCacheStorage());
cache.setDelay(1000L);
loader.setThrowException(true);
try
{
cache.getTemplate("t", Locale.getDefault(), "", true);
fail();
}
catch(IOException e)
{
assertEquals("mock IO exception", e.getMessage());
assertEquals(1, loader.getFindCount());
try
{
cache.getTemplate("t", Locale.getDefault(), "", true);
fail();
}
catch(IOException e2)
{
// Still 1 - returned cached exception
assertEquals("There was an error loading the template on an " +
"earlier attempt; it is attached as a cause", e2.getMessage());
assertSame(e, e2.getCause());
assertEquals(1, loader.getFindCount());
try
{
Thread.sleep(1100L);
cache.getTemplate("t", Locale.getDefault(), "", true);
fail();
}
catch(IOException e3)
{
// Cache had to retest