????????Service?????Service??????Dao?????????Mock???Dao???ɡ??????????????????????????????????
????java????
????public interface IAccountService extends IBaseService{
????Account findAccountById(String id);
????Account findAccounByName(String name);
????void regist(Account account)throws ObjectExistsException;
????}
??????????????
????java????
????public void regist(Account account)throws ObjectExistsException{
????if(accountDao.findAccounByName(account.getName())!=null)
????throw new ObjectExistsException("User's name is exists!");
????accountDao.save(account);
????}
???????????
????java????
????protected void setUp()throws Exception{
????control=MockControl.createControl(IAccountDao.class);
????accountDao=(IAccountDao)control.getMock();
????as=new AccountService();
????as.setAccountDao(accountDao);
????}
????public void testFindAccountByName(){
????String name="wuhua";
????accountDao.findAccounByName(name);
????Account a=new Account("wuhua");
????a.setId(name);
????control.setReturnValue(a);
????control.replay();
????Account at=as.findAccounByName(name);
????Assert.assertEquals(name??at.getId());
????Assert.assertEquals(a??at);
????control.verify();
????}
???????????????????????????name??"wuhua";
??????????Dao???????
???????????巵???????????????
????????????????????ж????????????????