@Test public void testInvoke() 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)); ValidationCode validationCode = invocation.invoke(); assertThat(interceptor1.isRan(), is(true)); assertThat(interceptor2.isRan(), is(true)); assertThat(invocation.isExecuted(), is(true)); assertThat(validationCode, is(ValidationCode.SUCCESSFUL)); }
@Override public ValidationCode invoke() { try { if (interceptors.hasNext() && !executed) { Interceptor interceptor = interceptors.next(); ValidationCode code = interceptor.intercept(this); if (ValidationCode.breakDown(code)) { executed = true; validationCode = code; } } else { executed = true; validationCode = ValidationCode.SUCCESSFUL; } } catch (Exception e) { executed = true; validationCode = ValidationCode.EXECUTION_ERROR; logger.error("Invocation error with context {}", invocationContext, e); } return validationCode; }
DefaultInvocation implements Invocation { @Override public ValidationCode invoke() { try { if (interceptors.hasNext() && !executed) { Interceptor interceptor = interceptors.next(); ValidationCode code = interceptor.intercept(this); if (ValidationCode.breakDown(code)) { executed = true; validationCode = code; } } else { executed = true; validationCode = ValidationCode.SUCCESSFUL; } } catch (Exception e) { executed = true; validationCode = ValidationCode.EXECUTION_ERROR; logger.error("Invocation error with context {}", invocationContext, e); } return validationCode; } }
DefaultInvocation implements Invocation { @Override public ValidationCode invoke() { try { if (interceptors.hasNext() && !executed) { Interceptor interceptor = interceptors.next(); ValidationCode code = interceptor.intercept(this); if (ValidationCode.breakDown(code)) { executed = true; validationCode = code; } } else { executed = true; validationCode = ValidationCode.SUCCESSFUL; } } catch (Exception e) { executed = true; validationCode = ValidationCode.EXECUTION_ERROR; logger.error("Invocation error with context {}", invocationContext, e); } return validationCode; } DefaultInvocation(InvocationContext invocationContext, List<? extends Interceptor> interceptorList); }
DefaultInvocation implements Invocation { @Override public ValidationCode invoke() { try { if (interceptors.hasNext() && !executed) { Interceptor interceptor = interceptors.next(); ValidationCode code = interceptor.intercept(this); if (ValidationCode.breakDown(code)) { executed = true; validationCode = code; } } else { executed = true; validationCode = ValidationCode.SUCCESSFUL; } } catch (Exception e) { executed = true; validationCode = ValidationCode.EXECUTION_ERROR; logger.error("Invocation error with context {}", invocationContext, e); } return validationCode; } DefaultInvocation(InvocationContext invocationContext, List<? extends Interceptor> interceptorList); @Override ValidationCode invoke(); @Override ValidationCode getValidationCode(); @Override boolean isExecuted(); @Override InvocationContext getInvocationContext(); }
DefaultInvocation implements Invocation { @Override public ValidationCode invoke() { try { if (interceptors.hasNext() && !executed) { Interceptor interceptor = interceptors.next(); ValidationCode code = interceptor.intercept(this); if (ValidationCode.breakDown(code)) { executed = true; validationCode = code; } } else { executed = true; validationCode = ValidationCode.SUCCESSFUL; } } catch (Exception e) { executed = true; validationCode = ValidationCode.EXECUTION_ERROR; logger.error("Invocation error with context {}", invocationContext, e); } return validationCode; } DefaultInvocation(InvocationContext invocationContext, List<? extends Interceptor> interceptorList); @Override ValidationCode invoke(); @Override ValidationCode getValidationCode(); @Override boolean isExecuted(); @Override InvocationContext getInvocationContext();  }