AddListAttributeModel { public void execute(String role, Request request, ModelBody modelBody) throws IOException { Deque<Object> composeStack = ComposeStackUtil.getComposeStack(request); ListAttribute listAttribute = new ListAttribute(); listAttribute.setRole(role); composeStack.push(listAttribute); modelBody.evaluateWithoutWriting(); listAttribute = (ListAttribute) composeStack.pop(); ListAttribute parent = (ListAttribute) composeStack.peek(); parent.add(listAttribute); }  void execute(String role, Request request, ModelBody modelBody);  }
@Test public void testExecute() throws IOException { Deque<Object> composeStack = new ArrayDeque<Object>(); Request request = createMock(Request.class); Map<String, Object> requestScope = new HashMap<String, Object>(); ModelBody modelBody = createMock(ModelBody.class); modelBody.evaluateWithoutWriting(); requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack); expect(request.getContext("request")).andReturn(requestScope); replay(request, modelBody); ListAttribute parent = new ListAttribute(); composeStack.push(parent); model.execute("myRole", request, modelBody); assertEquals(1, composeStack.size()); assertEquals(parent, composeStack.pop()); assertEquals(1, parent.getValue().size()); ListAttribute listAttribute = (ListAttribute) parent.getValue().get(0); assertEquals("myRole", listAttribute.getRole()); verify(request, modelBody); }