Publish binding event for replaced attributes in MockHttpSession

Issue: SPR-17109
This commit is contained in:
Vedran Pavic
2018-08-01 12:49:41 +02:00
committed by Juergen Hoeller
parent 0001f87d59
commit 70dbaf9751
3 changed files with 91 additions and 8 deletions

View File

@@ -41,6 +41,7 @@ import org.springframework.util.StringUtils;
* @author Rod Johnson
* @author Mark Fisher
* @author Sam Brannen
* @author Vedran Pavic
* @since 1.0.2
*/
@SuppressWarnings("deprecation")
@@ -176,9 +177,14 @@ public class MockHttpSession implements HttpSession {
assertIsValid();
Assert.notNull(name, "Attribute name must not be null");
if (value != null) {
this.attributes.put(name, value);
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value));
Object oldValue = this.attributes.put(name, value);
if (value != oldValue) {
if (oldValue instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
}
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value));
}
}
}
else {