CachingTilesContainer extends TilesContainerWrapper implements MutableTilesContainer { @Override public void register(Definition definition, Request request) { Map<String, Definition> definitions = getOrCreateDefinitions(request); if (definition.getName() == null) { definition.setName(getNextUniqueDefinitionName(definitions)); } if (definition.isExtending()) { this.resolveInheritance(definition, request); } definitions.put(definition.getName(), definition); } 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 testRegister() { 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(definition.getName()).andReturn(null); expect(definitions.containsKey("$anonymousMutableDefinition1")) .andReturn(false); definition.setName("$anonymousMutableDefinition1"); expect(definition.isExtending()).andReturn(true); expect(definition.isExtending()).andReturn(false); expect(definition.getName()).andReturn("$anonymousMutableDefinition1"); expect(definitions.put("$anonymousMutableDefinition1", definition)) .andReturn(null); replay(wrapped, request, definitions, scope, definition); container.register(definition, request); verify(wrapped, request, definitions, scope, definition); }
@SuppressWarnings("unchecked") @Test public void testRegisterCreateDefinitions() { Request request = createMock(Request.class); Map<String, Object> scope = createMock(Map.class); Definition definition = createMock(Definition.class); expect(request.getContext("request")).andReturn(scope).anyTimes(); expect(scope.get(DEFAULT_DEFINITIONS_ATTRIBUTE_NAME)).andReturn( null); expect(scope.put(eq(DEFAULT_DEFINITIONS_ATTRIBUTE_NAME), isA(HashMap.class))).andReturn(null); expect(definition.getName()).andReturn(null); definition.setName("$anonymousMutableDefinition1"); expect(definition.isExtending()).andReturn(true); expect(definition.isExtending()).andReturn(false); expect(definition.getName()).andReturn("$anonymousMutableDefinition1"); replay(wrapped, request, scope, definition); container.register(definition, request); verify(wrapped, request, scope, definition); }