????????е???????Action?????
???????????? ???????[ 2015/5/5 15:24:25 ] ???????????????
????Action?????????????????????????????????????????tomcat????
?????????????У?????struts?????????鷳??????????execute???????????mock????????????
???????á?????Webwork?????????Щ??
????????????????????????????
????java????
????Account account;
????IAccountService accountService;
????public void setAccount(Account account){
????this.account=account;
????}
????public void setAccountService(IAccountService accountService){
????this.accountService=accountService;
????}
????public String regist()throws Exception{
????if(account==null){
????account=new Account();
????return INPUT;
????}
????if(!validForm(account))
????return INPUT;
????try{
????accountService.regist(account);
????}catch(ObjectExistsException e){
????e.printStackTrace();
????return INPUT;
????}
????return SUCCESS;
????}
????private boolean validForm(Account e){
????if(e.getName()==null||e.getName().trim().equals(""))
????return false;
????if(e.getPassword()==null||e.getPassword().trim().equals(""))
????return false;
????return true;
????}
?????о????????????????????????????????????
???????????setAccount????setAccountService?????
??????Account?????????????po????????????new???
????AccountService?????mock???????????????????????mock?????????????
????java????
????package org.wuhua.action;
????import junit.framework.TestCase;
????import org.easymock.MockControl;
????import org.wuhua.exception.ObjectExistsException;
????import org.wuhua.model.Account;
????import org.wuhua.service.IAccountService;
????import sms.king.AccountManager;
????import com.opensymphony.xwork.Action;
????public class AccountActionTest extends TestCase{
????private MockControl control;
????IAccountService accountService;
????protected void setUp()throws Exception{
????control=MockControl.createControl(IAccountService.class);
????accountService=(IAccountService)control.getMock();
????}
????public void testRegistOk()throws Exception{
????Account employee=new Account("name");
????employee.setPassword("password");
????accountService.regist(employee);
????control.setVoidCallable(1);
????control.replay();
????AccountAction action=new AccountAction();
????action.setAccount(employee);
????action.setAccountService(accountService);
????assertEquals(Action.SUCCESS??action.regist());
????control.verify();
????}
????public void testRegistNameExists()throws Exception{
????Account employee=new Account("name");
????employee.setPassword("password");
????accountService.regist(employee);
????control.setThrowable(new ObjectExistsException(""));
????control.replay();
????AccountAction action=new AccountAction();
????action.setAccount(employee);
????action.setAccountService(accountService);
????assertEquals(Action.INPUT??action.regist());
????control.verify();
????}
????}
????ok??????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11