Batcher<Batch> batcher = mock(Batcher.class);
BatchContext context = mock(BatchContext.class);
String name = CachedAuthenticatedSessionHandler.class.getName() + ".AuthenticatedSession";
SessionAttributes attributes = mock(SessionAttributes.class);
Account account = mock(Account.class);
AuthenticatedSession session = new AuthenticatedSession(account, HttpServletRequest.FORM_AUTH);
Account oldAccount = mock(Account.class);
when(this.manager.getSessionManager()).thenReturn(manager);
when(manager.getBatcher()).thenReturn(batcher);
when(batcher.resumeBatch(this.batch)).thenReturn(context);
when(this.session.getAttributes()).thenReturn(attributes);
when(attributes.setAttribute(name, account)).thenReturn(oldAccount);
AuthenticatedSession result = (AuthenticatedSession) this.adapter.setAttribute(name, session);
assertSame(oldAccount, result.getAccount());
assertSame(HttpServletRequest.FORM_AUTH, result.getMechanism());
verify(context).close();
reset(context);
when(attributes.setAttribute(name, account)).thenReturn(null);
result = (AuthenticatedSession) this.adapter.setAttribute(name, session);
assertNull(result);
verify(context).close();
reset(context);
session = new AuthenticatedSession(account, HttpServletRequest.BASIC_AUTH);
AuthenticatedSession oldSession = new AuthenticatedSession(oldAccount, HttpServletRequest.BASIC_AUTH);
LocalSessionContext localContext = mock(LocalSessionContext.class);
when(this.session.getLocalContext()).thenReturn(localContext);
when(localContext.getAuthenticatedSession()).thenReturn(oldSession);