dimanche 26 janvier 2020

Java test for an exception

I have a class with this method

@Test
public void testWithOriginalPattern() throws Exception {
  this.OBJCET_CONTENT =
      "{\"service_instance\": \"foo\", \"notifications\": {\"subject\": \"bar0-9A-Za-z-._\"}}";
  final HttpServletRequest request = createGoodRequest(this.OBJCET_CONTENT);
  final ContainerMetadataManagementServlet containerMetadataManagementServlet =
      new MockContainerMetadataManagementServlet();
  assertNotNull(containerMetadataManagementServlet.runGetConfig(request, "/service-api-create-bucket-schema.json"));
}

I now want to do the test with invalid characters in the subject. When this happens the following exception is thrown:

HttpException(400,{"status_code":400,"error_code":"MalformedNotificationsError","uri":"uri","message":"The provided JSON was not well-formed or did not validate against the published schema."},null)

How do I test for that?

Aucun commentaire:

Enregistrer un commentaire