### Question:
AnonymousLoginModule extends AbstractLoginModule { public boolean login() throws LoginException { HttpRequestCallback hcb = new HttpRequestCallback(); Callback[] callbacks = new Callback[] { hcb }; try { m_handler.handle( callbacks ); HttpServletRequest request = hcb.getRequest(); WikiPrincipal ipAddr = new WikiPrincipal( HttpUtil.getRemoteAddress(request) ); if ( log.isDebugEnabled() ) { HttpSession session = request.getSession( false ); String sid = (session == null) ? NULL : session.getId(); log.debug("Logged in session ID=" + sid + "; IP=" + ipAddr); } m_principals.add( ipAddr ); return true; } catch( IOException e ) { log.error("IOException: " + e.getMessage()); return false; } catch( UnsupportedCallbackException e ) { String message = "Unable to handle callback, disallowing login."; log.error( message, e ); throw new LoginException( message ); } }  boolean login(); static final String PROMPT; }### Answer:
@Test public final void testLogin() { HttpServletRequest request = m_engine.newHttpRequest(); try { CallbackHandler handler = new WebContainerCallbackHandler( m_engine, request ); LoginModule module = new AnonymousLoginModule(); module.initialize( m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>() ); module.login(); module.commit(); Set< Principal > principals = m_subject.getPrincipals(); Assertions.assertEquals( 1, principals.size() ); Assertions.assertTrue( principals.contains( new WikiPrincipal( "127.0.0.1" ) ) ); Assertions.assertFalse( principals.contains( Role.ANONYMOUS ) ); Assertions.assertFalse( principals.contains( Role.ALL ) ); } catch( LoginException e ) { System.err.println( e.getMessage() ); Assertions.assertTrue( false ); } }
@Test public final void testLogout() { HttpServletRequest request = m_engine.newHttpRequest(); try { CallbackHandler handler = new WebContainerCallbackHandler( m_engine, request ); LoginModule module = new AnonymousLoginModule(); module.initialize( m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>() ); module.login(); module.commit(); Set< Principal > principals = m_subject.getPrincipals(); Assertions.assertEquals( 1, principals.size() ); Assertions.assertTrue( principals.contains( new WikiPrincipal( "127.0.0.1" ) ) ); Assertions.assertFalse( principals.contains( Role.ANONYMOUS ) ); Assertions.assertFalse( principals.contains( Role.ALL ) ); module.logout(); Assertions.assertEquals( 0, principals.size() ); } catch( LoginException e ) { System.err.println( e.getMessage() ); Assertions.assertTrue( false ); } }