title: Jersey test - ExceptionMapper - UniformInterfaceException when HTTP status is not 200
body: <p>I have to test Jersey 1.19 with jersey-test-framework-grizzly2. There is configuration class with registered REST endpoint and exception mapper class:</p>
  
  <pre><code>public class ConfiguredMyServiceTest extends JerseyTest {
  
      @Override
      protected int getPort(int defaultPort) {
          return 8080;
      }
  
      public static class AppConfig extends DefaultResourceConfig {   
          public AppConfig() {
              getSingletons().add(new ExceptionMapperProvider());
              getSingletons().add(new MyService());
          }
      }
  
      @Override
      public WebAppDescriptor configure() {
          return new WebAppDescriptor.Builder()
              .initParam(WebComponent.RESOURCE_CONFIG_CLASS, 
                  AppConfig.class.getName())
                  .build();
      }
  }
  </code></pre>
  
  <p>When I execute/test REST endpoint which returns HTTP status 200 it works well. </p>
  
  <p>If exception is thrown, exception mapper handles it well and forms return object javax.ws.rs.core.Response with error code:</p>
  
  <pre><code>@Provider
  @Singleton
  public class ExceptionMapperProvider implements ExceptionMapper&lt;Exception&gt;{
  
      @Override
      public Response toResponse(final Exception exception){
          return Response.status(HttpStatusCodes.STATUS_CODE_SERVER_ERROR).entity(new BasicResponse(InternalStatus.UNHANDLED_EXCEPTION, exception.getMessage())).type(MediaType.APPLICATION_JSON).build();
      }
  }
  </code></pre>
  
  <p>However, I get </p>
  
  <pre><code>com.sun.jersey.api.client.UniformInterfaceException: POST http://localhost:8080/v1/my-service/ returned a response status of 401 Unauthorized
  </code></pre>
  
  <p>when I try to assert Response in my JUnit tests. How to get well formed response instead of UniformInterfaceException?</p>