CachingTilesContainer extends TilesContainerWrapper implements MutableTilesContainer { @Override public boolean isValidDefinition(String definition, Request request) { if (getCustomDefinition(definition, request) != null) { return true; } return super.isValidDefinition(definition, request); } CachingTilesContainer(TilesContainer originalContainer);  CachingTilesContainer(TilesContainer originalContainer, String definitionsAttributeName); Definition getDefinition(String definition,
            Request request); @Override boolean isValidDefinition(String definition, Request request); @Override void register(Definition definition, Request request); @Override void render(String definition, Request request);  }
@SuppressWarnings("unchecked") @Test public void testIsValidDefinition() { Request request = createMock(Request.class); Map<String, Definition> definitions = createMock(Map.class); Map<String, Object> scope = createMock(Map.class); Definition definition = createMock(Definition.class); expect(request.getContext("request")).andReturn(scope); expect(scope.get(DEFAULT_DEFINITIONS_ATTRIBUTE_NAME)).andReturn( definitions); expect(definitions.get("definition")).andReturn(definition); replay(wrapped, request, definitions, scope, definition); assertTrue(container.isValidDefinition("definition", request)); verify(wrapped, request, definitions, scope, definition); }
@SuppressWarnings("unchecked") @Test public void testIsValidDefinitionContainer() { Request request = createMock(Request.class); Map<String, Definition> definitions = createMock(Map.class); Map<String, Object> scope = createMock(Map.class); expect(request.getContext("request")).andReturn(scope); expect(scope.get(DEFAULT_DEFINITIONS_ATTRIBUTE_NAME)).andReturn( definitions); expect(definitions.get("definition")).andReturn(null); expect(wrapped.isValidDefinition("definition", request)).andReturn(true); replay(wrapped, request, definitions, scope); assertTrue(container.isValidDefinition("definition", request)); verify(wrapped, request, definitions, scope); }