public static void assertErrorCodeWithRegexp(int errorCode, String regExp, Runnable runnable) {
try {
runnable.run();
Assert.fail(RestClientException.class + " exception expected");
} catch (com.atlassian.jira.rest.client.api.RestClientException ex) {
final ErrorCollection errorElement = getOnlyElement(ex.getErrorCollections().iterator());
final String errorMessage = getOnlyElement(errorElement.getErrorMessages().iterator());
Assert.assertTrue("'" + ex.getMessage() + "' does not match regexp '" + regExp + "'", errorMessage.matches(regExp));
Assert.assertTrue(ex.getStatusCode().isPresent());
Assert.assertEquals(errorCode, ex.getStatusCode().get().intValue());
}
}