GetAsStringModel { public void execute(boolean ignore, String preparer, String role, Object defaultValue, String defaultValueRole, String defaultValueType, @Parameter(required = true) String name, Attribute value, Request request, ModelBody modelBody) throws IOException { TilesContainer container = TilesAccess.getCurrentContainer(request); Deque<Object> composeStack = ComposeStackUtil.getComposeStack(request); Attribute attribute = resolveAttribute(container, ignore, preparer, role, defaultValue, defaultValueRole, defaultValueType, name, value, request); if (attribute != null) { composeStack.push(attribute); } modelBody.evaluateWithoutWriting(); container = TilesAccess.getCurrentContainer(request); Writer writer = request.getWriter(); if (attribute != null) { attribute = (Attribute) composeStack.pop(); } renderAttribute(attribute, container, writer, ignore, request); } GetAsStringModel();  GetAsStringModel(AttributeResolver attributeResolver); void execute(boolean ignore, String preparer, String role,
            Object defaultValue, String defaultValueRole,
            String defaultValueType, @Parameter(required = true) String name,
            Attribute value, Request request, ModelBody modelBody);  }
@Test public void testExecute() throws IOException { TilesContainer container = createMock(TilesContainer.class); Attribute attribute = createMock(Attribute.class); AttributeContext attributeContext = createMock(AttributeContext.class); Request request = createMock(Request.class); Writer writer = createMock(Writer.class); Map<String, Object> requestScope = new HashMap<String, Object>(); Deque<Object> composeStack = new ArrayDeque<Object>(); requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack); requestScope.put(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME, container); ApplicationContext applicationContext = createMock(ApplicationContext.class); ModelBody modelBody = createMock(ModelBody.class); modelBody.evaluateWithoutWriting(); expect(request.getApplicationContext()).andReturn(applicationContext).times(2); expect(request.getContext("request")).andReturn(requestScope).anyTimes(); expect(request.getWriter()).andReturn(writer); container.prepare("myPreparer", request); expect(resolver.computeAttribute(container, attribute, "myName", "myRole", false, "myDefaultValue", "myDefaultValueRole", "myDefaultValueType", request)).andReturn(attribute); expect(container.startContext(request)).andReturn(attributeContext); expect(container.evaluate(attribute, request)).andReturn("myValue"); writer.write("myValue"); container.endContext(request); replay(resolver, container, writer, request, applicationContext, modelBody); model.execute(false, "myPreparer", "myRole", "myDefaultValue", "myDefaultValueRole", "myDefaultValueType", "myName", attribute, request, modelBody); verify(resolver, container, writer, request, applicationContext, modelBody); }
@Test public void testExecuteIgnore() throws IOException { TilesContainer container = createMock(TilesContainer.class); AttributeContext attributeContext = createMock(AttributeContext.class); Request request = createMock(Request.class); Writer writer = createMock(Writer.class); Map<String, Object> requestScope = new HashMap<String, Object>(); Deque<Object> composeStack = new ArrayDeque<Object>(); requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack); requestScope.put(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME, container); ApplicationContext applicationContext = createMock(ApplicationContext.class); ModelBody modelBody = createMock(ModelBody.class); modelBody.evaluateWithoutWriting(); expect(request.getApplicationContext()).andReturn(applicationContext).times(2); expect(request.getContext("request")).andReturn(requestScope).anyTimes(); expect(request.getWriter()).andReturn(writer); container.prepare("myPreparer", request); expect(resolver.computeAttribute(container, null, "myName", "myRole", true, "myDefaultValue", "myDefaultValueRole", "myDefaultValueType", request)).andReturn(null); expect(container.startContext(request)).andReturn(attributeContext); container.endContext(request); replay(resolver, container, writer, request, applicationContext, modelBody); model.execute(true, "myPreparer", "myRole", "myDefaultValue", "myDefaultValueRole", "myDefaultValueType", "myName", null, request, modelBody); verify(resolver, container, writer, request, applicationContext, modelBody); }