### Question:
KieServerEndpointRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { KieServerEndpoint endpoint = null; if (resourceInfo.getResourceMethod().isAnnotationPresent(KieServerEndpoint.class)) { endpoint = resourceInfo.getResourceMethod().getAnnotation(KieServerEndpoint.class); } else if(resourceInfo.getResourceClass().isAnnotationPresent(KieServerEndpoint.class)) { endpoint = resourceInfo.getResourceClass().getAnnotation(KieServerEndpoint.class); } if ("GET".equals(requestContext.getMethod())) { return; } if (endpoint == null) { requestContext.abortWith(Response.status(SERVICE_UNAVAILABLE).entity("Endpoint disabled").build()); return; } List<EndpointType> current = new ArrayList<>(asList(endpoint.categories())); current.retainAll(valid); if(current.isEmpty()) { requestContext.abortWith(Response.status(SERVICE_UNAVAILABLE).entity("Endpoint disabled").build()); } }  @Override void filter(ContainerRequestContext requestContext);  }### Answer:
@Test public void testGetAlwaysPass() throws Exception { ContainerRequestContext requestContext = mock(ContainerRequestContext.class); when(resourceInfo.getResourceMethod()).thenReturn(TestSimpleOperations.class.getMethod("test1")); when(resourceInfo.getResourceClass()).thenReturn((Class) TestSimpleOperations.class); when(requestContext.getMethod()).thenReturn("GET"); filter.filter(requestContext); verify(requestContext, times(0)).abortWith(anyObject()); }
@Test public void testOtherOperationNoPass() throws Exception { ContainerRequestContext requestContext = mock(ContainerRequestContext.class); when(resourceInfo.getResourceMethod()).thenReturn(TestSimpleOperations.class.getMethod("test1")); when(resourceInfo.getResourceClass()).thenReturn((Class) TestSimpleOperations.class); when(requestContext.getMethod()).thenReturn("POST"); filter.filter(requestContext); verify(requestContext, times(1)).abortWith(anyObject()); }
@Test public void testOtherNoPassAnnotationPass() throws Exception { ContainerRequestContext requestContext = mock(ContainerRequestContext.class); when(resourceInfo.getResourceMethod()).thenReturn(TestAnnotationOperations.class.getMethod("test1")); when(resourceInfo.getResourceClass()).thenReturn((Class) TestAnnotationOperations.class); when(requestContext.getMethod()).thenReturn("POST"); filter.filter(requestContext); verify(requestContext, times(1)).abortWith(anyObject()); }
@Test public void testOtherAlwaysPassAnnotationPass() throws Exception { ContainerRequestContext requestContext = mock(ContainerRequestContext.class); when(resourceInfo.getResourceMethod()).thenReturn(TestAnnotationOperations.class.getMethod("test2")); when(resourceInfo.getResourceClass()).thenReturn((Class) TestAnnotationOperations.class); when(requestContext.getMethod()).thenReturn("POST"); filter.filter(requestContext); verify(requestContext, times(0)).abortWith(anyObject()); }
@Test public void testOtherOverrideBadPassAnnotationPass() throws Exception { ContainerRequestContext requestContext = mock(ContainerRequestContext.class); when(resourceInfo.getResourceMethod()).thenReturn(TestTypeAnnotationOperations.class.getMethod("test1")); when(resourceInfo.getResourceClass()).thenReturn((Class) TestTypeAnnotationOperations.class); when(requestContext.getMethod()).thenReturn("POST"); filter.filter(requestContext); verify(requestContext, times(1)).abortWith(anyObject()); }
@Test public void testOtherTypePassAnnotationPass() throws Exception { ContainerRequestContext requestContext = mock(ContainerRequestContext.class); when(resourceInfo.getResourceMethod()).thenReturn(TestAnnotationOperations.class.getMethod("test2")); when(resourceInfo.getResourceClass()).thenReturn((Class) TestAnnotationOperations.class); when(requestContext.getMethod()).thenReturn("POST"); filter.filter(requestContext); verify(requestContext, times(0)).abortWith(anyObject()); }