@Test
public void testRefreshRequired() throws URISyntaxException, IOException, InterruptedException {

    // Set up multiple data sources.
    Map<String, Attribute> attribs = new HashMap<String, Attribute>();
    attribs.put("testparm", new Attribute("testval"));
    Definition rewriteTest = new Definition("rewrite.test", Attribute.createTemplateAttribute("/test.jsp"), attribs);
    expect(dao.getDefinition("rewrite.test", null)).andReturn(rewriteTest);
    replay(dao);
    List<ApplicationResource> sources = new ArrayList<ApplicationResource>();
    sources.add(resource);
    dao.setSources(sources);
    DefinitionsReader reader = new DigesterDefinitionsReader();
    dao.setReader(reader);
    Request context = createMock(Request.class);
    expect(context.getContext("session")).andReturn(new HashMap<String, Object>()).anyTimes();
    expect(context.getRequestLocale()).andReturn(null).anyTimes();
    replay(context);
    Definition definition = dao.getDefinition("rewrite.test", null);
    assertNotNull("rewrite.test definition not found.", definition);
    assertEquals("Incorrect initial template value", "/test.jsp", definition.getTemplateAttribute().getValue());
    RefreshMonitor reloadable = dao;
    dao.loadDefinitionsFromResource(resource);
    assertEquals("Factory should be fresh.", false, reloadable.refreshRequired());
    // Make sure the system actually updates the timestamp.
    Thread.sleep(SLEEP_MILLIS);
    // Set up multiple data sources.
    resource.modify("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n" + "<!DOCTYPE tiles-definitions PUBLIC "
            + "\"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN\" "
            + "\"http://tiles.apache.org/dtds/tiles-config_3_0.dtd\">\n\n" + "<tiles-definitions>"
            + "<definition name=\"rewrite.test\" template=\"/newtest.jsp\">"
            + "<put-attribute name=\"testparm\" value=\"testval\"/>" + "</definition>" //
            + "</tiles-definitions>");
    assertEquals("Factory should be stale.", true, reloadable.refreshRequired());
    verify(context, dao);
}