我有一个使用此方法的类
@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"));
}
我现在想用主题中的无效字符进行测试。发生这种情况时,会引发以下异常:
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)
我该如何测试?
最佳答案
修改您的测试方法,如下面的代码:
@Test(expected = StatusRuntimeException.class)
public void test01()
{
containerMetadataManagementServlet.runGetConfig(request,"/service-api-create-bucket-schema.json");
}
关于Java测试异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59920037/