SessionScopeExtractor implements AttributeExtractor { @SuppressWarnings("unchecked") @Override public Enumeration<String> getKeys() { HttpSession session = request.getSession(false); if (session != null) { return session.getAttributeNames(); } return Collections.enumeration(Collections.<String>emptySet()); } SessionScopeExtractor(HttpServletRequest request); @Override void setValue(String name, Object value); @Override void removeValue(String name); @SuppressWarnings("unchecked") @Override Enumeration<String> getKeys(); @Override Object getValue(String key);  }
@SuppressWarnings("unchecked") @Test public void testGetKeys() { Enumeration<String> keys = createMock(Enumeration.class); expect(request.getSession(false)).andReturn(session); expect(session.getAttributeNames()).andReturn(keys); replay(request, session, keys); assertEquals(keys, extractor.getKeys()); verify(request, session, keys); }
@Test public void testGetKeysNoSession() { expect(request.getSession(false)).andReturn(null); replay(request, session); Enumeration<String> keys = extractor.getKeys(); assertNotNull(keys); assertFalse(keys.hasMoreElements()); verify(request, session); }