@Test public void testSunnyDayPathLogsCorrectly() throws Throwable { MethodInvocation methodInvocation = mock(MethodInvocation.class); Log log = mock(Log.class); given(log.isTraceEnabled()).willReturn(true); DebugInterceptor interceptor = new StubDebugInterceptor(log); interceptor.invoke(methodInvocation); checkCallCountTotal(interceptor); verify(log, times(2)).trace(anyString()); }
@Test public void testExceptionPathStillLogsCorrectly() throws Throwable { MethodInvocation methodInvocation = mock(MethodInvocation.class); IllegalArgumentException exception = new IllegalArgumentException(); given(methodInvocation.proceed()).willThrow(exception); Log log = mock(Log.class); given(log.isTraceEnabled()).willReturn(true); DebugInterceptor interceptor = new StubDebugInterceptor(log); try { interceptor.invoke(methodInvocation); fail("Must have propagated the IllegalArgumentException."); } catch (IllegalArgumentException expected) { } checkCallCountTotal(interceptor); verify(log).trace(anyString()); verify(log).trace(anyString(), eq(exception)); }