SessionMapTestpublic class SessionMapTest extends TestCase
Fields Summary |
---|
private com.mockobjects.dynamic.Mock | requestMock | private com.mockobjects.dynamic.Mock | sessionMock |
Methods Summary |
---|
protected void | setUp()
sessionMock = new Mock(HttpSession.class);
requestMock = new Mock(HttpServletRequest.class);
requestMock.matchAndReturn("getSession", new Constraint[]{new IsEqual(Boolean.FALSE)}, sessionMock.proxy());
| public void | testClearInvalidatesTheSession()
List<String> attributeNames = new ArrayList<String>();
attributeNames.add("test");
attributeNames.add("anotherTest");
Enumeration attributeNamesEnum = Collections.enumeration(attributeNames);
MockSessionMap sessionMap = new MockSessionMap((HttpServletRequest) requestMock.proxy());
sessionMock.expect("setAttribute",
new Constraint[] {
new IsEqual("test"), new IsEqual("test value")
});
sessionMock.expect("setAttribute",
new Constraint[] {
new IsEqual("anotherTest"), new IsEqual("another test value")
});
sessionMock.expectAndReturn("getAttributeNames", attributeNamesEnum);
sessionMock.expect("removeAttribute",
new Constraint[]{
new IsEqual("test")
});
sessionMock.expect("removeAttribute",
new Constraint[]{
new IsEqual("anotherTest")
});
sessionMap.put("test", "test value");
sessionMap.put("anotherTest", "another test value");
sessionMap.clear();
assertNull(sessionMap.get("test"));
assertNull(sessionMap.get("anotherTest"));
sessionMock.verify();
| public void | testGetOnSessionMapUsesWrappedSessionsGetAttribute()
Object value = new Object();
sessionMock.expectAndReturn("getAttribute", new Constraint[]{
new IsEqual("KEY")
}, value);
SessionMap sessionMap = new SessionMap((HttpServletRequest) requestMock.proxy());
assertEquals("Expected the get using KEY to return the value object setup in the mockSession", value, sessionMap.get("KEY"));
sessionMock.verify();
| public void | testPutOnSessionMapUsesWrappedSessionsSetsAttribute()
Object value = new Object();
sessionMock.expect("getAttribute", new Constraint[]{new IsAnything()});
sessionMock.expect("setAttribute", new Constraint[]{
new IsEqual("KEY"), new IsEqual(value)
});
SessionMap sessionMap = new SessionMap((HttpServletRequest) requestMock.proxy());
sessionMap.put("KEY", value);
sessionMock.verify();
| public void | testPuttingObjectInMapReturnsNullForPreviouslyUnusedKey()
Object value = new Object();
sessionMock.expectAndReturn("getAttribute", new Constraint[]{
new IsEqual("KEY")
}, null);
sessionMock.expect("setAttribute", new Constraint[]{
new IsEqual("KEY"), new IsEqual(value)
});
SessionMap sessionMap = new SessionMap((HttpServletRequest) requestMock.proxy());
assertNull("should be null, as the contract for Map says that put returns the previous value in the map for the key", sessionMap.put("KEY", value));
sessionMock.verify();
| public void | testPuttingObjectInMapReturnsPreviousValueForKey()
Object originalValue = new Object();
Object value = new Object();
sessionMock.expectAndReturn("getAttribute", new Constraint[]{
new IsEqual("KEY")
}, null);
sessionMock.expect("setAttribute", new Constraint[]{
new IsEqual("KEY"), new IsEqual(originalValue)
});
sessionMock.expectAndReturn("getAttribute", new Constraint[]{
new IsEqual("KEY")
}, originalValue);
sessionMock.expect("setAttribute", new Constraint[]{
new IsEqual("KEY"), new IsEqual(value)
});
SessionMap sessionMap = new SessionMap((HttpServletRequest) requestMock.proxy());
sessionMap.put("KEY", originalValue);
assertEquals("should be the OriginalValue, as the contract for Map says that put returns the previous value in the map for the key", originalValue, sessionMap.put("KEY", value));
sessionMock.verify();
| public void | testRemovePassThroughCallToRemoveAttribute()
Object value = new Object();
sessionMock.expectAndReturn("getAttribute", new Constraint[]{
new IsEqual("KEY")
}, value);
sessionMock.expect("removeAttribute", new Constraint[]{
new IsEqual("KEY")
});
SessionMap sessionMap = new SessionMap((HttpServletRequest) requestMock.proxy());
assertEquals(value, sessionMap.remove("KEY"));
sessionMock.verify();
|
|