1

How to unit test the following method using JUnit4??

public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    Object serviceObject = null;
    BaseServiceRequest baseServiceRequest = null;
    ServiceContext serviceContext = null;

    baseServiceRequest = (BaseServiceRequest) joinPoint.getArgs()[0];
    if (baseServiceRequest == null)
        ExceptionHandlerUtil.createExceptionType("SL","BaseServiceRequest cannot be empty", new Object[] {});

    serviceContext = baseServiceRequest.getServiceContext();
    ExceptionHandlerUtil.createExceptionType("SL","ServiceContext cannot be empty", new Object[] {});
    createServiceInvocationInterceptor(baseServiceRequ est,joinPoint);

    serviceObject = getServiceObject(serviceContext, joinPoint);
    serviceContext.getMethodInvocationEvent().setReturnValue(serviceObject);

    return serviceObject;
}
4

1 回答 1

0

我不知道这是否是您想知道的,因为问题有点不清楚,但是如果您想知道如何模拟生产方面用于单元测试的对象,您可以使用另一个方面 - 我们称之为元方面或测试方面 - 为了做到这一点。我已经在How to mock an aspect下描述了一种方法。

于 2012-08-11T23:48:31.223 回答