SessionScopeExtractor implements AttributeExtractor { @Override public Enumeration<String> getKeys() { if (context.getSession() == null) { return null; } return context.getAttributeNamesInScope(PageContext.SESSION_SCOPE); } SessionScopeExtractor(PageContext context); @Override void removeValue(String name); @Override Enumeration<String> getKeys(); @Override Object getValue(String key); @Override void setValue(String key, Object value);  }
@SuppressWarnings("unchecked") @Test public void testGetKeys() { expect(context.getSession()).andReturn(session); Enumeration<String> keys = createMock(Enumeration.class); expect(context.getAttributeNamesInScope(PageContext.SESSION_SCOPE)).andReturn(keys); replay(context, session); assertEquals(keys, extractor.getKeys()); verify(context, session); }
@Test public void testGetKeysNoSession() { expect(context.getSession()).andReturn(null); replay(context, session); assertNull(extractor.getKeys()); verify(context, session); }