RESTeasy + Server mock + ExceptionMapper not found

I have a script that ExceptionMapperuses JAX-RS using RESTeasy 2.0.1.GA. It works great.

Now I would like to test everything using the RESTeasy mock mechanism . Unfortunately, my ExceptionMapper provider is not registered. What am I missing?

POJOResourceFactory factory = new POJOResourceFactory(SomeWebResource.class);

Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
dispatcher.getRegistry().addResourceFactory(factory); 

MockHttpRequest request = MockHttpRequest.get("url");
MockHttpResponse response = new MockHttpResponse();

// here my exception is thrown
dispatcher.invoke(request, response);

// but I expect the response to be 404 (which works outside the mock setup)
Assert.assertEquals(response.getStatus(), 404);
+5
source share
1 answer

Ok, I found a solution. You need to register ExceptionMapper manually:

dispatcher.getProviderFactory().addExceptionMapper(SomeExceptionMapper.class);
+10
source

All Articles