@Test public void shouldUseContainerIfInterceptorAccepts() throws Exception { LazyInterceptorHandler handler = new LazyInterceptorHandler(container,AlwaysAcceptInterceptor.class); handler.execute(stack,method,instance); verify(container).instanceFor(AlwaysAcceptInterceptor.class); verify(mockInterceptor).intercept(stack, method, instance); verify(mockInterceptor, never()).accepts(any(ResourceMethod.class)); }
public void execute(InterceptorStack stack, ResourceMethod method, Object resourceInstance) throws InterceptionException { boolean accepts; try { accepts = getAcceptor().accepts(method); } catch (NullPointerException e) { throw new InterceptionException("StaticInterceptors should not use constructor parameters inside the accepts method", e); } if (accepts) { Interceptor interceptor = container.instanceFor(type); if (interceptor == null) { throw new InterceptionException("Unable to instantiate interceptor for " + type.getName() + ": the container returned null."); } logger.debug("Invoking interceptor {}", interceptor.getClass().getSimpleName()); interceptor.intercept(stack, method, resourceInstance); } else { stack.next(method, resourceInstance); } }
LazyInterceptorHandler implements InterceptorHandler { public void execute(InterceptorStack stack, ResourceMethod method, Object resourceInstance) throws InterceptionException { boolean accepts; try { accepts = getAcceptor().accepts(method); } catch (NullPointerException e) { throw new InterceptionException("StaticInterceptors should not use constructor parameters inside the accepts method", e); } if (accepts) { Interceptor interceptor = container.instanceFor(type); if (interceptor == null) { throw new InterceptionException("Unable to instantiate interceptor for " + type.getName() + ": the container returned null."); } logger.debug("Invoking interceptor {}", interceptor.getClass().getSimpleName()); interceptor.intercept(stack, method, resourceInstance); } else { stack.next(method, resourceInstance); } } }
LazyInterceptorHandler implements InterceptorHandler { public void execute(InterceptorStack stack, ResourceMethod method, Object resourceInstance) throws InterceptionException { boolean accepts; try { accepts = getAcceptor().accepts(method); } catch (NullPointerException e) { throw new InterceptionException("StaticInterceptors should not use constructor parameters inside the accepts method", e); } if (accepts) { Interceptor interceptor = container.instanceFor(type); if (interceptor == null) { throw new InterceptionException("Unable to instantiate interceptor for " + type.getName() + ": the container returned null."); } logger.debug("Invoking interceptor {}", interceptor.getClass().getSimpleName()); interceptor.intercept(stack, method, resourceInstance); } else { stack.next(method, resourceInstance); } } LazyInterceptorHandler(Container container, Class<? extends Interceptor> type); }
LazyInterceptorHandler implements InterceptorHandler { public void execute(InterceptorStack stack, ResourceMethod method, Object resourceInstance) throws InterceptionException { boolean accepts; try { accepts = getAcceptor().accepts(method); } catch (NullPointerException e) { throw new InterceptionException("StaticInterceptors should not use constructor parameters inside the accepts method", e); } if (accepts) { Interceptor interceptor = container.instanceFor(type); if (interceptor == null) { throw new InterceptionException("Unable to instantiate interceptor for " + type.getName() + ": the container returned null."); } logger.debug("Invoking interceptor {}", interceptor.getClass().getSimpleName()); interceptor.intercept(stack, method, resourceInstance); } else { stack.next(method, resourceInstance); } } LazyInterceptorHandler(Container container, Class<? extends Interceptor> type); void execute(InterceptorStack stack, ResourceMethod method, Object resourceInstance); @Override String toString(); }
LazyInterceptorHandler implements InterceptorHandler { public void execute(InterceptorStack stack, ResourceMethod method, Object resourceInstance) throws InterceptionException { boolean accepts; try { accepts = getAcceptor().accepts(method); } catch (NullPointerException e) { throw new InterceptionException("StaticInterceptors should not use constructor parameters inside the accepts method", e); } if (accepts) { Interceptor interceptor = container.instanceFor(type); if (interceptor == null) { throw new InterceptionException("Unable to instantiate interceptor for " + type.getName() + ": the container returned null."); } logger.debug("Invoking interceptor {}", interceptor.getClass().getSimpleName()); interceptor.intercept(stack, method, resourceInstance); } else { stack.next(method, resourceInstance); } } LazyInterceptorHandler(Container container, Class<? extends Interceptor> type); void execute(InterceptorStack stack, ResourceMethod method, Object resourceInstance); @Override String toString();  }