ResourceLookupInterceptor implements Interceptor { public void intercept(InterceptorStack stack, ResourceMethod ignorableMethod, Object resourceInstance) throws InterceptionException { try { ResourceMethod method = translator.translate(requestInfo); methodInfo.setResourceMethod(method); stack.next(method, resourceInstance); } catch (ResourceNotFoundException e) { resourceNotFoundHandler.couldntFind(requestInfo); } catch (MethodNotAllowedException e) { LOGGER.debug(e.getMessage(), e); methodNotAllowedHandler.deny(requestInfo, e.getAllowedMethods()); } } ResourceLookupInterceptor(UrlToResourceTranslator translator, MethodInfo methodInfo,
			ResourceNotFoundHandler resourceNotFoundHandler, MethodNotAllowedHandler methodNotAllowedHandler,
			RequestInfo requestInfo); void intercept(InterceptorStack stack, ResourceMethod ignorableMethod, Object resourceInstance); boolean accepts(ResourceMethod method);  }
@Test public void shouldHandle404() throws IOException, InterceptionException { when(translator.translate(info)).thenThrow(new ResourceNotFoundException()); lookup.intercept(null, null, null); verify(notFoundHandler).couldntFind(info); }
@Test public void shouldHandle405() throws IOException, InterceptionException { EnumSet<HttpMethod> allowedMethods = EnumSet.of(HttpMethod.GET); when(translator.translate(info)).thenThrow(new MethodNotAllowedException(allowedMethods, HttpMethod.POST.toString())); lookup.intercept(null, null, null); verify(methodNotAllowedHandler).deny(info, allowedMethods); }
@Test public void shouldUseResourceMethodFoundWithNextInterceptor() throws IOException, InterceptionException { final ResourceMethod method = mock(ResourceMethod.class); final InterceptorStack stack = mock(InterceptorStack.class); when(translator.translate(info)).thenReturn(method); lookup.intercept(stack, null, null); verify(stack).next(method, null); verify(methodInfo).setResourceMethod(method); }