### Question:
InvocationProxy { public ValidationCode invoke() { InvocationContext context = invocation.getInvocationContext(); ValidationCode code; try { code = invocation.invoke(); } finally { logger.info("Whole time : {} ", context.printProfiling()); } return code; } InvocationProxy(Invocation invocation); ValidationCode invoke();  }### Answer:
@Test public void test() throws Exception { InvocationContext context = mock(InvocationContext.class); Invocation invocation = mock(Invocation.class); when(invocation.getInvocationContext()).thenReturn(context); InvocationProxy proxy = new InvocationProxy(invocation); proxy.invoke(); verify(invocation).invoke(); verify(context).printProfiling(); }
@Test public void testWithException() throws Exception { InvocationContext context = mock(InvocationContext.class); Invocation invocation = mock(Invocation.class); when(invocation.invoke()).thenThrow(new RuntimeException()); when(invocation.getInvocationContext()).thenReturn(context); InvocationProxy proxy = new InvocationProxy(invocation); boolean hasException = false; try { proxy.invoke(); } catch (Exception e) { hasException = true; } assertThat(hasException, is(true)); verify(invocation).invoke(); verify(context).printProfiling(); }
@Test public void testIntegration() throws Exception { SleepInterceptor interceptor1 = new SleepInterceptor(100); SleepInterceptor interceptor2 = new SleepInterceptor(50); final UserAccount user = mock(UserAccount.class); DefaultInvocation invocation = new DefaultInvocation(new InvocationContext(user, "portfolioId", BigMoney.parse("GBP 1.23"), new Date()), ImmutableList.of(interceptor1, interceptor2)); InvocationProxy proxy = new InvocationProxy(invocation); ValidationCode resultCode = proxy.invoke(); assertThat(interceptor1.isRan(), is(true)); assertThat(interceptor2.isRan(), is(true)); assertThat(invocation.isExecuted(), is(true)); assertThat(resultCode, is(ValidationCode.SUCCESSFUL)); }