mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
Merge pull request #585 from sdutry/issue/WW-5196
WW-5196 use generics for RequestMap and ApplicationMap and correct SessionMap to also be of type <String, Object>
This commit is contained in:
@@ -50,13 +50,21 @@ public class SessionMapTest extends TestCase {
|
||||
List<String> attributeNames = new ArrayList<String>();
|
||||
attributeNames.add("test");
|
||||
attributeNames.add("anotherTest");
|
||||
Enumeration attributeNamesEnum = Collections.enumeration(attributeNames);
|
||||
Enumeration<String> attributeNamesEnum = Collections.enumeration(attributeNames);
|
||||
|
||||
MockSessionMap sessionMap = new MockSessionMap((HttpServletRequest) requestMock.proxy());
|
||||
sessionMock.expect("getAttribute",
|
||||
new Constraint[] {
|
||||
new IsEqual("test")
|
||||
});
|
||||
sessionMock.expect("setAttribute",
|
||||
new Constraint[] {
|
||||
new IsEqual("test"), new IsEqual("test value")
|
||||
});
|
||||
sessionMock.expect("getAttribute",
|
||||
new Constraint[] {
|
||||
new IsEqual("anotherTest")
|
||||
});
|
||||
sessionMock.expect("setAttribute",
|
||||
new Constraint[] {
|
||||
new IsEqual("anotherTest"), new IsEqual("another test value")
|
||||
@@ -70,6 +78,14 @@ public class SessionMapTest extends TestCase {
|
||||
new Constraint[]{
|
||||
new IsEqual("anotherTest")
|
||||
});
|
||||
sessionMock.expect("getAttribute",
|
||||
new Constraint[] {
|
||||
new IsEqual("test")
|
||||
});
|
||||
sessionMock.expect("getAttribute",
|
||||
new Constraint[] {
|
||||
new IsEqual("anotherTest")
|
||||
});
|
||||
sessionMap.put("test", "test value");
|
||||
sessionMap.put("anotherTest", "another test value");
|
||||
sessionMap.clear();
|
||||
@@ -102,7 +118,7 @@ public class SessionMapTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testGetObjectOnSessionMapUsesWrappedSessionsGetAttributeWithStringValue() throws Exception {
|
||||
Object key = new Object();
|
||||
String key = "theKey";
|
||||
Object value = new Object();
|
||||
sessionMock.expectAndReturn("getAttribute", new Constraint[]{
|
||||
new IsEqual(key.toString())
|
||||
@@ -114,7 +130,7 @@ public class SessionMapTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testPutObjectOnSessionMapUsesWrappedSessionsSetsAttributeWithStringValue() throws Exception {
|
||||
Object key = new Object();
|
||||
String key = "theKey";
|
||||
Object value = new Object();
|
||||
sessionMock.expect("getAttribute", new Constraint[]{new IsAnything()});
|
||||
sessionMock.expect("setAttribute", new Constraint[]{
|
||||
@@ -130,10 +146,10 @@ public class SessionMapTest extends TestCase {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
Object key = new Object();
|
||||
String key = "theKey";
|
||||
Object value = new Object();
|
||||
|
||||
SessionMap<Object, Object> sessionMap = new SessionMap<Object, Object>(request);
|
||||
SessionMap sessionMap = new SessionMap(request);
|
||||
sessionMap.put(key, value);
|
||||
assertTrue(sessionMap.containsKey(key));
|
||||
}
|
||||
@@ -142,11 +158,11 @@ public class SessionMapTest extends TestCase {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
Object key = new Object();
|
||||
Object someOtherKey = new Object();
|
||||
String key = "theKey";
|
||||
Object someOtherKey = "someOtherKey";
|
||||
Object value = new Object();
|
||||
|
||||
SessionMap<Object, Object> sessionMap = new SessionMap<Object, Object>(request);
|
||||
SessionMap sessionMap = new SessionMap(request);
|
||||
sessionMap.put(key, value);
|
||||
|
||||
assertFalse(sessionMap.containsKey(someOtherKey));
|
||||
@@ -219,7 +235,7 @@ public class SessionMapTest extends TestCase {
|
||||
|
||||
private static final long serialVersionUID = 8783604360786273764L;
|
||||
|
||||
private Map map = new HashMap();
|
||||
private Map<String, Object> map = new HashMap<>();
|
||||
|
||||
public MockSessionMap(HttpServletRequest request) {
|
||||
super(request);
|
||||
@@ -228,8 +244,8 @@ public class SessionMapTest extends TestCase {
|
||||
public Object get(Object key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
public Object put(Object key, Object value) {
|
||||
|
||||
public Object put(String key, Object value) {
|
||||
Object originalValue = super.put(key, value);
|
||||
map.put(key, value); //put the value into our map after putting it in the superclass map to avoid polluting the get call.
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.dispatcher;
|
||||
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class StringObjectEntryTest extends TestCase {
|
||||
public void testGetKey() {
|
||||
StringObjectEntry entry = new StringObjectEntryTestImpl("theKey", "theValue");
|
||||
assertEquals("theKey", entry.getKey());
|
||||
}
|
||||
|
||||
public void testGetValue() {
|
||||
StringObjectEntry entry = new StringObjectEntryTestImpl("theKey", "theValue");
|
||||
assertEquals("theValue", entry.getValue());
|
||||
}
|
||||
|
||||
public void testEquals() {
|
||||
StringObjectEntry entry = new StringObjectEntryTestImpl("theKey", "theValue");
|
||||
|
||||
assertEquals(entry, new StringObjectEntryTestImpl("theKey", "theValue"));
|
||||
assertNotEquals(entry, new StringObjectEntryTestImpl("theKey", "differentValue"));
|
||||
assertNotEquals(entry, new StringObjectEntryTestImpl("differentKey", "theValue"));
|
||||
assertNotEquals(entry, new StringObjectEntryTestImpl("differentKey", "differentValue"));
|
||||
}
|
||||
|
||||
public void testHashCode() {
|
||||
StringObjectEntry entry = new StringObjectEntryTestImpl("theKey", "theValue");
|
||||
assertEquals(-1962296402, entry.hashCode());
|
||||
}
|
||||
|
||||
static class StringObjectEntryTestImpl extends StringObjectEntry {
|
||||
StringObjectEntryTestImpl(final String key, final Object value) {
|
||||
super(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object setValue(final Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,7 @@ public class CspInterceptorTest extends StrutsInternalTestCase {
|
||||
ActionContext context = ActionContext.getContext()
|
||||
.withServletRequest(request)
|
||||
.withServletResponse(response)
|
||||
.withSession(new SessionMap<>(request))
|
||||
.withSession(new SessionMap(request))
|
||||
.bind();
|
||||
mai.setInvocationContext(context);
|
||||
session = request.getSession();
|
||||
|
||||
+2
-3
@@ -38,7 +38,6 @@ import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.struts2.views.jsp.AbstractUITagTest.normalize;
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
@@ -260,8 +259,8 @@ public class FreemarkerResultMockedTest extends StrutsInternalTestCase {
|
||||
EasyMock.replay(servletContext);
|
||||
|
||||
init();
|
||||
// create session
|
||||
request.getSession();
|
||||
// create session and add nonce
|
||||
request.getSession().setAttribute("nonce", "aNonce");
|
||||
|
||||
request.setRequestURI("/tutorial/test10.action");
|
||||
ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request, configurationManager);
|
||||
|
||||
@@ -107,7 +107,7 @@ public abstract class AbstractTagTest extends StrutsInternalTestCase {
|
||||
MockDispatcher du = new MockDispatcher(pageContext.getServletContext(), new HashMap<>(), configurationManager);
|
||||
du.init();
|
||||
Dispatcher.setInstance(du);
|
||||
session = new SessionMap<>(request);
|
||||
session = new SessionMap(request);
|
||||
Map<String, Object> extraContext = du.createContextMap(new RequestMap(request),
|
||||
HttpParameters.create(request.getParameterMap()).build(),
|
||||
session,
|
||||
|
||||
@@ -1674,7 +1674,7 @@ public class URLTagTest extends AbstractUITagTest {
|
||||
|
||||
mockContainer = new Mock(Container.class);
|
||||
|
||||
session = new SessionMap<>(request);
|
||||
session = new SessionMap(request);
|
||||
Map<String, Object> extraContext = du.createContextMap(new RequestMap(request),
|
||||
HttpParameters.create(request.getParameterMap()).build(),
|
||||
session,
|
||||
|
||||
Reference in New Issue
Block a user