Browse Source
The invalidate() method in MockHttpSession is currently implemented incorrectly. According to the Servlet specification, the method should throw an IllegalStateException if it is invoked on an already invalidated session. However, invoking invalidate() on the same MockHttpSession instance multiple times does not throw an exception. This commits addresses this issue by checking the invalid field and throwing an IllegalStateException if it has already been set to true. Issue: SPR-9686pull/120/head
2 changed files with 59 additions and 1 deletions
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
/* |
||||
* Copyright 2002-2012 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.mock.web; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Unit tests for {@link MockHttpSession}. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 3.2 |
||||
*/ |
||||
public class MockHttpSessionTests { |
||||
|
||||
private MockHttpSession session = new MockHttpSession(); |
||||
|
||||
|
||||
@Test |
||||
public void invalidateOnce() { |
||||
assertFalse(session.isInvalid()); |
||||
session.invalidate(); |
||||
assertTrue(session.isInvalid()); |
||||
} |
||||
|
||||
@Test(expected = IllegalStateException.class) |
||||
public void invalidateTwice() { |
||||
session.invalidate(); |
||||
session.invalidate(); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue