use of com.mockobjects.constraint.IsEqual in project struts by apache.
the class SessionMapTest method testRemovePassThroughCallToRemoveAttribute.
public void testRemovePassThroughCallToRemoveAttribute() throws Exception {
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();
}
use of com.mockobjects.constraint.IsEqual in project struts by apache.
the class SessionMapTest method setUp.
protected void setUp() throws Exception {
sessionMock = new Mock(HttpSession.class);
sessionMock.matchAndReturn("getId", "1");
requestMock = new Mock(HttpServletRequest.class);
requestMock.matchAndReturn("getSession", new Constraint[] { new IsEqual(Boolean.FALSE) }, sessionMock.proxy());
}
use of com.mockobjects.constraint.IsEqual in project struts by apache.
the class SessionMapTest method testPuttingObjectInMapReturnsNullForPreviouslyUnusedKey.
public void testPuttingObjectInMapReturnsNullForPreviouslyUnusedKey() throws Exception {
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();
}
use of com.mockobjects.constraint.IsEqual in project struts by apache.
the class SessionMapTest method testPuttingObjectInMapReturnsPreviousValueForKey.
public void testPuttingObjectInMapReturnsPreviousValueForKey() throws Exception {
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();
}
use of com.mockobjects.constraint.IsEqual in project struts by apache.
the class SessionMapTest method testClearInvalidatesTheSession.
public void testClearInvalidatesTheSession() throws Exception {
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();
}
Aggregations