}
@Test
public void iterator() {
Sessions<String> sessions = mock(Sessions.class);
SessionManager manager = mock(SessionManager.class);
Session session = mock(Session.class);
String deployment = "deployment";
String sessionId = "session";
when(this.sso.getSessions()).thenReturn(sessions);
when(sessions.getDeployments()).thenReturn(Collections.singleton(deployment));
when(sessions.getSession(deployment)).thenReturn(sessionId);
when(this.registry.getSessionManager(deployment)).thenReturn(manager);
when(manager.getSession(sessionId)).thenReturn(session);
when(session.getId()).thenReturn(sessionId);
Iterator<Session> results = this.subject.iterator();
assertTrue(results.hasNext());
Session result = results.next();
assertEquals(session.getId(), result.getId());
assertFalse(results.hasNext());
verifyZeroInteractions(this.batch);
// Validate that returned sessions can be invalidated
HttpServerExchange exchange = new HttpServerExchange(null);
Session mutableSession = mock(Session.class);
when(session.getSessionManager()).thenReturn(manager);
when(manager.getSession(same(exchange), Matchers.<SessionConfig>any())).thenReturn(mutableSession);
result.invalidate(exchange);
verify(mutableSession).invalidate(same(exchange));
}