@Test
public void returnsResponseWithStatus_METHOD_NOT_ALLOWED_WhenSubResourceLocatorProducesResourceThatDoesNotSupportRequestedHttpMethod() throws Exception {

    when(request.getMethod()).thenReturn("GET");
    when(applicationContext.getPathSegments(false)).thenReturn(createPathSegments("a", "b", "c", "d;x=y"));
    LocatorResource locatorResource = new LocatorResource();
    SubResourceLocatorDescriptor subResourceLocator = mockSubResourceLocator(LocatorResource.class.getMethod("resource"), "c/d");
    ObjectFactory resourceFactory = mockResourceFactory(locatorResource, newArrayList(), newArrayList(), newArrayList(subResourceLocator));
    matchRequestPath("c/d");
    when(resources.getMatchedResource(eq("/a/b/c/d"), anyList())).thenReturn(resourceFactory);
    when(methodInvoker.invokeMethod(same(locatorResource), same(subResourceLocator), same(applicationContext))).thenReturn(new SubResource());
    requestDispatcher.dispatch(request, response);
    ArgumentCaptor<Response> argumentCaptor = ArgumentCaptor.forClass(Response.class);
    verify(response, atLeastOnce()).setResponse(argumentCaptor.capture());
    assertEquals(METHOD_NOT_ALLOWED, argumentCaptor.getValue().getStatusInfo());
    String allowHeader = argumentCaptor.getValue().getHeaderString(ALLOW);
    assertEquals("POST,OPTIONS", allowHeader);
}