API { public static void sendError(int status, String message) { if ((status < 100) || (status > 599)) { throw new IllegalArgumentException("HTTP status code must be between 100 and 599."); } if ((message == null) || message.isEmpty()) { throw new IllegalArgumentException("Error message cannot be null or empty."); } throw new HttpErrorException(status, message); } API(SessionManager sessionManager, Authorizer authorizer, RequestLookup requestLookup); RequestLookup getRequestLookup(); static Object callOSGiService(String serviceClassName, String serviceMethodName, Object... args); static Map<String, Object> getOSGiServices(String serviceClassName); static void callMicroService(); static void sendError(int status, String message); static void sendRedirect(String redirectUrl); Session createSession(User user); Optional<Session> getSession(); boolean hasPermission(Permission permission); boolean destroySession();  }
@Test public void testSendError() { Assert.assertThrows(IllegalArgumentException.class, () -> API.sendError(99, "Some error!")); Assert.assertThrows(IllegalArgumentException.class, () -> API.sendError(600, "Some error!")); Assert.assertThrows(IllegalArgumentException.class, () -> API.sendError(500, null)); Assert.assertThrows(IllegalArgumentException.class, () -> API.sendError(500, "")); HttpErrorException exception = Assert.expectThrows(HttpErrorException.class, () -> API.sendError(500, "Some internal server error!")); Assert.assertEquals(exception.getHttpStatusCode(), 500); Assert.assertEquals(exception.getMessage(), "Some internal server error!"); }