包装异常>>>测试
一个包装异常的小例子.
public Activity updateActivity(Map Mapactivity) { Long id = Long.valueOf(Mapactivity.get("id").toString()); Activity act = (Activity)this.getHibernateTemplate().get(Activity.class,id); try { BeanUtils.populate(act,Mapactivity); this.getHibernateTemplate().update(act); }catch(Exception e){ throw new DolphinOperationException(e,CodeCategories.UPDATE_FAILURE); //CodeCategories.UPDATE_FAILURE 常量200或者400 } return act; }public class DolphinOperationException extends RuntimeException { private Integer errorCode; //定义一个错误编码 public DolphinOperationException(Integer errorCode) { this.errorCode = errorCode; } public DolphinOperationException(Throwable cause, Integer errorCode) { super(cause); this.errorCode = errorCode; } public DolphinOperationException(Integer errorCode,String message) { super(message); } public DolphinOperationException(String message, Throwable cause, Integer errorCode) { super(message, cause); this.errorCode = errorCode; } public Integer getErrorCode() { return errorCode; }} @Test @Rollback(false) public void updateActivity(){ Address ads = new Address(); ads.setAddress("22222"); User user = new User(); user.setId(15l); Activity act = new Activity(); act.setId(2l); act.setAddress(ads); act.setStartTime(new Date()); act.setTitle("光棍节写测试1"); Activity activity=am.updateActivity(act); assertNotNull(activity); }