modeldriveninterceptortest.java

来自「在Struts2中的jar包xwork的源代码.版本为2.0.7」· Java 代码 · 共 71 行

JAVA
71
字号
/* * Copyright (c) 2002-2003 by OpenSymphony * All rights reserved. */package com.opensymphony.xwork2.interceptor;import com.mockobjects.dynamic.Mock;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;import com.opensymphony.xwork2.util.ValueStack;import com.opensymphony.xwork2.util.ValueStackFactory;import junit.framework.TestCase;import java.util.Date;/** * @author $Author: mrdon $ * @version $Revision: 1142 $ */public class ModelDrivenInterceptorTest extends TestCase {    Action action;    Mock mockActionInvocation;    ModelDrivenInterceptor modelDrivenInterceptor;    Object model;    public void testModelDrivenGetsPushedOntoStack() throws Exception {        ValueStack stack = ValueStackFactory.getFactory().createValueStack();        action = new ModelDrivenAction();        mockActionInvocation.expectAndReturn("getAction", action);        mockActionInvocation.expectAndReturn("getStack", stack);        mockActionInvocation.expectAndReturn("invoke", "foo");        modelDrivenInterceptor.intercept((ActionInvocation) mockActionInvocation.proxy());        Object topOfStack = stack.pop();        assertEquals("our model should be on the top of the stack", model, topOfStack);    }    public void testStackNotModifedForNormalAction() throws Exception {        action = new ActionSupport();        mockActionInvocation.expectAndReturn("getAction", action);        mockActionInvocation.expectAndReturn("invoke", "foo");        // nothing should happen        modelDrivenInterceptor.intercept((ActionInvocation) mockActionInvocation.proxy());    }    protected void setUp() throws Exception {        mockActionInvocation = new Mock(ActionInvocation.class);        modelDrivenInterceptor = new ModelDrivenInterceptor();        model = new Date(); // any object will do    }    protected void tearDown() throws Exception {        mockActionInvocation.verify();    }    public class ModelDrivenAction extends ActionSupport implements ModelDriven {        public Object getModel() {            return model;        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?