API { public Session createSession(User user) { if (user == null) { throw new IllegalArgumentException("User of a session cannot be null."); } destroySession(); try { return sessionManager.createSession(user, requestLookup.getRequest(), requestLookup.getResponse()); } catch (SessionManagementException e) { throw new PluginExecutionException( "Cannot create a session for user '" + user.getId() + "' using session manager '" + sessionManager.getClass().getName() + "'.", e); } } 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 testCreateSession() throws Exception { HttpRequest request = mock(HttpRequest.class); when(request.getContextPath()).thenReturn("/test"); HttpResponse response = mock(HttpResponse.class); User user = mock(User.class); when(user.getId()).thenReturn("admin"); RequestLookup requestLookup = new RequestLookup("/test", request, response); SessionManager sessionManager = createSessionManager(); mockCreateSession(user, sessionManager); API api = new API(sessionManager, null, requestLookup); Assert.assertThrows(IllegalArgumentException.class, () -> api.createSession(null)); Session createdSession = api.createSession(user); Assert.assertEquals(createdSession.getUser(), user); }