Search in sources :

Example 1 with IsEqual

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();
}
Also used : IsEqual(com.mockobjects.constraint.IsEqual)

Example 2 with IsEqual

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());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) Mock(com.mockobjects.dynamic.Mock) IsEqual(com.mockobjects.constraint.IsEqual)

Example 3 with IsEqual

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();
}
Also used : IsEqual(com.mockobjects.constraint.IsEqual)

Example 4 with IsEqual

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();
}
Also used : IsEqual(com.mockobjects.constraint.IsEqual)

Example 5 with IsEqual

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();
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) IsEqual(com.mockobjects.constraint.IsEqual)

Aggregations

IsEqual (com.mockobjects.constraint.IsEqual)9 IsAnything (com.mockobjects.constraint.IsAnything)2 Mock (com.mockobjects.dynamic.Mock)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1