Throw ISEs in MockHttpSession for invalid session
The Javadoc for several methods in HttpSession specifies that an IllegalStateException must be thrown if the method is called on an invalidated session; however, Spring's MockHttpSession did not implement this behavior consistently prior to this commit. This commit therefore ensures that the following methods in MockHttpSession properly throw an IllegalStateException as defined in the Servlet specification. - long getCreationTime() - long getLastAccessedTime() - Object getAttribute(String) - Object getValue(String) - Enumeration<String> getAttributeNames() - String[] getValueNames() - void setAttribute(String, Object) - void putValue(String , Object) - void removeAttribute(String) - void removeValue(String) - void invalidate() - boolean isNew() Issue: SPR-7659
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,7 @@ import org.junit.Test;
|
||||
*/
|
||||
public class MockHttpSessionTests {
|
||||
|
||||
private MockHttpSession session = new MockHttpSession();
|
||||
private final MockHttpSession session = new MockHttpSession();
|
||||
|
||||
|
||||
@Test
|
||||
@@ -44,4 +44,103 @@ public class MockHttpSessionTests {
|
||||
session.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void getCreationTimeOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.getCreationTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void getLastAccessedTimeOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.getLastAccessedTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void getAttributeOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.getAttribute("foo");
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void getAttributeNamesOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.getAttributeNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void getValueOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.getValue("foo");
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void getValueNamesOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.getValueNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void setAttributeOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.setAttribute("name", "value");
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void putValueOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.putValue("name", "value");
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void removeAttributeOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.removeAttribute("name");
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void removeValueOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.removeValue("name");
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void isNewOnInvalidatedSession() {
|
||||
session.invalidate();
|
||||
session.isNew();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user