Skip to content

Commit

Permalink
[#2052] make session put with Object work the same way as with String
Browse files Browse the repository at this point in the history
# Conflicts:
#	framework/src/play/mvc/Scope.java
  • Loading branch information
Anton Keks, Erik Jõgi authored and xael-fry committed Jun 14, 2016
1 parent 0702d7a commit e08b50e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
16 changes: 6 additions & 10 deletions framework/src/play/mvc/Scope.java
@@ -1,30 +1,25 @@
package play.mvc;

import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;

import play.Logger;
import play.Play;
import play.data.binding.Binder;
import play.data.binding.ParamNode;
import play.data.binding.RootParamNode;
import play.data.parsing.DataParser;
import play.data.parsing.DataParsers;
import play.data.parsing.TextParser;
import play.data.validation.Validation;
import play.exceptions.UnexpectedException;
import play.libs.Codec;
import play.libs.Crypto;
import play.libs.Time;
import play.utils.Utils;

import java.lang.annotation.Annotation;
import java.net.URLEncoder;
import java.util.*;

/**
* All application Scopes
*/
Expand Down Expand Up @@ -280,8 +275,9 @@ public void put(String key, Object value) {
change();
if (value == null) {
put(key, (String) null);
} else {
put(key, value.toString());
}
put(key, value + "");
}

public String get(String key) {
Expand Down
38 changes: 32 additions & 6 deletions framework/test-src/play/mvc/ScopeTest.java
@@ -1,15 +1,13 @@
package play.mvc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.*;

import org.junit.Test;
import play.PlayBuilder;
import play.mvc.Http.Request;
import play.mvc.Http.Response;
import play.mvc.Scope.Params;
import play.mvc.Scope.Session;

import static org.junit.Assert.*;


public class ScopeTest {
Expand Down Expand Up @@ -123,4 +121,32 @@ public void testParamsRemoveStartWith() {

assertEquals(2, params.all().size());
}

@Test
public void sessionPutWithNullObject() throws Exception {
Session session = new Session();
session.put("hello", (Object)null);
assertNull(session.get("hello"));
}

@Test
public void sessionPutWithObject() throws Exception {
Session session = new Session();
session.put("hello", 123);
assertEquals("123", session.get("hello"));
}

@Test
public void sessionPutWithNullString() throws Exception {
Session session = new Session();
session.put("hello", (String)null);
assertNull(session.get("hello"));
}

@Test
public void sessionPutWithString() throws Exception {
Session session = new Session();
session.put("hello", "world");
assertEquals("world", session.get("hello"));
}
}

0 comments on commit e08b50e

Please sign in to comment.