API { public static void sendRedirect(String redirectUrl) { if ((redirectUrl == null) || redirectUrl.isEmpty()) { throw new IllegalArgumentException("Redirect URL cannot be null or empty."); } throw new PageRedirectException(redirectUrl); } 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 testSendRedirect() { Assert.assertThrows(IllegalArgumentException.class, () -> API.sendRedirect(null)); Assert.assertThrows(IllegalArgumentException.class, () -> API.sendRedirect("")); PageRedirectException pre = Assert.expectThrows(PageRedirectException.class, () -> API.sendRedirect("/some/uri")); Assert.assertEquals(pre.getHttpStatusCode(), HttpResponse.STATUS_FOUND); Assert.assertEquals(pre.getRedirectUrl(), "/some/uri"); }