@Test public void formatAccessDeniedMessage() { Long id = 1L; String resourceName = "resourceName"; String expected = "Access to resourceName '1' is denied or resourceName doesn't exist."; try { ExceptionMessageFormatterUtil.formatAccessDeniedMessage(this::throwAccessDenied, resourceName, id); } catch (AccessDeniedException e) { Assert.assertEquals(expected, e.getMessage()); } }
public static void formatAccessDeniedMessage(Runnable r, String resourceName, Long id) { try { r.run(); } catch (AccessDeniedException e) { throw new AccessDeniedException( String.format("Access to %s '%s' is denied or %s doesn't exist.", resourceName, id, resourceName), e); } }
ExceptionMessageFormatterUtil { public static void formatAccessDeniedMessage(Runnable r, String resourceName, Long id) { try { r.run(); } catch (AccessDeniedException e) { throw new AccessDeniedException( String.format("Access to %s '%s' is denied or %s doesn't exist.", resourceName, id, resourceName), e); } } }
ExceptionMessageFormatterUtil { public static void formatAccessDeniedMessage(Runnable r, String resourceName, Long id) { try { r.run(); } catch (AccessDeniedException e) { throw new AccessDeniedException( String.format("Access to %s '%s' is denied or %s doesn't exist.", resourceName, id, resourceName), e); } } private  ExceptionMessageFormatterUtil(); }
ExceptionMessageFormatterUtil { public static void formatAccessDeniedMessage(Runnable r, String resourceName, Long id) { try { r.run(); } catch (AccessDeniedException e) { throw new AccessDeniedException( String.format("Access to %s '%s' is denied or %s doesn't exist.", resourceName, id, resourceName), e); } } private  ExceptionMessageFormatterUtil(); static void formatAccessDeniedMessage(Runnable r, String resourceName, Long id); static void formatAccessDeniedMessage(Runnable r, String resourceType, String resourceName); static String getErrorMessageFromException(Exception exception); }
ExceptionMessageFormatterUtil { public static void formatAccessDeniedMessage(Runnable r, String resourceName, Long id) { try { r.run(); } catch (AccessDeniedException e) { throw new AccessDeniedException( String.format("Access to %s '%s' is denied or %s doesn't exist.", resourceName, id, resourceName), e); } } private  ExceptionMessageFormatterUtil(); static void formatAccessDeniedMessage(Runnable r, String resourceName, Long id); static void formatAccessDeniedMessage(Runnable r, String resourceType, String resourceName); static String getErrorMessageFromException(Exception exception);  }