提交 b3492f61 编写于 作者: S Stephane Nicoll

Merge pull request #523 from marschall/spring-expression-warnings

* spring-expression-warnings:
  Clean up spring-expression tests warnings
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -75,14 +75,14 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests { ...@@ -75,14 +75,14 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests {
// ArrayList containing List<Integer> to List<String> // ArrayList containing List<Integer> to List<String>
Class<?> clazz = typeDescriptorForListOfString.getElementTypeDescriptor().getType(); Class<?> clazz = typeDescriptorForListOfString.getElementTypeDescriptor().getType();
assertEquals(String.class,clazz); assertEquals(String.class,clazz);
List l = (List) tcs.convertValue(listOfInteger, TypeDescriptor.forObject(listOfInteger), typeDescriptorForListOfString); List<?> l = (List<?>) tcs.convertValue(listOfInteger, TypeDescriptor.forObject(listOfInteger), typeDescriptorForListOfString);
assertNotNull(l); assertNotNull(l);
// ArrayList containing List<String> to List<Integer> // ArrayList containing List<String> to List<Integer>
clazz = typeDescriptorForListOfInteger.getElementTypeDescriptor().getType(); clazz = typeDescriptorForListOfInteger.getElementTypeDescriptor().getType();
assertEquals(Integer.class,clazz); assertEquals(Integer.class,clazz);
l = (List) tcs.convertValue(listOfString, TypeDescriptor.forObject(listOfString), typeDescriptorForListOfString); l = (List<?>) tcs.convertValue(listOfString, TypeDescriptor.forObject(listOfString), typeDescriptorForListOfString);
assertNotNull(l); assertNotNull(l);
} }
...@@ -95,7 +95,7 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests { ...@@ -95,7 +95,7 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests {
// Assign a List<String> to the List<Integer> field - the component elements should be converted // Assign a List<String> to the List<Integer> field - the component elements should be converted
parser.parseExpression("listOfInteger").setValue(context,listOfString); parser.parseExpression("listOfInteger").setValue(context,listOfString);
assertEquals(3,e.getValue(context,Integer.class).intValue()); // size now 3 assertEquals(3,e.getValue(context,Integer.class).intValue()); // size now 3
Class clazz = parser.parseExpression("listOfInteger[1].getClass()").getValue(context,Class.class); // element type correctly Integer Class<?> clazz = parser.parseExpression("listOfInteger[1].getClass()").getValue(context, Class.class); // element type correctly Integer
assertEquals(Integer.class,clazz); assertEquals(Integer.class,clazz);
} }
......
/*
* Copyright 2002-2014 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.expression.spel; package org.springframework.expression.spel;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
...@@ -64,12 +80,12 @@ public class IndexingTests { ...@@ -64,12 +80,12 @@ public class IndexingTests {
@Override @Override
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException { public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
return (((Map) target).containsKey(name)); return (((Map<?, ?>) target).containsKey(name));
} }
@Override @Override
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException { public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
return new TypedValue(((Map) target).get(name)); return new TypedValue(((Map<?, ?>) target).get(name));
} }
@Override @Override
...@@ -298,7 +314,7 @@ public class IndexingTests { ...@@ -298,7 +314,7 @@ public class IndexingTests {
@Test @Test
public void resolveCollectionElementType() { public void resolveCollectionElementType() {
listNotGeneric = new ArrayList(); listNotGeneric = new ArrayList(2);
listNotGeneric.add(5); listNotGeneric.add(5);
listNotGeneric.add(6); listNotGeneric.add(6);
SpelExpressionParser parser = new SpelExpressionParser(); SpelExpressionParser parser = new SpelExpressionParser();
...@@ -338,7 +354,7 @@ public class IndexingTests { ...@@ -338,7 +354,7 @@ public class IndexingTests {
@Test @Test
public void testListOfScalar() { public void testListOfScalar() {
listOfScalarNotGeneric = new ArrayList(); listOfScalarNotGeneric = new ArrayList(1);
listOfScalarNotGeneric.add("5"); listOfScalarNotGeneric.add("5");
SpelExpressionParser parser = new SpelExpressionParser(); SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("listOfScalarNotGeneric[0]"); Expression expression = parser.parseExpression("listOfScalarNotGeneric[0]");
......
...@@ -182,12 +182,12 @@ public class MapAccessTests extends AbstractExpressionTests { ...@@ -182,12 +182,12 @@ public class MapAccessTests extends AbstractExpressionTests {
@Override @Override
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException { public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
return (((Map) target).containsKey(name)); return (((Map<?, ?>) target).containsKey(name));
} }
@Override @Override
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException { public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
return new TypedValue(((Map) target).get(name)); return new TypedValue(((Map<? ,?>) target).get(name));
} }
@Override @Override
......
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -46,7 +46,7 @@ public class SelectionAndProjectionTests { ...@@ -46,7 +46,7 @@ public class SelectionAndProjectionTests {
EvaluationContext context = new StandardEvaluationContext(new ListTestBean()); EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
Object value = expression.getValue(context); Object value = expression.getValue(context);
assertTrue(value instanceof List); assertTrue(value instanceof List);
List list = (List) value; List<?> list = (List<?>) value;
assertEquals(5, list.size()); assertEquals(5, list.size());
assertEquals(0, list.get(0)); assertEquals(0, list.get(0));
assertEquals(1, list.get(1)); assertEquals(1, list.get(1));
...@@ -79,7 +79,7 @@ public class SelectionAndProjectionTests { ...@@ -79,7 +79,7 @@ public class SelectionAndProjectionTests {
EvaluationContext context = new StandardEvaluationContext(new SetTestBean()); EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
Object value = expression.getValue(context); Object value = expression.getValue(context);
assertTrue(value instanceof List); assertTrue(value instanceof List);
List list = (List) value; List<?> list = (List<?>) value;
assertEquals(5, list.size()); assertEquals(5, list.size());
assertEquals(0, list.get(0)); assertEquals(0, list.get(0));
assertEquals(1, list.get(1)); assertEquals(1, list.get(1));
...@@ -221,7 +221,7 @@ public class SelectionAndProjectionTests { ...@@ -221,7 +221,7 @@ public class SelectionAndProjectionTests {
context.setVariable("testList", IntegerTestBean.createList()); context.setVariable("testList", IntegerTestBean.createList());
Object value = expression.getValue(context); Object value = expression.getValue(context);
assertTrue(value instanceof List); assertTrue(value instanceof List);
List list = (List) value; List<?> list = (List<?>) value;
assertEquals(3, list.size()); assertEquals(3, list.size());
assertEquals(5, list.get(0)); assertEquals(5, list.get(0));
assertEquals(6, list.get(1)); assertEquals(6, list.get(1));
...@@ -235,7 +235,7 @@ public class SelectionAndProjectionTests { ...@@ -235,7 +235,7 @@ public class SelectionAndProjectionTests {
context.setVariable("testList", IntegerTestBean.createSet()); context.setVariable("testList", IntegerTestBean.createSet());
Object value = expression.getValue(context); Object value = expression.getValue(context);
assertTrue(value instanceof List); assertTrue(value instanceof List);
List list = (List) value; List<?> list = (List<?>) value;
assertEquals(3, list.size()); assertEquals(3, list.size());
assertEquals(5, list.get(0)); assertEquals(5, list.get(0));
assertEquals(6, list.get(1)); assertEquals(6, list.get(1));
......
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -166,15 +166,15 @@ public class SetValueTests extends AbstractExpressionTests { ...@@ -166,15 +166,15 @@ public class SetValueTests extends AbstractExpressionTests {
e.setValue(eContext, "true"); e.setValue(eContext, "true");
// All keys should be strings // All keys should be strings
Set ks = parse("mapOfStringToBoolean.keySet()").getValue(eContext,Set.class); Set<?> ks = parse("mapOfStringToBoolean.keySet()").getValue(eContext, Set.class);
for (Object o: ks) { for (Object o: ks) {
assertEquals(String.class,o.getClass()); assertEquals(String.class,o.getClass());
} }
// All values should be booleans // All values should be booleans
Collection vs = parse("mapOfStringToBoolean.values()").getValue(eContext,Collection.class); Collection<?> vs = parse("mapOfStringToBoolean.values()").getValue(eContext, Collection.class);
for (Object o: vs) { for (Object o: vs) {
assertEquals(Boolean.class,o.getClass()); assertEquals(Boolean.class, o.getClass());
} }
// One final test check coercion on the key for a map lookup // One final test check coercion on the key for a map lookup
......
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -383,8 +383,8 @@ public class SpelDocumentationTests extends AbstractExpressionTests { ...@@ -383,8 +383,8 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
@Test @Test
public void testTypes() throws Exception { public void testTypes() throws Exception {
Class dateClass = parser.parseExpression("T(java.util.Date)").getValue(Class.class); Class<?> dateClass = parser.parseExpression("T(java.util.Date)").getValue(Class.class);
assertEquals(Date.class,dateClass); assertEquals(Date.class, dateClass);
boolean trueValue = parser.parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR").getValue(Boolean.class); boolean trueValue = parser.parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR").getValue(Boolean.class);
assertTrue(trueValue); assertTrue(trueValue);
} }
......
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -481,7 +481,7 @@ public class ReflectionHelperTests extends AbstractExpressionTests { ...@@ -481,7 +481,7 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
/** /**
* Used to validate the match returned from a compareArguments call. * Used to validate the match returned from a compareArguments call.
*/ */
private void checkMatch(Class[] inputTypes, Class[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) { private void checkMatch(Class<?>[] inputTypes, Class<?>[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) {
ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArguments(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter); ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArguments(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
if (expectedMatchKind == null) { if (expectedMatchKind == null) {
assertNull("Did not expect them to match in any way", matchInfo); assertNull("Did not expect them to match in any way", matchInfo);
...@@ -504,7 +504,7 @@ public class ReflectionHelperTests extends AbstractExpressionTests { ...@@ -504,7 +504,7 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
/** /**
* Used to validate the match returned from a compareArguments call. * Used to validate the match returned from a compareArguments call.
*/ */
private void checkMatch2(Class[] inputTypes, Class[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) { private void checkMatch2(Class<?>[] inputTypes, Class<?>[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) {
ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArgumentsVarargs(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter); ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArgumentsVarargs(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
if (expectedMatchKind == null) { if (expectedMatchKind == null) {
assertNull("Did not expect them to match in any way: " + matchInfo, matchInfo); assertNull("Did not expect them to match in any way: " + matchInfo, matchInfo);
...@@ -535,9 +535,9 @@ public class ReflectionHelperTests extends AbstractExpressionTests { ...@@ -535,9 +535,9 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
assertEquals(expected,actual); assertEquals(expected,actual);
} }
private List<TypeDescriptor> getTypeDescriptors(Class... types) { private List<TypeDescriptor> getTypeDescriptors(Class<?>... types) {
List<TypeDescriptor> typeDescriptors = new ArrayList<TypeDescriptor>(types.length); List<TypeDescriptor> typeDescriptors = new ArrayList<TypeDescriptor>(types.length);
for (Class type : types) { for (Class<?> type : types) {
typeDescriptors.add(TypeDescriptor.valueOf(type)); typeDescriptors.add(TypeDescriptor.valueOf(type));
} }
return typeDescriptors; return typeDescriptors;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册