Example usage for org.springframework.aop.interceptor SimpleTraceInterceptor invokeUnderTrace

List of usage examples for org.springframework.aop.interceptor SimpleTraceInterceptor invokeUnderTrace

Introduction

In this page you can find the example usage for org.springframework.aop.interceptor SimpleTraceInterceptor invokeUnderTrace.

Prototype

@Override
    protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable 

Source Link

Usage

From source file:org.springframework.aop.interceptor.SimpleTraceInterceptorTests.java

@Test
public void testSunnyDayPathLogsCorrectly() throws Throwable {
    MethodInvocation mi = mock(MethodInvocation.class);
    given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[] {}));
    given(mi.getThis()).willReturn(this);

    Log log = mock(Log.class);

    SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
    interceptor.invokeUnderTrace(mi, log);

    verify(log, times(2)).trace(anyString());
}

From source file:org.springframework.aop.interceptor.SimpleTraceInterceptorTests.java

@Test
public void testExceptionPathStillLogsCorrectly() throws Throwable {
    MethodInvocation mi = mock(MethodInvocation.class);
    given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[] {}));
    given(mi.getThis()).willReturn(this);
    IllegalArgumentException exception = new IllegalArgumentException();
    given(mi.proceed()).willThrow(exception);

    Log log = mock(Log.class);

    final SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);

    try {//from  w  ww.j ava  2s . com
        interceptor.invokeUnderTrace(mi, log);
        fail("Must have propagated the IllegalArgumentException.");
    } catch (IllegalArgumentException expected) {
    }

    verify(log).trace(anyString());
    verify(log).trace(anyString(), eq(exception));
}