private static String createErrorMessage(ClientResponse clientResponse) {
   clientResponse.bufferEntity();
   String errorMessage = clientResponse.toString();
   if (clientResponse.hasEntity()) {
     errorMessage = errorMessage + " " + clientResponse.getEntity(String.class);
   }
   return errorMessage;
 }
  @Test
  public void testGetPaymentModes() {
    final ClientResponse result =
        webResource
            .path(URI)
            .cookie(tenantCookie)
            .header(HEADER_AUTH_KEY, HEADER_AUTH_VALUE_BASIC_ADMIN)
            .accept(MediaType.APPLICATION_XML)
            .get(ClientResponse.class);
    result.bufferEntity();
    assertOk(result, false);

    final PaymentModesDTO paymentModes = result.getEntity(PaymentModesDTO.class);
    assertNotNull("No paymentmodes found at response: " + result, paymentModes);
    assertEquals(
        "Wrong number of paymentMode found at response: " + result,
        1,
        paymentModes.getPaymentModes().size());

    assertIsNotNull(paymentModes.getPaymentModes(), PaymentModeDTO.class, "code", "uri");
  }
 private void throwIf400WithErrorMessage(final ClientResponse response) {
   if (ClientResponse.Status.BAD_REQUEST.equals(response.getClientResponseStatus())) {
     final String body = getResponseBody(response);
     response.bufferEntity();
     ErrorResponse errorResponse = null;
     try {
       errorResponse = response.getEntity(ErrorResponse.class);
     } catch (Exception ignore) {
       // most probably we do not have an error response
     }
     if (errorResponse != null) {
       // convert them to hide stupid "old" REST model, and not have it leak out
       final List<ErrorMessage> errors = Lists.newArrayList();
       for (org.sonatype.nexus.client.internal.msg.ErrorMessage message :
           errorResponse.getErrors()) {
         errors.add(
             new NexusClientErrorResponseException.ErrorMessage(
                 message.getId(), message.getMsg()));
       }
       throw new NexusClientErrorResponseException(
           response.getClientResponseStatus().getReasonPhrase(), body, errors);
     }
   }
 }