java异常源码_exceptiontest.java 源代码在线查看 - java 异常处理java 异常处理java 异常处理 资源下载 虫虫电子下载站...

package com.ldd600.exception.test;import org.jmock.Expectations;import org.jmock.Mockery;import org.springframework.beans.factory.BeanFactory;import com.ldd600.exception.action.BusinessAction;import com.ldd600.exception.base.BaseAppException;import com.ldd600.exception.base.BaseAppRuntimeException;import com.ldd600.exception.base.ConfigException;import com.ldd600.exception.base.handler.ConsoleHandler;import com.ldd600.exception.context.CoreContextFactory;import com.ldd600.exception.dto.DefaultRequest;import com.ldd600.exception.dto.DefaultResponse;import com.ldd600.exception.dto.Request;import com.ldd600.exception.dto.Response;import com.ldd600.exception.webservice.ActionBrokerImpl;public class ExceptionTest extends DependencyInjectionExceptionTestCase {Mockery context = new Mockery();ActionBrokerImpl broker = new ActionBrokerImpl();final Request request = new DefaultRequest();final Response response = new DefaultResponse();@Overrideprotected String[] getConfigLocations() {return new String[] { "applicationContext.xml" };}public void testExceptionThrow() {final BusinessAction action = context.mock(BusinessAction.class);final BeanFactory beanFactory = context.mock(BeanFactory.class);assertThrowing(new Closure() {public void run() throws Throwable {context.checking(new Expectations() {{allowing(beanFactory).getBean("action");will(returnValue(action));one(action).execute(request, response);will(throwException(new BaseAppException()));}});broker.setExceptionHandler(new ConsoleHandler());broker.setBeanFactory(beanFactory);broker.execute("action", request, response);}}, BaseAppException.class);}public void testExceptionalAutoLoad() throws BaseAppException {final BeanFactory beanFactory = context.mock(BeanFactory.class);final BusinessAction action = context.mock(BusinessAction.class);context.checking(new Expectations() {{allowing(beanFactory).getBean("action");will(returnValue(action));one(action).execute(request, response);will(throwException(new ConfigException()));}});broker.setBeanFactory(beanFactory);broker.execute("action", request, response);assertEquals(CoreContextFactory.getInstance().getExceptionContext().getErrorCode(ConfigException.class), "LDD600-00002");context.assertIsSatisfied();}public void testRuntimeException() {final BusinessAction action = context.mock(BusinessAction.class);final BeanFactory beanFactory = context.mock(BeanFactory.class);assertThrowing(new Closure() {public void run() throws Throwable {context.checking(new Expectations() {{allowing(beanFactory).getBean("action");will(returnValue(action));one(action).execute(request, response);will(throwException(new BaseAppRuntimeException()));}});broker.setExceptionHandler(new ConsoleHandler());broker.setBeanFactory(beanFactory);broker.execute("action", request, response);}}, BaseAppRuntimeException.class);// test configassertEquals(CoreContextFactory.getInstance().getExceptionContext().getErrorCode(BaseAppRuntimeException.class), "LDD600-00001");// test handlerassertFalse(response.isSuccess());assertEquals(response.getErrorCode(), CoreContextFactory.getInstance().getExceptionContext().getErrorCode(BaseAppRuntimeException.class));context.assertIsSatisfied();}public void testCheckedException() {final BusinessAction action = context.mock(BusinessAction.class);final BeanFactory beanFactory = context.mock(BeanFactory.class);assertThrowing(new Closure() {public void run() throws Throwable {context.checking(new Expectations() {{allowing(beanFactory).getBean("action");will(returnValue(action));one(action).execute(request, response);will(throwException(new ExceptionFaker()));}});broker.setBeanFactory(beanFactory);broker.execute("action", request, response);}}, ExceptionFaker.class);// test configassertEquals(CoreContextFactory.getInstance().getExceptionContext().getErrorCode(ExceptionFaker.class), "LDD600-00003");// test handlerassertFalse(response.isSuccess());assertEquals(response.getErrorCode(), CoreContextFactory.getInstance().getExceptionContext().getErrorCode(ExceptionFaker.class));context.assertIsSatisfied();}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值