Merge pull request #27248 from Syuziko

* pr/27248:
  Polish contribution
  Polish tests

Closes gh-27248
This commit is contained in:
Stephane Nicoll 2021-08-08 11:40:02 +02:00
commit d4cd9405dd
36 changed files with 1104 additions and 1116 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -296,10 +296,10 @@ public abstract class AbstractPropertyAccessorTests {
accessor.setPropertyValue("spouse.age", 35);
accessor.setPropertyValue("spouse.name", "Kerry");
accessor.setPropertyValue("spouse.company", "Lewisham");
assertThat(kerry.getName().equals("Kerry")).as("kerry name is Kerry").isTrue();
assertThat(kerry.getName()).as("kerry name is Kerry").isEqualTo("Kerry");
assertThat(target.getSpouse() == kerry).as("nested set worked").isTrue();
assertThat(kerry.getSpouse() == null).as("no back relation").isTrue();
assertThat(kerry.getSpouse()).as("no back relation").isNull();
accessor.setPropertyValue(new PropertyValue("spouse.spouse", target));
assertThat(kerry.getSpouse() == target).as("nested set worked").isTrue();
@ -316,7 +316,7 @@ public abstract class AbstractPropertyAccessorTests {
accessor.setPropertyValue("spouse", kerry);
assertThat(target.getSpouse() == kerry).as("nested set worked").isTrue();
assertThat(kerry.getSpouse() == null).as("no back relation").isTrue();
assertThat(kerry.getSpouse()).as("no back relation").isNull();
accessor.setPropertyValue(new PropertyValue("spouse.spouse", target));
assertThat(kerry.getSpouse() == target).as("nested set worked").isTrue();
assertThat(kerry.getAge() == 0).as("kerry age not set").isTrue();
@ -478,8 +478,8 @@ public abstract class AbstractPropertyAccessorTests {
accessor.setPropertyValue("age", newAge);
accessor.setPropertyValue(new PropertyValue("name", newName));
accessor.setPropertyValue(new PropertyValue("touchy", newTouchy));
assertThat(target.getName().equals(newName)).as("Name property should have changed").isTrue();
assertThat(target.getTouchy().equals(newTouchy)).as("Touchy property should have changed").isTrue();
assertThat(target.getName()).as("Name property should have changed").isEqualTo(newName);
assertThat(target.getTouchy()).as("Touchy property should have changed").isEqualTo(newTouchy);
assertThat(target.getAge() == newAge).as("Age property should have changed").isTrue();
}
@ -490,7 +490,7 @@ public abstract class AbstractPropertyAccessorTests {
AbstractPropertyAccessor accessor = createAccessor(target);
target.setAge(newAge);
Object bwAge = accessor.getPropertyValue("age");
assertThat(bwAge instanceof Integer).as("Age is an integer").isTrue();
assertThat(bwAge).as("Age is an integer").isInstanceOf(Integer.class);
assertThat(bwAge).as("Bean wrapper must pick up changes").isEqualTo(newAge);
}
@ -500,13 +500,13 @@ public abstract class AbstractPropertyAccessorTests {
target.setName("Frank"); // we need to change it back
target.setSpouse(target);
AbstractPropertyAccessor accessor = createAccessor(target);
assertThat(target.getName() != null).as("name is not null to start off").isTrue();
assertThat(target.getName()).as("name is not null to start off").isNotNull();
accessor.setPropertyValue("name", null);
assertThat(target.getName() == null).as("name is now null").isTrue();
assertThat(target.getName()).as("name is now null").isNull();
// now test with non-string
assertThat(target.getSpouse() != null).as("spouse is not null to start off").isTrue();
assertThat(target.getSpouse()).as("spouse is not null to start off").isNotNull();
accessor.setPropertyValue("spouse", null);
assertThat(target.getSpouse() == null).as("spouse is now null").isTrue();
assertThat(target.getSpouse()).as("spouse is now null").isNull();
}
@Test
@ -591,20 +591,20 @@ public abstract class AbstractPropertyAccessorTests {
accessor.setPropertyValue("float2", "8.1");
accessor.setPropertyValue("double2", "6.1");
accessor.setPropertyValue("bigDecimal", "4.0");
assertThat(new Short("2").equals(accessor.getPropertyValue("short2"))).as("Correct short2 value").isTrue();
assertThat(new Short("2").equals(target.getShort2())).as("Correct short2 value").isTrue();
assertThat(new Integer("8").equals(accessor.getPropertyValue("int2"))).as("Correct int2 value").isTrue();
assertThat(new Integer("8").equals(target.getInt2())).as("Correct int2 value").isTrue();
assertThat(new Long("6").equals(accessor.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
assertThat(new Long("6").equals(target.getLong2())).as("Correct long2 value").isTrue();
assertThat(new BigInteger("3").equals(accessor.getPropertyValue("bigInteger"))).as("Correct bigInteger value").isTrue();
assertThat(new BigInteger("3").equals(target.getBigInteger())).as("Correct bigInteger value").isTrue();
assertThat(new Float("8.1").equals(accessor.getPropertyValue("float2"))).as("Correct float2 value").isTrue();
assertThat(new Float("8.1").equals(target.getFloat2())).as("Correct float2 value").isTrue();
assertThat(new Double("6.1").equals(accessor.getPropertyValue("double2"))).as("Correct double2 value").isTrue();
assertThat(new Double("6.1").equals(target.getDouble2())).as("Correct double2 value").isTrue();
assertThat(new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal"))).as("Correct bigDecimal value").isTrue();
assertThat(new BigDecimal("4.0").equals(target.getBigDecimal())).as("Correct bigDecimal value").isTrue();
assertThat(Short.valueOf("2")).as("Correct short2 value").isEqualTo(accessor.getPropertyValue("short2"));
assertThat(Short.valueOf("2")).as("Correct short2 value").isEqualTo(target.getShort2());
assertThat(Integer.valueOf("8")).as("Correct int2 value").isEqualTo(accessor.getPropertyValue("int2"));
assertThat(Integer.valueOf("8")).as("Correct int2 value").isEqualTo(target.getInt2());
assertThat(Long.valueOf("6")).as("Correct long2 value").isEqualTo(accessor.getPropertyValue("long2"));
assertThat(Long.valueOf("6")).as("Correct long2 value").isEqualTo(target.getLong2());
assertThat(new BigInteger("3")).as("Correct bigInteger value").isEqualTo(accessor.getPropertyValue("bigInteger"));
assertThat(new BigInteger("3")).as("Correct bigInteger value").isEqualTo(target.getBigInteger());
assertThat(Float.valueOf("8.1")).as("Correct float2 value").isEqualTo(accessor.getPropertyValue("float2"));
assertThat(Float.valueOf("8.1")).as("Correct float2 value").isEqualTo(target.getFloat2());
assertThat(Double.valueOf("6.1").equals(accessor.getPropertyValue("double2"))).as("Correct double2 value").isTrue();
assertThat(Double.valueOf("6.1")).as("Correct double2 value").isEqualTo(target.getDouble2());
assertThat(new BigDecimal("4.0")).as("Correct bigDecimal value").isEqualTo(accessor.getPropertyValue("bigDecimal"));
assertThat(new BigDecimal("4.0")).as("Correct bigDecimal value").isEqualTo(target.getBigDecimal());
}
@Test
@ -616,22 +616,22 @@ public abstract class AbstractPropertyAccessorTests {
accessor.setPropertyValue("long2", new BigInteger("6"));
accessor.setPropertyValue("bigInteger", 3L);
accessor.setPropertyValue("float2", 8.1D);
accessor.setPropertyValue("double2", new BigDecimal(6.1));
accessor.setPropertyValue("double2", new BigDecimal("6.1"));
accessor.setPropertyValue("bigDecimal", 4.0F);
assertThat(new Short("2").equals(accessor.getPropertyValue("short2"))).as("Correct short2 value").isTrue();
assertThat(new Short("2").equals(target.getShort2())).as("Correct short2 value").isTrue();
assertThat(new Integer("8").equals(accessor.getPropertyValue("int2"))).as("Correct int2 value").isTrue();
assertThat(new Integer("8").equals(target.getInt2())).as("Correct int2 value").isTrue();
assertThat(new Long("6").equals(accessor.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
assertThat(new Long("6").equals(target.getLong2())).as("Correct long2 value").isTrue();
assertThat(Short.valueOf("2")).as("Correct short2 value").isEqualTo(accessor.getPropertyValue("short2"));
assertThat(Short.valueOf("2")).as("Correct short2 value").isEqualTo(target.getShort2());
assertThat(Integer.valueOf("8")).as("Correct int2 value").isEqualTo(accessor.getPropertyValue("int2"));
assertThat(Integer.valueOf("8")).as("Correct int2 value").isEqualTo(target.getInt2());
assertThat(Long.valueOf("6")).as("Correct long2 value").isEqualTo(accessor.getPropertyValue("long2"));
assertThat(Long.valueOf("6")).as("Correct long2 value").isEqualTo(target.getLong2());
assertThat(new BigInteger("3").equals(accessor.getPropertyValue("bigInteger"))).as("Correct bigInteger value").isTrue();
assertThat(new BigInteger("3").equals(target.getBigInteger())).as("Correct bigInteger value").isTrue();
assertThat(new Float("8.1").equals(accessor.getPropertyValue("float2"))).as("Correct float2 value").isTrue();
assertThat(new Float("8.1").equals(target.getFloat2())).as("Correct float2 value").isTrue();
assertThat(new Double("6.1").equals(accessor.getPropertyValue("double2"))).as("Correct double2 value").isTrue();
assertThat(new Double("6.1").equals(target.getDouble2())).as("Correct double2 value").isTrue();
assertThat(new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal"))).as("Correct bigDecimal value").isTrue();
assertThat(new BigDecimal("4.0").equals(target.getBigDecimal())).as("Correct bigDecimal value").isTrue();
assertThat(new BigInteger("3")).as("Correct bigInteger value").isEqualTo(target.getBigInteger());
assertThat(Float.valueOf("8.1")).as("Correct float2 value").isEqualTo(accessor.getPropertyValue("float2"));
assertThat(Float.valueOf("8.1")).as("Correct float2 value").isEqualTo(target.getFloat2());
assertThat(Double.valueOf("6.1")).as("Correct double2 value").isEqualTo(accessor.getPropertyValue("double2"));
assertThat(Double.valueOf("6.1")).as("Correct double2 value").isEqualTo(target.getDouble2());
assertThat(new BigDecimal("4.0")).as("Correct bigDecimal value").isEqualTo(accessor.getPropertyValue("bigDecimal"));
assertThat(new BigDecimal("4.0")).as("Correct bigDecimal value").isEqualTo(target.getBigDecimal());
}
@Test
@ -724,11 +724,11 @@ public abstract class AbstractPropertyAccessorTests {
String ps = "peace=war\nfreedom=slavery";
accessor.setPropertyValue("properties", ps);
assertThat(target.name.equals("ptest")).as("name was set").isTrue();
assertThat(target.properties != null).as("properties non null").isTrue();
assertThat(target.name).as("name was set").isEqualTo("ptest");
assertThat(target.properties).as("properties non null").isNotNull();
String freedomVal = target.properties.getProperty("freedom");
String peaceVal = target.properties.getProperty("peace");
assertThat(peaceVal.equals("war")).as("peace==war").isTrue();
assertThat(peaceVal).as("peace==war").isEqualTo("war");
assertThat(freedomVal.equals("slavery")).as("Freedom==slavery").isTrue();
}
@ -737,7 +737,7 @@ public abstract class AbstractPropertyAccessorTests {
PropsTester target = new PropsTester();
AbstractPropertyAccessor accessor = createAccessor(target);
accessor.setPropertyValue("stringArray", new String[] {"foo", "fi", "fi", "fum"});
accessor.setPropertyValue("stringArray", new String[]{"foo", "fi", "fi", "fum"});
assertThat(target.stringArray.length == 4).as("stringArray length = 4").isTrue();
assertThat(target.stringArray[0].equals("foo") && target.stringArray[1].equals("fi") &&
target.stringArray[2].equals("fi") && target.stringArray[3].equals("fum")).as("correct values").isTrue();
@ -763,10 +763,10 @@ public abstract class AbstractPropertyAccessorTests {
accessor.setPropertyValue("stringArray", "one");
assertThat(target.stringArray.length == 1).as("stringArray length = 1").isTrue();
assertThat(target.stringArray[0].equals("one")).as("stringArray elt is ok").isTrue();
assertThat(target.stringArray[0]).as("stringArray elt is ok").isEqualTo("one");
accessor.setPropertyValue("stringArray", null);
assertThat(target.stringArray == null).as("stringArray is null").isTrue();
assertThat(target.stringArray).as("stringArray is null").isNull();
}
@Test
@ -836,10 +836,10 @@ public abstract class AbstractPropertyAccessorTests {
accessor.setAutoGrowNestedPaths(true);
accessor.setPropertyValue("array[0]", "Test0");
assertThat(target.getArray().length).isEqualTo(1);
assertThat(target.getArray()).hasSize(1);
accessor.setPropertyValue("array[2]", "Test2");
assertThat(target.getArray().length).isEqualTo(3);
assertThat(target.getArray()).hasSize(3);
assertThat(target.getArray()[0].equals("Test0") && target.getArray()[1] == null &&
target.getArray()[2].equals("Test2")).as("correct values").isTrue();
}
@ -849,7 +849,7 @@ public abstract class AbstractPropertyAccessorTests {
PropsTester target = new PropsTester();
AbstractPropertyAccessor accessor = createAccessor(target);
accessor.setPropertyValue("intArray", new int[] {4, 5, 2, 3});
accessor.setPropertyValue("intArray", new int[]{4, 5, 2, 3});
assertThat(target.intArray.length == 4).as("intArray length = 4").isTrue();
assertThat(target.intArray[0] == 4 && target.intArray[1] == 5 &&
target.intArray[2] == 2 && target.intArray[3] == 3).as("correct values").isTrue();
@ -910,12 +910,12 @@ public abstract class AbstractPropertyAccessorTests {
}
});
accessor.setPropertyValue("intArray", new int[] {4, 5, 2, 3});
accessor.setPropertyValue("intArray", new int[]{4, 5, 2, 3});
assertThat(target.intArray.length == 4).as("intArray length = 4").isTrue();
assertThat(target.intArray[0] == 4 && target.intArray[1] == 5 &&
target.intArray[2] == 2 && target.intArray[3] == 3).as("correct values").isTrue();
accessor.setPropertyValue("intArray", new String[] {"3", "4", "1", "2"});
accessor.setPropertyValue("intArray", new String[]{"3", "4", "1", "2"});
assertThat(target.intArray.length == 4).as("intArray length = 4").isTrue();
assertThat(target.intArray[0] == 4 && target.intArray[1] == 5 &&
target.intArray[2] == 2 && target.intArray[3] == 3).as("correct values").isTrue();
@ -924,7 +924,7 @@ public abstract class AbstractPropertyAccessorTests {
assertThat(target.intArray.length == 1).as("intArray length = 4").isTrue();
assertThat(target.intArray[0] == 1).as("correct values").isTrue();
accessor.setPropertyValue("intArray", new String[] {"0"});
accessor.setPropertyValue("intArray", new String[]{"0"});
assertThat(target.intArray.length == 1).as("intArray length = 4").isTrue();
assertThat(target.intArray[0] == 1).as("correct values").isTrue();
@ -947,8 +947,8 @@ public abstract class AbstractPropertyAccessorTests {
public void setPrimitiveArrayProperty() {
PrimitiveArrayBean target = new PrimitiveArrayBean();
AbstractPropertyAccessor accessor = createAccessor(target);
accessor.setPropertyValue("array", new String[] {"1", "2"});
assertThat(target.getArray().length).isEqualTo(2);
accessor.setPropertyValue("array", new String[]{"1", "2"});
assertThat(target.getArray()).hasSize(2);
assertThat(target.getArray()[0]).isEqualTo(1);
assertThat(target.getArray()[1]).isEqualTo(2);
}
@ -967,7 +967,7 @@ public abstract class AbstractPropertyAccessorTests {
});
int[] input = new int[1024];
accessor.setPropertyValue("array", input);
assertThat(target.getArray().length).isEqualTo(1024);
assertThat(target.getArray()).hasSize(1024);
assertThat(target.getArray()[0]).isEqualTo(1);
assertThat(target.getArray()[1]).isEqualTo(1);
}
@ -986,8 +986,8 @@ public abstract class AbstractPropertyAccessorTests {
});
int[] input = new int[1024];
accessor.setPropertyValue("array", input);
assertThat(target.getArray().length).isEqualTo(1024);
assertThat(target.getArray()[0]).isEqualTo(0);
assertThat(target.getArray()).hasSize(1024);
assertThat(target.getArray()[0]).isZero();
assertThat(target.getArray()[1]).isEqualTo(1);
}
@ -998,10 +998,10 @@ public abstract class AbstractPropertyAccessorTests {
accessor.setAutoGrowNestedPaths(true);
accessor.setPropertyValue("array[0]", 1);
assertThat(target.getArray().length).isEqualTo(1);
assertThat(target.getArray()).hasSize(1);
accessor.setPropertyValue("array[2]", 3);
assertThat(target.getArray().length).isEqualTo(3);
assertThat(target.getArray()).hasSize(3);
assertThat(target.getArray()[0] == 1 && target.getArray()[1] == 0 &&
target.getArray()[2] == 3).as("correct values").isTrue();
}
@ -1018,7 +1018,7 @@ public abstract class AbstractPropertyAccessorTests {
values.add("4");
accessor.setPropertyValue("items", values);
Object[] result = target.items;
assertThat(result.length).isEqualTo(4);
assertThat(result).hasSize(4);
assertThat(result[0]).isEqualTo("1");
assertThat(result[1]).isEqualTo("2");
assertThat(result[2]).isEqualTo("3");
@ -1078,7 +1078,7 @@ public abstract class AbstractPropertyAccessorTests {
Set<String> list = new HashSet<>();
list.add("list1");
accessor.setPropertyValue("list", list);
assertThat(target.getCollection().size()).isEqualTo(1);
assertThat(target.getCollection()).hasSize(1);
assertThat(target.getCollection().containsAll(coll)).isTrue();
assertThat(target.getSet().size()).isEqualTo(1);
assertThat(target.getSet().containsAll(set)).isTrue();
@ -1105,7 +1105,7 @@ public abstract class AbstractPropertyAccessorTests {
Set<String> list = new HashSet<>();
list.add("list1");
accessor.setPropertyValue("list", list.toArray());
assertThat(target.getCollection().size()).isEqualTo(1);
assertThat(target.getCollection()).hasSize(1);
assertThat(target.getCollection().containsAll(coll)).isTrue();
assertThat(target.getSet().size()).isEqualTo(1);
assertThat(target.getSet().containsAll(set)).isTrue();
@ -1122,17 +1122,17 @@ public abstract class AbstractPropertyAccessorTests {
AbstractPropertyAccessor accessor = createAccessor(target);
Collection<Integer> coll = new HashSet<>();
coll.add(0);
accessor.setPropertyValue("collection", new int[] {0});
accessor.setPropertyValue("collection", new int[]{0});
List<Integer> set = new ArrayList<>();
set.add(1);
accessor.setPropertyValue("set", new int[] {1});
accessor.setPropertyValue("set", new int[]{1});
List<Integer> sortedSet = new ArrayList<>();
sortedSet.add(2);
accessor.setPropertyValue("sortedSet", new int[] {2});
accessor.setPropertyValue("sortedSet", new int[]{2});
Set<Integer> list = new HashSet<>();
list.add(3);
accessor.setPropertyValue("list", new int[] {3});
assertThat(target.getCollection().size()).isEqualTo(1);
accessor.setPropertyValue("list", new int[]{3});
assertThat(target.getCollection()).hasSize(1);
assertThat(target.getCollection().containsAll(coll)).isTrue();
assertThat(target.getSet().size()).isEqualTo(1);
assertThat(target.getSet().containsAll(set)).isTrue();
@ -1159,7 +1159,7 @@ public abstract class AbstractPropertyAccessorTests {
Set<Integer> list = new HashSet<>();
list.add(3);
accessor.setPropertyValue("list", 3);
assertThat(target.getCollection().size()).isEqualTo(1);
assertThat(target.getCollection()).hasSize(1);
assertThat(target.getCollection().containsAll(coll)).isTrue();
assertThat(target.getSet().size()).isEqualTo(1);
assertThat(target.getSet().containsAll(set)).isTrue();
@ -1236,7 +1236,7 @@ public abstract class AbstractPropertyAccessorTests {
Map<String, String> sortedMap = new TreeMap<>();
sortedMap.put("sortedKey", "sortedValue");
accessor.setPropertyValue("sortedMap", sortedMap);
assertThat(target.getMap().size()).isEqualTo(1);
assertThat(target.getMap()).hasSize(1);
assertThat(target.getMap().get("key")).isEqualTo("value");
assertThat(target.getSortedMap().size()).isEqualTo(1);
assertThat(target.getSortedMap().get("sortedKey")).isEqualTo("sortedValue");
@ -1527,7 +1527,7 @@ public abstract class AbstractPropertyAccessorTests {
assertThat((target.getList().get(0))).isEqualTo(tb3);
assertThat((target.getList().get(1))).isEqualTo(tb2);
assertThat((target.getList().get(2))).isEqualTo(tb0);
assertThat((target.getList().get(3))).isEqualTo(null);
assertThat((target.getList().get(3))).isNull();
assertThat((target.getList().get(4))).isEqualTo(tb1);
assertThat((target.getMap().get("key1"))).isEqualTo(tb1);
assertThat((target.getMap().get("key2"))).isEqualTo(tb0);
@ -1538,7 +1538,7 @@ public abstract class AbstractPropertyAccessorTests {
assertThat(accessor.getPropertyValue("list[0]")).isEqualTo(tb3);
assertThat(accessor.getPropertyValue("list[1]")).isEqualTo(tb2);
assertThat(accessor.getPropertyValue("list[2]")).isEqualTo(tb0);
assertThat(accessor.getPropertyValue("list[3]")).isEqualTo(null);
assertThat(accessor.getPropertyValue("list[3]")).isNull();
assertThat(accessor.getPropertyValue("list[4]")).isEqualTo(tb1);
assertThat(accessor.getPropertyValue("map[\"key1\"]")).isEqualTo(tb1);
assertThat(accessor.getPropertyValue("map['key2']")).isEqualTo(tb0);
@ -1582,7 +1582,7 @@ public abstract class AbstractPropertyAccessorTests {
public void propertyTypeIndexedProperty() {
IndexedTestBean target = new IndexedTestBean();
AbstractPropertyAccessor accessor = createAccessor(target);
assertThat(accessor.getPropertyType("map[key0]")).isEqualTo(null);
assertThat(accessor.getPropertyType("map[key0]")).isNull();
accessor = createAccessor(target);
accessor.setPropertyValue("map[key0]", "my String");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -46,10 +46,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Chris Beams
* @since 18.01.2006
*/
public class BeanWrapperGenericsTests {
class BeanWrapperGenericsTests {
@Test
public void testGenericSet() {
void testGenericSet() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
Set<String> input = new HashSet<>();
@ -61,7 +61,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericLowerBoundedSet() {
void testGenericLowerBoundedSet() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, true));
@ -74,7 +74,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericSetWithConversionFailure() {
void testGenericSetWithConversionFailure() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
Set<TestBean> input = new HashSet<>();
@ -85,7 +85,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericList() throws MalformedURLException {
void testGenericList() throws MalformedURLException {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
List<String> input = new ArrayList<>();
@ -97,7 +97,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericListElement() throws MalformedURLException {
void testGenericListElement() throws MalformedURLException {
GenericBean<?> gb = new GenericBean<>();
gb.setResourceList(new ArrayList<>());
BeanWrapper bw = new BeanWrapperImpl(gb);
@ -106,29 +106,29 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericMap() {
void testGenericMap() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
Map<String, String> input = new HashMap<>();
input.put("4", "5");
input.put("6", "7");
bw.setPropertyValue("shortMap", input);
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
}
@Test
public void testGenericMapElement() {
void testGenericMapElement() {
GenericBean<?> gb = new GenericBean<>();
gb.setShortMap(new HashMap<>());
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("shortMap[4]", "5");
assertThat(bw.getPropertyValue("shortMap[4]")).isEqualTo(5);
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
}
@Test
public void testGenericMapWithKeyType() {
void testGenericMapWithKeyType() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
Map<String, String> input = new HashMap<>();
@ -140,17 +140,17 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericMapElementWithKeyType() {
void testGenericMapElementWithKeyType() {
GenericBean<?> gb = new GenericBean<>();
gb.setLongMap(new HashMap<Long, Integer>());
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("longMap[4]", "5");
assertThat(gb.getLongMap().get(new Long("4"))).isEqualTo("5");
assertThat(gb.getLongMap().get(Long.valueOf("4"))).isEqualTo("5");
assertThat(bw.getPropertyValue("longMap[4]")).isEqualTo("5");
}
@Test
public void testGenericMapWithCollectionValue() {
void testGenericMapWithCollectionValue() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
@ -169,7 +169,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericMapElementWithCollectionValue() {
void testGenericMapElementWithCollectionValue() {
GenericBean<?> gb = new GenericBean<>();
gb.setCollectionMap(new HashMap<>());
BeanWrapper bw = new BeanWrapperImpl(gb);
@ -182,19 +182,19 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericMapFromProperties() {
void testGenericMapFromProperties() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
Properties input = new Properties();
input.setProperty("4", "5");
input.setProperty("6", "7");
bw.setPropertyValue("shortMap", input);
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
}
@Test
public void testGenericListOfLists() throws MalformedURLException {
void testGenericListOfLists() throws MalformedURLException {
GenericBean<String> gb = new GenericBean<>();
List<List<Integer>> list = new ArrayList<>();
list.add(new ArrayList<>());
@ -206,7 +206,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericListOfListsWithElementConversion() throws MalformedURLException {
void testGenericListOfListsWithElementConversion() throws MalformedURLException {
GenericBean<String> gb = new GenericBean<>();
List<List<Integer>> list = new ArrayList<>();
list.add(new ArrayList<>());
@ -218,7 +218,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericListOfArrays() throws MalformedURLException {
void testGenericListOfArrays() throws MalformedURLException {
GenericBean<String> gb = new GenericBean<>();
ArrayList<String[]> list = new ArrayList<>();
list.add(new String[] {"str1", "str2"});
@ -230,7 +230,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericListOfArraysWithElementConversion() throws MalformedURLException {
void testGenericListOfArraysWithElementConversion() throws MalformedURLException {
GenericBean<String> gb = new GenericBean<>();
ArrayList<String[]> list = new ArrayList<>();
list.add(new String[] {"str1", "str2"});
@ -243,55 +243,55 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericListOfMaps() throws MalformedURLException {
void testGenericListOfMaps() throws MalformedURLException {
GenericBean<String> gb = new GenericBean<>();
List<Map<Integer, Long>> list = new ArrayList<>();
list.add(new HashMap<>());
gb.setListOfMaps(list);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("listOfMaps[0][10]", new Long(5));
assertThat(bw.getPropertyValue("listOfMaps[0][10]")).isEqualTo(new Long(5));
assertThat(gb.getListOfMaps().get(0).get(10)).isEqualTo(new Long(5));
bw.setPropertyValue("listOfMaps[0][10]", 5L);
assertThat(bw.getPropertyValue("listOfMaps[0][10]")).isEqualTo(5L);
assertThat(gb.getListOfMaps().get(0).get(10)).isEqualTo(Long.valueOf(5));
}
@Test
public void testGenericListOfMapsWithElementConversion() throws MalformedURLException {
void testGenericListOfMapsWithElementConversion() {
GenericBean<String> gb = new GenericBean<>();
List<Map<Integer, Long>> list = new ArrayList<>();
list.add(new HashMap<>());
gb.setListOfMaps(list);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("listOfMaps[0][10]", "5");
assertThat(bw.getPropertyValue("listOfMaps[0][10]")).isEqualTo(new Long(5));
assertThat(gb.getListOfMaps().get(0).get(10)).isEqualTo(new Long(5));
assertThat(bw.getPropertyValue("listOfMaps[0][10]")).isEqualTo(5L);
assertThat(gb.getListOfMaps().get(0).get(10)).isEqualTo(Long.valueOf(5));
}
@Test
public void testGenericMapOfMaps() throws MalformedURLException {
void testGenericMapOfMaps() throws MalformedURLException {
GenericBean<String> gb = new GenericBean<>();
Map<String, Map<Integer, Long>> map = new HashMap<>();
map.put("mykey", new HashMap<>());
gb.setMapOfMaps(map);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("mapOfMaps[mykey][10]", new Long(5));
assertThat(bw.getPropertyValue("mapOfMaps[mykey][10]")).isEqualTo(new Long(5));
assertThat(gb.getMapOfMaps().get("mykey").get(10)).isEqualTo(new Long(5));
bw.setPropertyValue("mapOfMaps[mykey][10]", 5L);
assertThat(bw.getPropertyValue("mapOfMaps[mykey][10]")).isEqualTo(5L);
assertThat(gb.getMapOfMaps().get("mykey").get(10)).isEqualTo(Long.valueOf(5));
}
@Test
public void testGenericMapOfMapsWithElementConversion() throws MalformedURLException {
void testGenericMapOfMapsWithElementConversion() throws MalformedURLException {
GenericBean<String> gb = new GenericBean<>();
Map<String, Map<Integer, Long>> map = new HashMap<>();
map.put("mykey", new HashMap<>());
gb.setMapOfMaps(map);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("mapOfMaps[mykey][10]", "5");
assertThat(bw.getPropertyValue("mapOfMaps[mykey][10]")).isEqualTo(new Long(5));
assertThat(gb.getMapOfMaps().get("mykey").get(10)).isEqualTo(new Long(5));
assertThat(bw.getPropertyValue("mapOfMaps[mykey][10]")).isEqualTo(Long.valueOf(5));
assertThat(gb.getMapOfMaps().get("mykey").get(10)).isEqualTo(Long.valueOf(5));
}
@Test
public void testGenericMapOfLists() throws MalformedURLException {
void testGenericMapOfLists() throws MalformedURLException {
GenericBean<String> gb = new GenericBean<>();
Map<Integer, List<Integer>> map = new HashMap<>();
map.put(1, new ArrayList<>());
@ -303,7 +303,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericMapOfListsWithElementConversion() throws MalformedURLException {
void testGenericMapOfListsWithElementConversion() throws MalformedURLException {
GenericBean<String> gb = new GenericBean<>();
Map<Integer, List<Integer>> map = new HashMap<>();
map.put(1, new ArrayList<>());
@ -315,7 +315,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericTypeNestingMapOfInteger() throws Exception {
void testGenericTypeNestingMapOfInteger() throws Exception {
Map<String, String> map = new HashMap<>();
map.put("testKey", "100");
@ -329,9 +329,9 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericTypeNestingMapOfListOfInteger() throws Exception {
void testGenericTypeNestingMapOfListOfInteger() throws Exception {
Map<String, List<String>> map = new HashMap<>();
List<String> list = Arrays.asList(new String[] {"1", "2", "3"});
List<String> list = Arrays.asList("1", "2", "3");
map.put("testKey", list);
NestedGenericCollectionBean gb = new NestedGenericCollectionBean();
@ -345,7 +345,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericTypeNestingListOfMapOfInteger() throws Exception {
void testGenericTypeNestingListOfMapOfInteger() throws Exception {
List<Map<String, String>> list = new ArrayList<>();
Map<String, String> map = new HashMap<>();
map.put("testKey", "5");
@ -362,9 +362,9 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericTypeNestingMapOfListOfListOfInteger() throws Exception {
void testGenericTypeNestingMapOfListOfListOfInteger() throws Exception {
Map<String, List<List<String>>> map = new HashMap<>();
List<String> list = Arrays.asList(new String[] {"1", "2", "3"});
List<String> list = Arrays.asList("1", "2", "3");
map.put("testKey", Collections.singletonList(list));
NestedGenericCollectionBean gb = new NestedGenericCollectionBean();
@ -378,7 +378,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testComplexGenericMap() {
void testComplexGenericMap() {
Map<List<String>, List<String>> inputMap = new HashMap<>();
List<String> inputKey = new ArrayList<>();
inputKey.add("1");
@ -391,11 +391,11 @@ public class BeanWrapperGenericsTests {
bw.setPropertyValue("genericMap", inputMap);
assertThat(holder.getGenericMap().keySet().iterator().next().get(0)).isEqualTo(1);
assertThat(holder.getGenericMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
assertThat(holder.getGenericMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
}
@Test
public void testComplexGenericMapWithCollectionConversion() {
void testComplexGenericMapWithCollectionConversion() {
Map<Set<String>, Set<String>> inputMap = new HashMap<>();
Set<String> inputKey = new HashSet<>();
inputKey.add("1");
@ -408,11 +408,11 @@ public class BeanWrapperGenericsTests {
bw.setPropertyValue("genericMap", inputMap);
assertThat(holder.getGenericMap().keySet().iterator().next().get(0)).isEqualTo(1);
assertThat(holder.getGenericMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
assertThat(holder.getGenericMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
}
@Test
public void testComplexGenericIndexedMapEntry() {
void testComplexGenericIndexedMapEntry() {
List<String> inputValue = new ArrayList<>();
inputValue.add("10");
@ -421,11 +421,11 @@ public class BeanWrapperGenericsTests {
bw.setPropertyValue("genericIndexedMap[1]", inputValue);
assertThat(holder.getGenericIndexedMap().keySet().iterator().next()).isEqualTo(1);
assertThat(holder.getGenericIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
assertThat(holder.getGenericIndexedMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
}
@Test
public void testComplexGenericIndexedMapEntryWithCollectionConversion() {
void testComplexGenericIndexedMapEntryWithCollectionConversion() {
Set<String> inputValue = new HashSet<>();
inputValue.add("10");
@ -434,11 +434,11 @@ public class BeanWrapperGenericsTests {
bw.setPropertyValue("genericIndexedMap[1]", inputValue);
assertThat(holder.getGenericIndexedMap().keySet().iterator().next()).isEqualTo(1);
assertThat(holder.getGenericIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
assertThat(holder.getGenericIndexedMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
}
@Test
public void testComplexDerivedIndexedMapEntry() {
void testComplexDerivedIndexedMapEntry() {
List<String> inputValue = new ArrayList<>();
inputValue.add("10");
@ -447,11 +447,11 @@ public class BeanWrapperGenericsTests {
bw.setPropertyValue("derivedIndexedMap[1]", inputValue);
assertThat(holder.getDerivedIndexedMap().keySet().iterator().next()).isEqualTo(1);
assertThat(holder.getDerivedIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
assertThat(holder.getDerivedIndexedMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
}
@Test
public void testComplexDerivedIndexedMapEntryWithCollectionConversion() {
void testComplexDerivedIndexedMapEntryWithCollectionConversion() {
Set<String> inputValue = new HashSet<>();
inputValue.add("10");
@ -460,11 +460,11 @@ public class BeanWrapperGenericsTests {
bw.setPropertyValue("derivedIndexedMap[1]", inputValue);
assertThat(holder.getDerivedIndexedMap().keySet().iterator().next()).isEqualTo(1);
assertThat(holder.getDerivedIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
assertThat(holder.getDerivedIndexedMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
}
@Test
public void testGenericallyTypedIntegerBean() throws Exception {
void testGenericallyTypedIntegerBean() {
GenericIntegerBean gb = new GenericIntegerBean();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("genericProperty", "10");
@ -475,7 +475,7 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testGenericallyTypedSetOfIntegerBean() throws Exception {
void testGenericallyTypedSetOfIntegerBean() {
GenericSetOfIntegerBean gb = new GenericSetOfIntegerBean();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("genericProperty", "10");
@ -486,23 +486,23 @@ public class BeanWrapperGenericsTests {
}
@Test
public void testSettingGenericPropertyWithReadOnlyInterface() {
void testSettingGenericPropertyWithReadOnlyInterface() {
Bar bar = new Bar();
BeanWrapper bw = new BeanWrapperImpl(bar);
bw.setPropertyValue("version", "10");
assertThat(bar.getVersion()).isEqualTo(new Double(10.0));
assertThat(bar.getVersion()).isEqualTo(Double.valueOf(10.0));
}
@Test
public void testSettingLongPropertyWithGenericInterface() {
void testSettingLongPropertyWithGenericInterface() {
Promotion bean = new Promotion();
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.setPropertyValue("id", "10");
assertThat(bean.getId()).isEqualTo(new Long(10));
assertThat(bean.getId()).isEqualTo(Long.valueOf(10));
}
@Test
public void testUntypedPropertyWithMapAtRuntime() {
void testUntypedPropertyWithMapAtRuntime() {
class Holder<D> {
private final D data;
public Holder(D data) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -182,9 +182,9 @@ class DefaultListableBeanFactoryTests {
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertThat(beanNames.length).isEqualTo(0);
assertThat(beanNames).hasSize(0);
beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
assertThat(beanNames.length).isEqualTo(0);
assertThat(beanNames).hasSize(0);
assertThat(lbf.containsSingleton("x1")).isFalse();
assertThat(lbf.containsBean("x1")).isTrue();
@ -216,9 +216,9 @@ class DefaultListableBeanFactoryTests {
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertThat(beanNames.length).isEqualTo(0);
assertThat(beanNames).hasSize(0);
beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
assertThat(beanNames.length).isEqualTo(0);
assertThat(beanNames).hasSize(0);
assertThat(lbf.containsSingleton("x1")).isFalse();
assertThat(lbf.containsBean("x1")).isTrue();
@ -249,9 +249,9 @@ class DefaultListableBeanFactoryTests {
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertThat(beanNames.length).isEqualTo(0);
assertThat(beanNames).hasSize(0);
beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
assertThat(beanNames.length).isEqualTo(0);
assertThat(beanNames).hasSize(0);
assertThat(lbf.containsSingleton("x1")).isFalse();
assertThat(lbf.containsBean("x1")).isTrue();
@ -283,7 +283,7 @@ class DefaultListableBeanFactoryTests {
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames).hasSize(1);
assertThat(beanNames[0]).isEqualTo("x1");
assertThat(lbf.containsSingleton("x1")).isTrue();
assertThat(lbf.containsBean("x1")).isTrue();
@ -337,7 +337,7 @@ class DefaultListableBeanFactoryTests {
TestBeanFactory.initialized = false;
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames).hasSize(1);
assertThat(beanNames[0]).isEqualTo("x1");
assertThat(lbf.containsSingleton("x1")).isFalse();
assertThat(lbf.containsBean("x1")).isTrue();
@ -349,7 +349,7 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.isTypeMatch("x1", TestBean.class)).isTrue();
assertThat(lbf.isTypeMatch("&x1", TestBean.class)).isFalse();
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
assertThat(lbf.getType("&x1")).isEqualTo(null);
assertThat(lbf.getType("&x1")).isNull();
assertThat(TestBeanFactory.initialized).isFalse();
}
@ -362,7 +362,7 @@ class DefaultListableBeanFactoryTests {
TestBeanFactory.initialized = false;
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames).hasSize(1);
assertThat(beanNames[0]).isEqualTo("x1");
assertThat(lbf.containsSingleton("x1")).isFalse();
assertThat(lbf.containsBean("x1")).isTrue();
@ -374,7 +374,7 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.isTypeMatch("x1", TestBean.class)).isTrue();
assertThat(lbf.isTypeMatch("&x1", TestBean.class)).isFalse();
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
assertThat(lbf.getType("&x1")).isEqualTo(null);
assertThat(lbf.getType("&x1")).isNull();
assertThat(TestBeanFactory.initialized).isFalse();
}
@ -389,7 +389,7 @@ class DefaultListableBeanFactoryTests {
TestBeanFactory.initialized = false;
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames).hasSize(1);
assertThat(beanNames[0]).isEqualTo("x1");
assertThat(lbf.containsSingleton("x1")).isFalse();
assertThat(lbf.containsBean("x1")).isTrue();
@ -401,7 +401,7 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.isTypeMatch("x1", TestBean.class)).isTrue();
assertThat(lbf.isTypeMatch("&x1", TestBean.class)).isFalse();
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
assertThat(lbf.getType("&x1")).isEqualTo(null);
assertThat(lbf.getType("&x1")).isNull();
assertThat(TestBeanFactory.initialized).isFalse();
}
@ -417,7 +417,7 @@ class DefaultListableBeanFactoryTests {
TestBeanFactory.initialized = false;
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames).hasSize(1);
assertThat(beanNames[0]).isEqualTo("x1");
assertThat(lbf.containsSingleton("x1")).isFalse();
assertThat(lbf.containsBean("x1")).isTrue();
@ -450,7 +450,7 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.isTypeMatch("x2", Object.class)).isTrue();
assertThat(lbf.isTypeMatch("&x2", Object.class)).isFalse();
assertThat(lbf.getType("x2")).isEqualTo(TestBean.class);
assertThat(lbf.getType("&x2")).isEqualTo(null);
assertThat(lbf.getType("&x2")).isNull();
assertThat(lbf.getAliases("x1").length).isEqualTo(1);
assertThat(lbf.getAliases("x1")[0]).isEqualTo("x2");
assertThat(lbf.getAliases("&x1").length).isEqualTo(1);
@ -3030,7 +3030,7 @@ class DefaultListableBeanFactoryTests {
public Object convertIfNecessary(Object value, @Nullable Class requiredType) {
if (value instanceof String && Float.class.isAssignableFrom(requiredType)) {
try {
return new Float(this.numberFormat.parse((String) value).floatValue());
return this.numberFormat.parse((String) value).floatValue();
}
catch (ParseException ex) {
throw new TypeMismatchException(value, requiredType, ex);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -64,10 +64,10 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
* @author Sam Brannen
* @since 20.01.2006
*/
public class BeanFactoryGenericsTests {
class BeanFactoryGenericsTests {
@Test
public void testGenericSetProperty() {
void testGenericSetProperty() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -84,7 +84,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericListProperty() throws Exception {
void testGenericListProperty() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -101,7 +101,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericListPropertyWithAutowiring() throws Exception {
void testGenericListPropertyWithAutowiring() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
@ -116,7 +116,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericListPropertyWithInvalidElementType() {
void testGenericListPropertyWithInvalidElementType() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericIntegerBean.class);
@ -134,7 +134,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericListPropertyWithOptionalAutowiring() {
void testGenericListPropertyWithOptionalAutowiring() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -146,7 +146,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericMapProperty() {
void testGenericMapProperty() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -158,12 +158,12 @@ public class BeanFactoryGenericsTests {
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
}
@Test
public void testGenericListOfArraysProperty() {
void testGenericListOfArraysProperty() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
@ -171,14 +171,14 @@ public class BeanFactoryGenericsTests {
assertThat(gb.getListOfArrays().size()).isEqualTo(1);
String[] array = gb.getListOfArrays().get(0);
assertThat(array.length).isEqualTo(2);
assertThat(array).hasSize(2);
assertThat(array[0]).isEqualTo("value1");
assertThat(array[1]).isEqualTo("value2");
}
@Test
public void testGenericSetConstructor() {
void testGenericSetConstructor() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -195,7 +195,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericSetConstructorWithAutowiring() {
void testGenericSetConstructorWithAutowiring() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerSingleton("integer1", 4);
bf.registerSingleton("integer2", 5);
@ -210,7 +210,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericSetConstructorWithOptionalAutowiring() {
void testGenericSetConstructorWithOptionalAutowiring() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -222,7 +222,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericSetListConstructor() throws Exception {
void testGenericSetListConstructor() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -245,7 +245,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericSetListConstructorWithAutowiring() throws Exception {
void testGenericSetListConstructorWithAutowiring() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerSingleton("integer1", 4);
bf.registerSingleton("integer2", 5);
@ -264,7 +264,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericSetListConstructorWithOptionalAutowiring() throws Exception {
void testGenericSetListConstructorWithOptionalAutowiring() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
@ -279,7 +279,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericSetMapConstructor() {
void testGenericSetMapConstructor() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -297,12 +297,12 @@ public class BeanFactoryGenericsTests {
assertThat(gb.getIntegerSet().contains(4)).isTrue();
assertThat(gb.getIntegerSet().contains(5)).isTrue();
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
}
@Test
public void testGenericMapResourceConstructor() throws Exception {
void testGenericMapResourceConstructor() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -315,13 +315,13 @@ public class BeanFactoryGenericsTests {
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
assertThat(gb.getResourceList().get(0)).isEqualTo(new UrlResource("http://localhost:8080"));
}
@Test
public void testGenericMapMapConstructor() {
void testGenericMapMapConstructor() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -338,16 +338,16 @@ public class BeanFactoryGenericsTests {
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
assertThat(gb.getShortMap()).isNotSameAs(gb.getPlainMap());
assertThat(gb.getPlainMap().size()).isEqualTo(2);
assertThat(gb.getPlainMap()).hasSize(2);
assertThat(gb.getPlainMap().get("1")).isEqualTo("0");
assertThat(gb.getPlainMap().get("2")).isEqualTo("3");
assertThat(gb.getShortMap().size()).isEqualTo(2);
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
}
@Test
public void testGenericMapMapConstructorWithSameRefAndConversion() {
void testGenericMapMapConstructorWithSameRefAndConversion() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -361,22 +361,22 @@ public class BeanFactoryGenericsTests {
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
assertThat(gb.getShortMap()).isNotSameAs(gb.getPlainMap());
assertThat(gb.getPlainMap().size()).isEqualTo(2);
assertThat(gb.getPlainMap()).hasSize(2);
assertThat(gb.getPlainMap().get("1")).isEqualTo("0");
assertThat(gb.getPlainMap().get("2")).isEqualTo("3");
assertThat(gb.getShortMap().size()).isEqualTo(2);
assertThat(gb.getShortMap().get(new Short("1"))).isEqualTo(0);
assertThat(gb.getShortMap().get(new Short("2"))).isEqualTo(3);
assertThat(gb.getShortMap().get(Short.valueOf("1"))).isEqualTo(0);
assertThat(gb.getShortMap().get(Short.valueOf("2"))).isEqualTo(3);
}
@Test
public void testGenericMapMapConstructorWithSameRefAndNoConversion() {
void testGenericMapMapConstructorWithSameRefAndNoConversion() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
Map<Short, Integer> input = new HashMap<>();
input.put(new Short((short) 1), 0);
input.put(new Short((short) 2), 3);
input.put((short) 1, 0);
input.put((short) 2, 3);
rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
@ -384,13 +384,13 @@ public class BeanFactoryGenericsTests {
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
assertThat(gb.getShortMap()).isSameAs(gb.getPlainMap());
assertThat(gb.getShortMap().size()).isEqualTo(2);
assertThat(gb.getShortMap().get(new Short("1"))).isEqualTo(0);
assertThat(gb.getShortMap().get(new Short("2"))).isEqualTo(3);
assertThat(gb.getShortMap()).hasSize(2);
assertThat(gb.getShortMap().get(Short.valueOf("1"))).isEqualTo(0);
assertThat(gb.getShortMap().get(Short.valueOf("2"))).isEqualTo(3);
}
@Test
public void testGenericMapWithKeyTypeConstructor() {
void testGenericMapWithKeyTypeConstructor() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
@ -407,7 +407,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericMapWithCollectionValueConstructor() {
void testGenericMapWithCollectionValueConstructor() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
@Override
@ -438,7 +438,7 @@ public class BeanFactoryGenericsTests {
@Test
public void testGenericSetFactoryMethod() {
void testGenericSetFactoryMethod() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setFactoryMethodName("createInstance");
@ -456,7 +456,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericSetListFactoryMethod() throws Exception {
void testGenericSetListFactoryMethod() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setFactoryMethodName("createInstance");
@ -480,7 +480,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericSetMapFactoryMethod() {
void testGenericSetMapFactoryMethod() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setFactoryMethodName("createInstance");
@ -499,12 +499,12 @@ public class BeanFactoryGenericsTests {
assertThat(gb.getIntegerSet().contains(4)).isTrue();
assertThat(gb.getIntegerSet().contains(5)).isTrue();
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
}
@Test
public void testGenericMapResourceFactoryMethod() throws Exception {
void testGenericMapResourceFactoryMethod() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setFactoryMethodName("createInstance");
@ -518,13 +518,13 @@ public class BeanFactoryGenericsTests {
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
assertThat(gb.getResourceList().get(0)).isEqualTo(new UrlResource("http://localhost:8080"));
}
@Test
public void testGenericMapMapFactoryMethod() {
void testGenericMapMapFactoryMethod() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setFactoryMethodName("createInstance");
@ -543,12 +543,12 @@ public class BeanFactoryGenericsTests {
assertThat(gb.getPlainMap().get("1")).isEqualTo("0");
assertThat(gb.getPlainMap().get("2")).isEqualTo("3");
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
}
@Test
public void testGenericMapWithKeyTypeFactoryMethod() {
void testGenericMapWithKeyTypeFactoryMethod() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setFactoryMethodName("createInstance");
@ -561,12 +561,12 @@ public class BeanFactoryGenericsTests {
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
assertThat(gb.getLongMap().get(new Long("4"))).isEqualTo("5");
assertThat(gb.getLongMap().get(new Long("6"))).isEqualTo("7");
assertThat(gb.getLongMap().get(Long.valueOf("4"))).isEqualTo("5");
assertThat(gb.getLongMap().get(Long.valueOf("6"))).isEqualTo("7");
}
@Test
public void testGenericMapWithCollectionValueFactoryMethod() {
void testGenericMapWithCollectionValueFactoryMethod() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
@Override
@ -597,7 +597,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericListBean() throws Exception {
void testGenericListBean() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
@ -607,7 +607,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericSetBean() throws Exception {
void testGenericSetBean() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
@ -617,18 +617,18 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericMapBean() throws Exception {
void testGenericMapBean() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
Map<?, ?> map = (Map<?, ?>) bf.getBean("map");
assertThat(map.size()).isEqualTo(1);
assertThat(map).hasSize(1);
assertThat(map.keySet().iterator().next()).isEqualTo(10);
assertThat(map.values().iterator().next()).isEqualTo(new URL("http://localhost:8080"));
}
@Test
public void testGenericallyTypedIntegerBean() {
void testGenericallyTypedIntegerBean() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
@ -639,7 +639,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericallyTypedSetOfIntegerBean() {
void testGenericallyTypedSetOfIntegerBean() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
@ -651,7 +651,7 @@ public class BeanFactoryGenericsTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
public void testSetBean() throws Exception {
void testSetBean() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
@ -671,7 +671,7 @@ public class BeanFactoryGenericsTests {
* <p>See SPR-9493
*/
@Test
public void parameterizedStaticFactoryMethod() {
void parameterizedStaticFactoryMethod() {
RootBeanDefinition rbd = new RootBeanDefinition(Mockito.class);
rbd.setFactoryMethodName("mock");
rbd.getConstructorArgumentValues().addGenericArgumentValue(Runnable.class);
@ -682,7 +682,7 @@ public class BeanFactoryGenericsTests {
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
assertThat(beans.size()).isEqualTo(1);
assertThat(beans).hasSize(1);
}
/**
@ -697,7 +697,7 @@ public class BeanFactoryGenericsTests {
* <p>See SPR-10411
*/
@Test
public void parameterizedInstanceFactoryMethod() {
void parameterizedInstanceFactoryMethod() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(MocksControl.class);
@ -714,11 +714,11 @@ public class BeanFactoryGenericsTests {
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
assertThat(beans.size()).isEqualTo(1);
assertThat(beans).hasSize(1);
}
@Test
public void parameterizedInstanceFactoryMethodWithNonResolvedClassName() {
void parameterizedInstanceFactoryMethodWithNonResolvedClassName() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(MocksControl.class);
@ -735,11 +735,11 @@ public class BeanFactoryGenericsTests {
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
assertThat(beans.size()).isEqualTo(1);
assertThat(beans).hasSize(1);
}
@Test
public void parameterizedInstanceFactoryMethodWithWrappedClassName() {
void parameterizedInstanceFactoryMethodWithWrappedClassName() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition();
@ -754,11 +754,11 @@ public class BeanFactoryGenericsTests {
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
assertThat(beans.size()).isEqualTo(1);
assertThat(beans).hasSize(1);
}
@Test
public void parameterizedInstanceFactoryMethodWithInvalidClassName() {
void parameterizedInstanceFactoryMethodWithInvalidClassName() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(MocksControl.class);
@ -775,11 +775,11 @@ public class BeanFactoryGenericsTests {
assertThat(bf.getType("mock")).isNull();
assertThat(bf.getType("mock")).isNull();
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
assertThat(beans.size()).isEqualTo(0);
assertThat(beans).hasSize(0);
}
@Test
public void parameterizedInstanceFactoryMethodWithIndexedArgument() {
void parameterizedInstanceFactoryMethodWithIndexedArgument() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(MocksControl.class);
@ -796,11 +796,11 @@ public class BeanFactoryGenericsTests {
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
assertThat(beans.size()).isEqualTo(1);
assertThat(beans).hasSize(1);
}
@Test // SPR-16720
public void parameterizedInstanceFactoryMethodWithTempClassLoader() {
void parameterizedInstanceFactoryMethodWithTempClassLoader() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setTempClassLoader(new OverridingClassLoader(getClass().getClassLoader()));
@ -818,11 +818,11 @@ public class BeanFactoryGenericsTests {
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
assertThat(beans.size()).isEqualTo(1);
assertThat(beans).hasSize(1);
}
@Test
public void testGenericMatchingWithBeanNameDifferentiation() {
void testGenericMatchingWithBeanNameDifferentiation() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setAutowireCandidateResolver(new GenericTypeAwareAutowireCandidateResolver());
@ -838,15 +838,15 @@ public class BeanFactoryGenericsTests {
String[] numberStoreNames = bf.getBeanNamesForType(ResolvableType.forClass(NumberStore.class));
String[] doubleStoreNames = bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(NumberStore.class, Double.class));
String[] floatStoreNames = bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(NumberStore.class, Float.class));
assertThat(numberStoreNames.length).isEqualTo(2);
assertThat(numberStoreNames).hasSize(2);
assertThat(numberStoreNames[0]).isEqualTo("doubleStore");
assertThat(numberStoreNames[1]).isEqualTo("floatStore");
assertThat(doubleStoreNames.length).isEqualTo(0);
assertThat(floatStoreNames.length).isEqualTo(0);
assertThat(doubleStoreNames).hasSize(0);
assertThat(floatStoreNames).hasSize(0);
}
@Test
public void testGenericMatchingWithFullTypeDifferentiation() {
void testGenericMatchingWithFullTypeDifferentiation() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
bf.setAutowireCandidateResolver(new GenericTypeAwareAutowireCandidateResolver());
@ -867,12 +867,12 @@ public class BeanFactoryGenericsTests {
String[] numberStoreNames = bf.getBeanNamesForType(ResolvableType.forClass(NumberStore.class));
String[] doubleStoreNames = bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(NumberStore.class, Double.class));
String[] floatStoreNames = bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(NumberStore.class, Float.class));
assertThat(numberStoreNames.length).isEqualTo(2);
assertThat(numberStoreNames).hasSize(2);
assertThat(numberStoreNames[0]).isEqualTo("store1");
assertThat(numberStoreNames[1]).isEqualTo("store2");
assertThat(doubleStoreNames.length).isEqualTo(1);
assertThat(doubleStoreNames).hasSize(1);
assertThat(doubleStoreNames[0]).isEqualTo("store1");
assertThat(floatStoreNames.length).isEqualTo(1);
assertThat(floatStoreNames).hasSize(1);
assertThat(floatStoreNames[0]).isEqualTo("store2");
ObjectProvider<NumberStore<?>> numberStoreProvider = bf.getBeanProvider(ResolvableType.forClass(NumberStore.class));
@ -938,7 +938,7 @@ public class BeanFactoryGenericsTests {
}
@Test
public void testGenericMatchingWithUnresolvedOrderedStream() {
void testGenericMatchingWithUnresolvedOrderedStream() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
bf.setAutowireCandidateResolver(new GenericTypeAwareAutowireCandidateResolver());

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -26,18 +26,18 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
*
* @author Rick Evans
*/
public class ClassNameBeanWiringInfoResolverTests {
class ClassNameBeanWiringInfoResolverTests {
@Test
public void resolveWiringInfoWithNullBeanInstance() throws Exception {
void resolveWiringInfoWithNullBeanInstance() throws Exception {
assertThatIllegalArgumentException().isThrownBy(() ->
new ClassNameBeanWiringInfoResolver().resolveWiringInfo(null));
}
@Test
public void resolveWiringInfo() {
void resolveWiringInfo() {
ClassNameBeanWiringInfoResolver resolver = new ClassNameBeanWiringInfoResolver();
Long beanInstance = new Long(1);
Long beanInstance = 1L;
BeanWiringInfo info = resolver.resolveWiringInfo(beanInstance);
assertThat(info).isNotNull();
assertThat(info.getBeanName()).as("Not resolving bean name to the class name of the supplied bean instance as per class contract.").isEqualTo(beanInstance.getClass().getName());

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -64,10 +64,10 @@ import static org.assertj.core.api.Assertions.within;
* @author Chris Beams
* @since 10.06.2003
*/
public class CustomEditorTests {
class CustomEditorTests {
@Test
public void testComplexObject() {
void testComplexObject() {
TestBean tb = new TestBean();
String newName = "Rod";
String tbString = "Kerry_34";
@ -80,12 +80,12 @@ public class CustomEditorTests {
pvs.addPropertyValue(new PropertyValue("touchy", "valid"));
pvs.addPropertyValue(new PropertyValue("spouse", tbString));
bw.setPropertyValues(pvs);
assertThat(tb.getSpouse() != null).as("spouse is non-null").isTrue();
assertThat(tb.getSpouse()).as("spouse is non-null").isNotNull();
assertThat(tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34).as("spouse name is Kerry and age is 34").isTrue();
}
@Test
public void testComplexObjectWithOldValueAccess() {
void testComplexObjectWithOldValueAccess() {
TestBean tb = new TestBean();
String newName = "Rod";
String tbString = "Kerry_34";
@ -100,7 +100,7 @@ public class CustomEditorTests {
pvs.addPropertyValue(new PropertyValue("spouse", tbString));
bw.setPropertyValues(pvs);
assertThat(tb.getSpouse() != null).as("spouse is non-null").isTrue();
assertThat(tb.getSpouse()).as("spouse is non-null").isNotNull();
assertThat(tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34).as("spouse name is Kerry and age is 34").isTrue();
ITestBean spouse = tb.getSpouse();
@ -109,7 +109,7 @@ public class CustomEditorTests {
}
@Test
public void testCustomEditorForSingleProperty() {
void testCustomEditorForSingleProperty() {
TestBean tb = new TestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(String.class, "name", new PropertyEditorSupport() {
@ -127,7 +127,7 @@ public class CustomEditorTests {
}
@Test
public void testCustomEditorForAllStringProperties() {
void testCustomEditorForAllStringProperties() {
TestBean tb = new TestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
@ -145,7 +145,7 @@ public class CustomEditorTests {
}
@Test
public void testCustomEditorForSingleNestedProperty() {
void testCustomEditorForSingleNestedProperty() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
BeanWrapper bw = new BeanWrapperImpl(tb);
@ -164,7 +164,7 @@ public class CustomEditorTests {
}
@Test
public void testCustomEditorForAllNestedStringProperties() {
void testCustomEditorForAllNestedStringProperties() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
BeanWrapper bw = new BeanWrapperImpl(tb);
@ -183,7 +183,7 @@ public class CustomEditorTests {
}
@Test
public void testDefaultBooleanEditorForPrimitiveType() {
void testDefaultBooleanEditorForPrimitiveType() {
BooleanTestBean tb = new BooleanTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
@ -229,7 +229,7 @@ public class CustomEditorTests {
}
@Test
public void testDefaultBooleanEditorForWrapperType() {
void testDefaultBooleanEditorForWrapperType() {
BooleanTestBean tb = new BooleanTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
@ -239,28 +239,28 @@ public class CustomEditorTests {
bw.setPropertyValue("bool2", "false");
assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
boolean condition3 = !tb.getBool2().booleanValue();
boolean condition3 = !tb.getBool2();
assertThat(condition3).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "on");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "off");
boolean condition2 = !tb.getBool2().booleanValue();
boolean condition2 = !tb.getBool2();
assertThat(condition2).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "yes");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "no");
boolean condition1 = !tb.getBool2().booleanValue();
boolean condition1 = !tb.getBool2();
assertThat(condition1).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "1");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "0");
boolean condition = !tb.getBool2().booleanValue();
boolean condition = !tb.getBool2();
assertThat(condition).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "");
@ -268,7 +268,7 @@ public class CustomEditorTests {
}
@Test
public void testCustomBooleanEditorWithAllowEmpty() {
void testCustomBooleanEditorWithAllowEmpty() {
BooleanTestBean tb = new BooleanTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(Boolean.class, new CustomBooleanEditor(true));
@ -279,37 +279,37 @@ public class CustomEditorTests {
bw.setPropertyValue("bool2", "false");
assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
boolean condition3 = !tb.getBool2().booleanValue();
boolean condition3 = !tb.getBool2();
assertThat(condition3).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "on");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "off");
boolean condition2 = !tb.getBool2().booleanValue();
boolean condition2 = !tb.getBool2();
assertThat(condition2).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "yes");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "no");
boolean condition1 = !tb.getBool2().booleanValue();
boolean condition1 = !tb.getBool2();
assertThat(condition1).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "1");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "0");
boolean condition = !tb.getBool2().booleanValue();
boolean condition = !tb.getBool2();
assertThat(condition).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "");
assertThat(bw.getPropertyValue("bool2") == null).as("Correct bool2 value").isTrue();
assertThat(tb.getBool2() == null).as("Correct bool2 value").isTrue();
assertThat(bw.getPropertyValue("bool2")).as("Correct bool2 value").isNull();
assertThat(tb.getBool2()).as("Correct bool2 value").isNull();
}
@Test
public void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() throws Exception {
void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() throws Exception {
String trueString = "pechorin";
String falseString = "nash";
@ -333,7 +333,7 @@ public class CustomEditorTests {
}
@Test
public void testDefaultNumberEditor() {
void testDefaultNumberEditor() {
NumberTestBean tb = new NumberTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
@ -350,34 +350,34 @@ public class CustomEditorTests {
bw.setPropertyValue("double2", "6.1");
bw.setPropertyValue("bigDecimal", "4.5");
assertThat(new Short("1").equals(bw.getPropertyValue("short1"))).as("Correct short1 value").isTrue();
assertThat(Short.valueOf("1").equals(bw.getPropertyValue("short1"))).as("Correct short1 value").isTrue();
assertThat(tb.getShort1() == 1).as("Correct short1 value").isTrue();
assertThat(new Short("2").equals(bw.getPropertyValue("short2"))).as("Correct short2 value").isTrue();
assertThat(new Short("2").equals(tb.getShort2())).as("Correct short2 value").isTrue();
assertThat(new Integer("7").equals(bw.getPropertyValue("int1"))).as("Correct int1 value").isTrue();
assertThat(Short.valueOf("2").equals(bw.getPropertyValue("short2"))).as("Correct short2 value").isTrue();
assertThat(Short.valueOf("2").equals(tb.getShort2())).as("Correct short2 value").isTrue();
assertThat(Integer.valueOf("7").equals(bw.getPropertyValue("int1"))).as("Correct int1 value").isTrue();
assertThat(tb.getInt1() == 7).as("Correct int1 value").isTrue();
assertThat(new Integer("8").equals(bw.getPropertyValue("int2"))).as("Correct int2 value").isTrue();
assertThat(new Integer("8").equals(tb.getInt2())).as("Correct int2 value").isTrue();
assertThat(new Long("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
assertThat(Integer.valueOf("8").equals(bw.getPropertyValue("int2"))).as("Correct int2 value").isTrue();
assertThat(Integer.valueOf("8").equals(tb.getInt2())).as("Correct int2 value").isTrue();
assertThat(Long.valueOf("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
assertThat(tb.getLong1() == 5).as("Correct long1 value").isTrue();
assertThat(new Long("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
assertThat(new Long("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
assertThat(Long.valueOf("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
assertThat(Long.valueOf("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
assertThat(new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))).as("Correct bigInteger value").isTrue();
assertThat(new BigInteger("3").equals(tb.getBigInteger())).as("Correct bigInteger value").isTrue();
assertThat(new Float("7.1").equals(bw.getPropertyValue("float1"))).as("Correct float1 value").isTrue();
assertThat(new Float("7.1").equals(new Float(tb.getFloat1()))).as("Correct float1 value").isTrue();
assertThat(new Float("8.1").equals(bw.getPropertyValue("float2"))).as("Correct float2 value").isTrue();
assertThat(new Float("8.1").equals(tb.getFloat2())).as("Correct float2 value").isTrue();
assertThat(new Double("5.1").equals(bw.getPropertyValue("double1"))).as("Correct double1 value").isTrue();
assertThat(Float.valueOf("7.1").equals(bw.getPropertyValue("float1"))).as("Correct float1 value").isTrue();
assertThat(Float.valueOf("7.1").equals(tb.getFloat1())).as("Correct float1 value").isTrue();
assertThat(Float.valueOf("8.1").equals(bw.getPropertyValue("float2"))).as("Correct float2 value").isTrue();
assertThat(Float.valueOf("8.1").equals(tb.getFloat2())).as("Correct float2 value").isTrue();
assertThat(Double.valueOf("5.1").equals(bw.getPropertyValue("double1"))).as("Correct double1 value").isTrue();
assertThat(tb.getDouble1() == 5.1).as("Correct double1 value").isTrue();
assertThat(new Double("6.1").equals(bw.getPropertyValue("double2"))).as("Correct double2 value").isTrue();
assertThat(new Double("6.1").equals(tb.getDouble2())).as("Correct double2 value").isTrue();
assertThat(Double.valueOf("6.1").equals(bw.getPropertyValue("double2"))).as("Correct double2 value").isTrue();
assertThat(Double.valueOf("6.1").equals(tb.getDouble2())).as("Correct double2 value").isTrue();
assertThat(new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))).as("Correct bigDecimal value").isTrue();
assertThat(new BigDecimal("4.5").equals(tb.getBigDecimal())).as("Correct bigDecimal value").isTrue();
}
@Test
public void testCustomNumberEditorWithoutAllowEmpty() {
void testCustomNumberEditorWithoutAllowEmpty() {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
NumberTestBean tb = new NumberTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
@ -407,34 +407,34 @@ public class CustomEditorTests {
bw.setPropertyValue("double2", "6,1");
bw.setPropertyValue("bigDecimal", "4,5");
assertThat(new Short("1").equals(bw.getPropertyValue("short1"))).as("Correct short1 value").isTrue();
assertThat(bw.getPropertyValue("short1")).as("Correct short1 value").isEqualTo(Short.valueOf("1"));
assertThat(tb.getShort1() == 1).as("Correct short1 value").isTrue();
assertThat(new Short("2").equals(bw.getPropertyValue("short2"))).as("Correct short2 value").isTrue();
assertThat(new Short("2").equals(tb.getShort2())).as("Correct short2 value").isTrue();
assertThat(new Integer("7").equals(bw.getPropertyValue("int1"))).as("Correct int1 value").isTrue();
assertThat(bw.getPropertyValue("short2")).as("Correct short2 value").isEqualTo(Short.valueOf("2"));
assertThat(tb.getShort2()).as("Correct short2 value").isEqualTo(Short.valueOf("2"));
assertThat(bw.getPropertyValue("int1")).as("Correct int1 value").isEqualTo(Integer.valueOf("7"));
assertThat(tb.getInt1() == 7).as("Correct int1 value").isTrue();
assertThat(new Integer("8").equals(bw.getPropertyValue("int2"))).as("Correct int2 value").isTrue();
assertThat(new Integer("8").equals(tb.getInt2())).as("Correct int2 value").isTrue();
assertThat(new Long("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
assertThat(bw.getPropertyValue("int2")).as("Correct int2 value").isEqualTo(Integer.valueOf("8"));
assertThat(tb.getInt2()).as("Correct int2 value").isEqualTo(Integer.valueOf("8"));
assertThat(bw.getPropertyValue("long1")).as("Correct long1 value").isEqualTo(Long.valueOf("5"));
assertThat(tb.getLong1() == 5).as("Correct long1 value").isTrue();
assertThat(new Long("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
assertThat(new Long("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
assertThat(bw.getPropertyValue("long2")).as("Correct long2 value").isEqualTo(Long.valueOf("6"));
assertThat(tb.getLong2()).as("Correct long2 value").isEqualTo(Long.valueOf("6"));
assertThat(new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))).as("Correct bigInteger value").isTrue();
assertThat(new BigInteger("3").equals(tb.getBigInteger())).as("Correct bigInteger value").isTrue();
assertThat(new Float("7.1").equals(bw.getPropertyValue("float1"))).as("Correct float1 value").isTrue();
assertThat(new Float("7.1").equals(new Float(tb.getFloat1()))).as("Correct float1 value").isTrue();
assertThat(new Float("8.1").equals(bw.getPropertyValue("float2"))).as("Correct float2 value").isTrue();
assertThat(new Float("8.1").equals(tb.getFloat2())).as("Correct float2 value").isTrue();
assertThat(new Double("5.1").equals(bw.getPropertyValue("double1"))).as("Correct double1 value").isTrue();
assertThat(bw.getPropertyValue("float1")).as("Correct float1 value").isEqualTo(Float.valueOf("7.1"));
assertThat(Float.valueOf(tb.getFloat1())).as("Correct float1 value").isEqualTo(Float.valueOf("7.1"));
assertThat(bw.getPropertyValue("float2")).as("Correct float2 value").isEqualTo(Float.valueOf("8.1"));
assertThat(tb.getFloat2()).as("Correct float2 value").isEqualTo(Float.valueOf("8.1"));
assertThat(bw.getPropertyValue("double1")).as("Correct double1 value").isEqualTo(Double.valueOf("5.1"));
assertThat(tb.getDouble1() == 5.1).as("Correct double1 value").isTrue();
assertThat(new Double("6.1").equals(bw.getPropertyValue("double2"))).as("Correct double2 value").isTrue();
assertThat(new Double("6.1").equals(tb.getDouble2())).as("Correct double2 value").isTrue();
assertThat(bw.getPropertyValue("double2")).as("Correct double2 value").isEqualTo(Double.valueOf("6.1"));
assertThat(tb.getDouble2()).as("Correct double2 value").isEqualTo(Double.valueOf("6.1"));
assertThat(new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))).as("Correct bigDecimal value").isTrue();
assertThat(new BigDecimal("4.5").equals(tb.getBigDecimal())).as("Correct bigDecimal value").isTrue();
}
@Test
public void testCustomNumberEditorWithAllowEmpty() {
void testCustomNumberEditorWithAllowEmpty() {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
NumberTestBean tb = new NumberTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
@ -443,10 +443,10 @@ public class CustomEditorTests {
bw.setPropertyValue("long1", "5");
bw.setPropertyValue("long2", "6");
assertThat(new Long("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
assertThat(Long.valueOf("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
assertThat(tb.getLong1() == 5).as("Correct long1 value").isTrue();
assertThat(new Long("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
assertThat(new Long("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
assertThat(Long.valueOf("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
assertThat(Long.valueOf("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
bw.setPropertyValue("long2", "");
assertThat(bw.getPropertyValue("long2") == null).as("Correct long2 value").isTrue();
@ -458,7 +458,7 @@ public class CustomEditorTests {
}
@Test
public void testCustomNumberEditorWithFrenchBigDecimal() throws Exception {
void testCustomNumberEditorWithFrenchBigDecimal() throws Exception {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH);
NumberTestBean tb = new NumberTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
@ -475,14 +475,14 @@ public class CustomEditorTests {
}
@Test
public void testParseShortGreaterThanMaxValueWithoutNumberFormat() {
void testParseShortGreaterThanMaxValueWithoutNumberFormat() {
CustomNumberEditor editor = new CustomNumberEditor(Short.class, true);
assertThatExceptionOfType(NumberFormatException.class).as("greater than Short.MAX_VALUE + 1").isThrownBy(() ->
editor.setAsText(String.valueOf(Short.MAX_VALUE + 1)));
}
@Test
public void testByteArrayPropertyEditor() {
void testByteArrayPropertyEditor() {
PrimitiveArrayBean bean = new PrimitiveArrayBean();
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.setPropertyValue("byteArray", "myvalue");
@ -490,7 +490,7 @@ public class CustomEditorTests {
}
@Test
public void testCharArrayPropertyEditor() {
void testCharArrayPropertyEditor() {
PrimitiveArrayBean bean = new PrimitiveArrayBean();
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.setPropertyValue("charArray", "myvalue");
@ -498,7 +498,7 @@ public class CustomEditorTests {
}
@Test
public void testCharacterEditor() {
void testCharacterEditor() {
CharBean cb = new CharBean();
BeanWrapper bw = new BeanWrapperImpl(cb);
@ -520,78 +520,78 @@ public class CustomEditorTests {
}
@Test
public void testCharacterEditorWithAllowEmpty() {
void testCharacterEditorWithAllowEmpty() {
CharBean cb = new CharBean();
BeanWrapper bw = new BeanWrapperImpl(cb);
bw.registerCustomEditor(Character.class, new CharacterEditor(true));
bw.setPropertyValue("myCharacter", new Character('c'));
assertThat(cb.getMyCharacter()).isEqualTo(new Character('c'));
bw.setPropertyValue("myCharacter", 'c');
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('c'));
bw.setPropertyValue("myCharacter", "c");
assertThat(cb.getMyCharacter()).isEqualTo(new Character('c'));
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('c'));
bw.setPropertyValue("myCharacter", "\u0041");
assertThat(cb.getMyCharacter()).isEqualTo(new Character('A'));
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('A'));
bw.setPropertyValue("myCharacter", " ");
assertThat(cb.getMyCharacter()).isEqualTo(new Character(' '));
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf(' '));
bw.setPropertyValue("myCharacter", "");
assertThat(cb.getMyCharacter()).isNull();
}
@Test
public void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter() throws Exception {
void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter() throws Exception {
PropertyEditor charEditor = new CharacterEditor(false);
assertThatIllegalArgumentException().isThrownBy(() ->
charEditor.setAsText("ColdWaterCanyon"));
}
@Test
public void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
PropertyEditor charEditor = new CharacterEditor(false);
assertThat(charEditor.getAsText()).isEqualTo("");
assertThat(charEditor.getAsText()).isEmpty();
charEditor = new CharacterEditor(true);
charEditor.setAsText(null);
assertThat(charEditor.getAsText()).isEqualTo("");
assertThat(charEditor.getAsText()).isEmpty();
charEditor.setAsText("");
assertThat(charEditor.getAsText()).isEqualTo("");
assertThat(charEditor.getAsText()).isEmpty();
charEditor.setAsText(" ");
assertThat(charEditor.getAsText()).isEqualTo(" ");
}
@Test
public void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull() throws Exception {
void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull() throws Exception {
PropertyEditor charEditor = new CharacterEditor(false);
assertThatIllegalArgumentException().isThrownBy(() ->
charEditor.setAsText(null));
}
@Test
public void testClassEditor() {
void testClassEditor() {
PropertyEditor classEditor = new ClassEditor();
classEditor.setAsText(TestBean.class.getName());
assertThat(classEditor.getValue()).isEqualTo(TestBean.class);
assertThat(classEditor.getAsText()).isEqualTo(TestBean.class.getName());
classEditor.setAsText(null);
assertThat(classEditor.getAsText()).isEqualTo("");
assertThat(classEditor.getAsText()).isEmpty();
classEditor.setAsText("");
assertThat(classEditor.getAsText()).isEqualTo("");
assertThat(classEditor.getAsText()).isEmpty();
classEditor.setAsText("\t ");
assertThat(classEditor.getAsText()).isEqualTo("");
assertThat(classEditor.getAsText()).isEmpty();
}
@Test
public void testClassEditorWithNonExistentClass() throws Exception {
void testClassEditorWithNonExistentClass() throws Exception {
PropertyEditor classEditor = new ClassEditor();
assertThatIllegalArgumentException().isThrownBy(() ->
classEditor.setAsText("hairdresser.on.Fire"));
}
@Test
public void testClassEditorWithArray() {
void testClassEditorWithArray() {
PropertyEditor classEditor = new ClassEditor();
classEditor.setAsText("org.springframework.beans.testfixture.beans.TestBean[]");
assertThat(classEditor.getValue()).isEqualTo(TestBean[].class);
@ -602,7 +602,7 @@ public class CustomEditorTests {
* SPR_2165 - ClassEditor is inconsistent with multidimensional arrays
*/
@Test
public void testGetAsTextWithTwoDimensionalArray() throws Exception {
void testGetAsTextWithTwoDimensionalArray() throws Exception {
String[][] chessboard = new String[8][8];
ClassEditor editor = new ClassEditor();
editor.setValue(chessboard.getClass());
@ -613,7 +613,7 @@ public class CustomEditorTests {
* SPR_2165 - ClassEditor is inconsistent with multidimensional arrays
*/
@Test
public void testGetAsTextWithRidiculousMultiDimensionalArray() throws Exception {
void testGetAsTextWithRidiculousMultiDimensionalArray() throws Exception {
String[][][][][] ridiculousChessboard = new String[8][4][0][1][3];
ClassEditor editor = new ClassEditor();
editor.setValue(ridiculousChessboard.getClass());
@ -621,7 +621,7 @@ public class CustomEditorTests {
}
@Test
public void testFileEditor() {
void testFileEditor() {
PropertyEditor fileEditor = new FileEditor();
fileEditor.setAsText("file:myfile.txt");
assertThat(fileEditor.getValue()).isEqualTo(new File("myfile.txt"));
@ -629,7 +629,7 @@ public class CustomEditorTests {
}
@Test
public void testFileEditorWithRelativePath() {
void testFileEditorWithRelativePath() {
PropertyEditor fileEditor = new FileEditor();
try {
fileEditor.setAsText("myfile.txt");
@ -641,7 +641,7 @@ public class CustomEditorTests {
}
@Test
public void testFileEditorWithAbsolutePath() {
void testFileEditorWithAbsolutePath() {
PropertyEditor fileEditor = new FileEditor();
// testing on Windows
if (new File("C:/myfile.txt").isAbsolute()) {
@ -656,18 +656,18 @@ public class CustomEditorTests {
}
@Test
public void testLocaleEditor() {
void testLocaleEditor() {
PropertyEditor localeEditor = new LocaleEditor();
localeEditor.setAsText("en_CA");
assertThat(localeEditor.getValue()).isEqualTo(Locale.CANADA);
assertThat(localeEditor.getAsText()).isEqualTo("en_CA");
localeEditor = new LocaleEditor();
assertThat(localeEditor.getAsText()).isEqualTo("");
assertThat(localeEditor.getAsText()).isEmpty();
}
@Test
public void testPatternEditor() {
void testPatternEditor() {
final String REGEX = "a.*";
PropertyEditor patternEditor = new PatternEditor();
@ -676,15 +676,15 @@ public class CustomEditorTests {
assertThat(patternEditor.getAsText()).isEqualTo(REGEX);
patternEditor = new PatternEditor();
assertThat(patternEditor.getAsText()).isEqualTo("");
assertThat(patternEditor.getAsText()).isEmpty();
patternEditor = new PatternEditor();
patternEditor.setAsText(null);
assertThat(patternEditor.getAsText()).isEqualTo("");
assertThat(patternEditor.getAsText()).isEmpty();
}
@Test
public void testCustomBooleanEditor() {
void testCustomBooleanEditor() {
CustomBooleanEditor editor = new CustomBooleanEditor(false);
editor.setAsText("true");
@ -696,15 +696,15 @@ public class CustomEditorTests {
assertThat(editor.getAsText()).isEqualTo("false");
editor.setValue(null);
assertThat(editor.getValue()).isEqualTo(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEmpty();
assertThatIllegalArgumentException().isThrownBy(() ->
editor.setAsText(null));
}
@Test
public void testCustomBooleanEditorWithEmptyAsNull() {
void testCustomBooleanEditorWithEmptyAsNull() {
CustomBooleanEditor editor = new CustomBooleanEditor(true);
editor.setAsText("true");
@ -716,34 +716,34 @@ public class CustomEditorTests {
assertThat(editor.getAsText()).isEqualTo("false");
editor.setValue(null);
assertThat(editor.getValue()).isEqualTo(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testCustomDateEditor() {
void testCustomDateEditor() {
CustomDateEditor editor = new CustomDateEditor(null, false);
editor.setValue(null);
assertThat(editor.getValue()).isEqualTo(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testCustomDateEditorWithEmptyAsNull() {
void testCustomDateEditorWithEmptyAsNull() {
CustomDateEditor editor = new CustomDateEditor(null, true);
editor.setValue(null);
assertThat(editor.getValue()).isEqualTo(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testCustomDateEditorWithExactDateLength() {
void testCustomDateEditorWithExactDateLength() {
int maxLength = 10;
String validDate = "01/01/2005";
String invalidDate = "01/01/05";
assertThat(validDate.length() == maxLength).isTrue();
assertThat(invalidDate.length() == maxLength).isFalse();
assertThat(validDate).hasSize(maxLength);
assertThat(invalidDate.length()).isNotEqualTo(maxLength);
CustomDateEditor editor = new CustomDateEditor(new SimpleDateFormat("MM/dd/yyyy"), true, maxLength);
editor.setAsText(validDate);
@ -753,39 +753,39 @@ public class CustomEditorTests {
}
@Test
public void testCustomNumberEditor() {
void testCustomNumberEditor() {
CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false);
editor.setAsText("5");
assertThat(editor.getValue()).isEqualTo(5);
assertThat(editor.getAsText()).isEqualTo("5");
editor.setValue(null);
assertThat(editor.getValue()).isEqualTo(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testCustomNumberEditorWithHex() {
void testCustomNumberEditorWithHex() {
CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false);
editor.setAsText("0x" + Integer.toHexString(64));
assertThat(editor.getValue()).isEqualTo(64);
}
@Test
public void testCustomNumberEditorWithEmptyAsNull() {
void testCustomNumberEditorWithEmptyAsNull() {
CustomNumberEditor editor = new CustomNumberEditor(Integer.class, true);
editor.setAsText("5");
assertThat(editor.getValue()).isEqualTo(5);
assertThat(editor.getAsText()).isEqualTo("5");
editor.setAsText("");
assertThat(editor.getValue()).isEqualTo(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEmpty();
editor.setValue(null);
assertThat(editor.getValue()).isEqualTo(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testStringTrimmerEditor() {
void testStringTrimmerEditor() {
StringTrimmerEditor editor = new StringTrimmerEditor(false);
editor.setAsText("test");
assertThat(editor.getValue()).isEqualTo("test");
@ -795,15 +795,15 @@ public class CustomEditorTests {
assertThat(editor.getAsText()).isEqualTo("test");
editor.setAsText("");
assertThat(editor.getValue()).isEqualTo("");
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
editor.setValue(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
editor.setAsText(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testStringTrimmerEditorWithEmptyAsNull() {
void testStringTrimmerEditorWithEmptyAsNull() {
StringTrimmerEditor editor = new StringTrimmerEditor(true);
editor.setAsText("test");
assertThat(editor.getValue()).isEqualTo("test");
@ -812,14 +812,14 @@ public class CustomEditorTests {
assertThat(editor.getValue()).isEqualTo("test");
assertThat(editor.getAsText()).isEqualTo("test");
editor.setAsText(" ");
assertThat(editor.getValue()).isEqualTo(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEmpty();
editor.setValue(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testStringTrimmerEditorWithCharsToDelete() {
void testStringTrimmerEditorWithCharsToDelete() {
StringTrimmerEditor editor = new StringTrimmerEditor("\r\n\f", false);
editor.setAsText("te\ns\ft");
assertThat(editor.getValue()).isEqualTo("test");
@ -829,13 +829,13 @@ public class CustomEditorTests {
assertThat(editor.getAsText()).isEqualTo("test");
editor.setAsText("");
assertThat(editor.getValue()).isEqualTo("");
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
editor.setValue(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testStringTrimmerEditorWithCharsToDeleteAndEmptyAsNull() {
void testStringTrimmerEditorWithCharsToDeleteAndEmptyAsNull() {
StringTrimmerEditor editor = new StringTrimmerEditor("\r\n\f", true);
editor.setAsText("te\ns\ft");
assertThat(editor.getValue()).isEqualTo("test");
@ -844,14 +844,14 @@ public class CustomEditorTests {
assertThat(editor.getValue()).isEqualTo("test");
assertThat(editor.getAsText()).isEqualTo("test");
editor.setAsText(" \n\f ");
assertThat(editor.getValue()).isEqualTo(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEmpty();
editor.setValue(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testIndexedPropertiesWithCustomEditorForType() {
void testIndexedPropertiesWithCustomEditorForType() {
IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
@ -904,7 +904,7 @@ public class CustomEditorTests {
}
@Test
public void testIndexedPropertiesWithCustomEditorForProperty() {
void testIndexedPropertiesWithCustomEditorForProperty() {
IndexedTestBean bean = new IndexedTestBean(false);
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(String.class, "array.name", new PropertyEditorSupport() {
@ -971,7 +971,7 @@ public class CustomEditorTests {
}
@Test
public void testIndexedPropertiesWithIndividualCustomEditorForProperty() {
void testIndexedPropertiesWithIndividualCustomEditorForProperty() {
IndexedTestBean bean = new IndexedTestBean(false);
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(String.class, "array[0].name", new PropertyEditorSupport() {
@ -1056,7 +1056,7 @@ public class CustomEditorTests {
}
@Test
public void testNestedIndexedPropertiesWithCustomEditorForProperty() {
void testNestedIndexedPropertiesWithCustomEditorForProperty() {
IndexedTestBean bean = new IndexedTestBean();
TestBean tb0 = bean.getArray()[0];
TestBean tb1 = bean.getArray()[1];
@ -1140,7 +1140,7 @@ public class CustomEditorTests {
}
@Test
public void testNestedIndexedPropertiesWithIndexedCustomEditorForProperty() {
void testNestedIndexedPropertiesWithIndexedCustomEditorForProperty() {
IndexedTestBean bean = new IndexedTestBean();
TestBean tb0 = bean.getArray()[0];
TestBean tb1 = bean.getArray()[1];
@ -1191,7 +1191,7 @@ public class CustomEditorTests {
}
@Test
public void testIndexedPropertiesWithDirectAccessAndPropertyEditors() {
void testIndexedPropertiesWithDirectAccessAndPropertyEditors() {
IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(TestBean.class, "array", new PropertyEditorSupport() {
@ -1245,7 +1245,7 @@ public class CustomEditorTests {
}
@Test
public void testIndexedPropertiesWithDirectAccessAndSpecificPropertyEditors() {
void testIndexedPropertiesWithDirectAccessAndSpecificPropertyEditors() {
IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(TestBean.class, "array[0]", new PropertyEditorSupport() {
@ -1332,7 +1332,7 @@ public class CustomEditorTests {
}
@Test
public void testIndexedPropertiesWithListPropertyEditor() {
void testIndexedPropertiesWithListPropertyEditor() {
IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(List.class, "list", new PropertyEditorSupport() {
@ -1350,7 +1350,7 @@ public class CustomEditorTests {
}
@Test
public void testConversionToOldCollections() throws PropertyVetoException {
void testConversionToOldCollections() throws PropertyVetoException {
OldCollectionsBean tb = new OldCollectionsBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(Vector.class, new CustomCollectionEditor(Vector.class));
@ -1367,7 +1367,7 @@ public class CustomEditorTests {
}
@Test
public void testUninitializedArrayPropertyWithCustomEditor() {
void testUninitializedArrayPropertyWithCustomEditor() {
IndexedTestBean bean = new IndexedTestBean(false);
BeanWrapper bw = new BeanWrapperImpl(bean);
PropertyEditor pe = new CustomNumberEditor(Integer.class, true);
@ -1383,7 +1383,7 @@ public class CustomEditorTests {
}
@Test
public void testArrayToArrayConversion() throws PropertyVetoException {
void testArrayToArrayConversion() throws PropertyVetoException {
IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
@ -1399,7 +1399,7 @@ public class CustomEditorTests {
}
@Test
public void testArrayToStringConversion() throws PropertyVetoException {
void testArrayToStringConversion() throws PropertyVetoException {
TestBean tb = new TestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
@ -1408,16 +1408,16 @@ public class CustomEditorTests {
setValue("-" + text + "-");
}
});
bw.setPropertyValue("name", new String[] {"a", "b"});
bw.setPropertyValue("name", new String[]{"a", "b"});
assertThat(tb.getName()).isEqualTo("-a,b-");
}
@Test
public void testClassArrayEditorSunnyDay() throws Exception {
void testClassArrayEditorSunnyDay() throws Exception {
ClassArrayEditor classArrayEditor = new ClassArrayEditor();
classArrayEditor.setAsText("java.lang.String,java.util.HashMap");
Class<?>[] classes = (Class<?>[]) classArrayEditor.getValue();
assertThat(classes.length).isEqualTo(2);
assertThat(classes).hasSize(2);
assertThat(classes[0]).isEqualTo(String.class);
assertThat(classes[1]).isEqualTo(HashMap.class);
assertThat(classArrayEditor.getAsText()).isEqualTo("java.lang.String,java.util.HashMap");
@ -1426,11 +1426,11 @@ public class CustomEditorTests {
}
@Test
public void testClassArrayEditorSunnyDayWithArrayTypes() throws Exception {
void testClassArrayEditorSunnyDayWithArrayTypes() throws Exception {
ClassArrayEditor classArrayEditor = new ClassArrayEditor();
classArrayEditor.setAsText("java.lang.String[],java.util.Map[],int[],float[][][]");
Class<?>[] classes = (Class<?>[]) classArrayEditor.getValue();
assertThat(classes.length).isEqualTo(4);
assertThat(classes).hasSize(4);
assertThat(classes[0]).isEqualTo(String[].class);
assertThat(classes[1]).isEqualTo(Map[].class);
assertThat(classes[2]).isEqualTo(int[].class);
@ -1441,31 +1441,31 @@ public class CustomEditorTests {
}
@Test
public void testClassArrayEditorSetAsTextWithNull() throws Exception {
void testClassArrayEditorSetAsTextWithNull() throws Exception {
ClassArrayEditor editor = new ClassArrayEditor();
editor.setAsText(null);
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testClassArrayEditorSetAsTextWithEmptyString() throws Exception {
void testClassArrayEditorSetAsTextWithEmptyString() throws Exception {
ClassArrayEditor editor = new ClassArrayEditor();
editor.setAsText("");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testClassArrayEditorSetAsTextWithWhitespaceString() throws Exception {
void testClassArrayEditorSetAsTextWithWhitespaceString() throws Exception {
ClassArrayEditor editor = new ClassArrayEditor();
editor.setAsText("\n");
assertThat(editor.getValue()).isNull();
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
}
@Test
public void testCharsetEditor() throws Exception {
void testCharsetEditor() throws Exception {
CharsetEditor editor = new CharsetEditor();
String name = "UTF-8";
editor.setAsText(name);

View File

@ -162,13 +162,13 @@ class ProceedTestingAspect implements Ordered {
public Object doubleOrQuits(ProceedingJoinPoint pjp) throws Throwable {
int value = ((Integer) pjp.getArgs()[0]).intValue();
pjp.getArgs()[0] = new Integer(value * 2);
pjp.getArgs()[0] = Integer.valueOf(value * 2);
return pjp.proceed();
}
public Object addOne(ProceedingJoinPoint pjp, Float value) throws Throwable {
float fv = value.floatValue();
return pjp.proceed(new Object[] {new Float(fv + 1.0F)});
return pjp.proceed(new Object[] {Float.valueOf(fv + 1.0F)});
}
public void captureStringArgument(JoinPoint tjp, String arg) {

View File

@ -79,7 +79,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Stephane Nicoll
* @author Juergen Hoeller
*/
public class AnnotationDrivenEventListenerTests {
class AnnotationDrivenEventListenerTests {
private ConfigurableApplicationContext context;
@ -97,7 +97,7 @@ public class AnnotationDrivenEventListenerTests {
@Test
public void simpleEventJavaConfig() {
void simpleEventJavaConfig() {
load(TestEventListener.class);
TestEvent event = new TestEvent(this, "test");
TestEventListener listener = this.context.getBean(TestEventListener.class);
@ -120,7 +120,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void simpleEventXmlConfig() {
void simpleEventXmlConfig() {
this.context = new ClassPathXmlApplicationContext(
"org/springframework/context/event/simple-event-configuration.xml");
@ -141,7 +141,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void metaAnnotationIsDiscovered() {
void metaAnnotationIsDiscovered() {
load(MetaAnnotationListenerTestBean.class);
MetaAnnotationListenerTestBean bean = this.context.getBean(MetaAnnotationListenerTestBean.class);
this.eventCollector.assertNoEventReceived(bean);
@ -159,7 +159,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void contextEventsAreReceived() {
void contextEventsAreReceived() {
load(ContextEventListener.class);
ContextEventListener listener = this.context.getBean(ContextEventListener.class);
@ -175,7 +175,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void methodSignatureNoEvent() {
void methodSignatureNoEvent() {
@SuppressWarnings("resource")
AnnotationConfigApplicationContext failingContext =
new AnnotationConfigApplicationContext();
@ -189,7 +189,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void simpleReply() {
void simpleReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, "dummy");
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@ -204,7 +204,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void nullReplyIgnored() {
void nullReplyIgnored() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, null); // No response
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@ -219,7 +219,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void arrayReply() {
void arrayReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, new String[]{"first", "second"});
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@ -234,7 +234,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void collectionReply() {
void collectionReply() {
load(TestEventListener.class, ReplyEventListener.class);
Set<Object> replies = new LinkedHashSet<>();
replies.add("first");
@ -253,7 +253,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void collectionReplyNullValue() {
void collectionReplyNullValue() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, Arrays.asList(null, "test"));
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@ -268,7 +268,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenableFutureReply() {
void listenableFutureReply() {
load(TestEventListener.class, ReplyEventListener.class);
SettableListenableFuture<String> future = new SettableListenableFuture<>();
future.set("dummy");
@ -285,7 +285,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void completableFutureReply() {
void completableFutureReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, CompletableFuture.completedFuture("dummy"));
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@ -300,7 +300,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void monoReply() {
void monoReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, Mono.just("dummy"));
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@ -315,7 +315,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void fluxReply() {
void fluxReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, Flux.just("dummy1", "dummy2"));
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@ -330,7 +330,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void eventListenerWorksWithSimpleInterfaceProxy() {
void eventListenerWorksWithSimpleInterfaceProxy() {
load(ScopedProxyTestBean.class);
SimpleService proxy = this.context.getBean(SimpleService.class);
@ -347,7 +347,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void eventListenerWorksWithAnnotatedInterfaceProxy() {
void eventListenerWorksWithAnnotatedInterfaceProxy() {
load(AnnotatedProxyTestBean.class);
AnnotatedSimpleService proxy = this.context.getBean(AnnotatedSimpleService.class);
@ -364,7 +364,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void eventListenerWorksWithCglibProxy() {
void eventListenerWorksWithCglibProxy() {
load(CglibProxyTestBean.class);
CglibProxyTestBean proxy = this.context.getBean(CglibProxyTestBean.class);
@ -381,14 +381,14 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void privateMethodOnCglibProxyFails() {
void privateMethodOnCglibProxyFails() {
assertThatExceptionOfType(BeanInitializationException.class).isThrownBy(() ->
load(CglibProxyWithPrivateMethod.class))
.withCauseInstanceOf(IllegalStateException.class);
}
@Test
public void eventListenerWorksWithCustomScope() {
void eventListenerWorksWithCustomScope() {
load(CustomScopeTestBean.class);
CustomScope customScope = new CustomScope();
this.context.getBeanFactory().registerScope("custom", customScope);
@ -417,7 +417,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void asyncProcessingApplied() throws InterruptedException {
void asyncProcessingApplied() throws InterruptedException {
loadAsync(AsyncEventListener.class);
String threadName = Thread.currentThread().getName();
@ -432,7 +432,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void asyncProcessingAppliedWithInterfaceProxy() throws InterruptedException {
void asyncProcessingAppliedWithInterfaceProxy() throws InterruptedException {
doLoad(AsyncConfigurationWithInterfaces.class, SimpleProxyTestBean.class);
String threadName = Thread.currentThread().getName();
@ -447,7 +447,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void asyncProcessingAppliedWithScopedProxy() throws InterruptedException {
void asyncProcessingAppliedWithScopedProxy() throws InterruptedException {
doLoad(AsyncConfigurationWithInterfaces.class, ScopedProxyTestBean.class);
String threadName = Thread.currentThread().getName();
@ -462,7 +462,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void exceptionPropagated() {
void exceptionPropagated() {
load(ExceptionEventListener.class);
TestEvent event = new TestEvent(this, "fail");
ExceptionEventListener listener = this.context.getBean(ExceptionEventListener.class);
@ -475,7 +475,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void exceptionNotPropagatedWithAsync() throws InterruptedException {
void exceptionNotPropagatedWithAsync() throws InterruptedException {
loadAsync(ExceptionEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, "fail");
ExceptionEventListener listener = this.context.getBean(ExceptionEventListener.class);
@ -489,7 +489,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenerWithSimplePayload() {
void listenerWithSimplePayload() {
load(TestEventListener.class);
TestEventListener listener = this.context.getBean(TestEventListener.class);
@ -500,7 +500,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenerWithNonMatchingPayload() {
void listenerWithNonMatchingPayload() {
load(TestEventListener.class);
TestEventListener listener = this.context.getBean(TestEventListener.class);
@ -511,7 +511,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void replyWithPayload() {
void replyWithPayload() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, "String");
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@ -527,7 +527,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenerWithGenericApplicationEvent() {
void listenerWithGenericApplicationEvent() {
load(GenericEventListener.class);
GenericEventListener listener = this.context.getBean(GenericEventListener.class);
@ -538,7 +538,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenerWithResolvableTypeEvent() {
void listenerWithResolvableTypeEvent() {
load(ResolvableTypeEventListener.class);
ResolvableTypeEventListener listener = this.context.getBean(ResolvableTypeEventListener.class);
@ -550,7 +550,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenerWithResolvableTypeEventWrongGeneric() {
void listenerWithResolvableTypeEventWrongGeneric() {
load(ResolvableTypeEventListener.class);
ResolvableTypeEventListener listener = this.context.getBean(ResolvableTypeEventListener.class);
@ -562,12 +562,12 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void conditionMatch() {
void conditionMatch() {
validateConditionMatch(ConditionalEventListener.class);
}
@Test
public void conditionMatchWithProxy() {
void conditionMatchWithProxy() {
validateConditionMatch(ConditionalEventListener.class, MethodValidationPostProcessor.class);
}
@ -600,7 +600,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void conditionDoesNotMatch() {
void conditionDoesNotMatch() {
long maxLong = Long.MAX_VALUE;
load(ConditionalEventListener.class);
TestEvent event = new TestEvent(this, "KO");
@ -625,7 +625,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void orderedListeners() {
void orderedListeners() {
load(OrderedTestListener.class);
OrderedTestListener listener = this.context.getBean(OrderedTestListener.class);
@ -635,7 +635,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test @Disabled // SPR-15122
public void listenersReceiveEarlyEvents() {
void listenersReceiveEarlyEvents() {
load(EventOnPostConstruct.class, OrderedTestListener.class);
OrderedTestListener listener = this.context.getBean(OrderedTestListener.class);
@ -643,7 +643,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void missingListenerBeanIgnored() {
void missingListenerBeanIgnored() {
load(MissingEventListener.class);
context.getBean(UseMissingEventListener.class);
context.getBean(ApplicationEventMulticaster.class).multicastEvent(new TestEvent(this));
@ -697,7 +697,7 @@ public class AnnotationDrivenEventListenerTests {
static class TestConditionEvaluator {
public boolean valid(Double ratio) {
return new Double(42).equals(ratio);
return Double.valueOf(42).equals(ratio);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -341,10 +341,10 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsRegistered("Bean instance not registered", objectName);
Object result = server.invoke(objectName, "add", new Object[] {new Integer(2), new Integer(3)}, new String[] {
Object result = server.invoke(objectName, "add", new Object[] {2, 3}, new String[] {
int.class.getName(), int.class.getName()});
assertThat(new Integer(5)).as("Incorrect result return from add").isEqualTo(result);
assertThat(Integer.valueOf(5)).as("Incorrect result return from add").isEqualTo(result);
assertThat(server.getAttribute(objectName, "Name")).as("Incorrect attribute value").isEqualTo(name);
server.setAttribute(objectName, new Attribute("Name", otherName));
@ -352,7 +352,7 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
}
@Test
void testBonaFideMBeanIsNotExportedWhenAutodetectIsTotallyTurnedOff() throws Exception {
void testBonaFideMBeanIsNotExportedWhenAutodetectIsTotallyTurnedOff() {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("^&_invalidObjectName_(*", builder.getBeanDefinition());

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -60,7 +60,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
IJmxTestBean bean = getBean();
assertThat(bean).isNotNull();
MBeanInfo inf = getMBeanInfo();
assertThat(inf.getOperations().length).as("Incorrect number of operations registered").isEqualTo(getExpectedOperationCount());
assertThat(inf.getOperations()).as("Incorrect number of operations registered").hasSize(getExpectedOperationCount());
}
@Test
@ -68,7 +68,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
IJmxTestBean bean = getBean();
assertThat(bean).isNotNull();
MBeanInfo inf = getMBeanInfo();
assertThat(inf.getAttributes().length).as("Incorrect number of attributes registered").isEqualTo(getExpectedAttributeCount());
assertThat(inf.getAttributes()).as("Incorrect number of attributes registered").hasSize(getExpectedAttributeCount());
}
@Test
@ -81,7 +81,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
public void testGetMBeanAttributeInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
MBeanAttributeInfo[] inf = info.getAttributes();
assertThat(inf.length).as("Invalid number of Attributes returned").isEqualTo(getExpectedAttributeCount());
assertThat(inf).as("Invalid number of Attributes returned").hasSize(getExpectedAttributeCount());
for (int x = 0; x < inf.length; x++) {
assertThat(inf[x]).as("MBeanAttributeInfo should not be null").isNotNull();
@ -93,7 +93,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
public void testGetMBeanOperationInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
MBeanOperationInfo[] inf = info.getOperations();
assertThat(inf.length).as("Invalid number of Operations returned").isEqualTo(getExpectedOperationCount());
assertThat(inf).as("Invalid number of Operations returned").hasSize(getExpectedOperationCount());
for (int x = 0; x < inf.length; x++) {
assertThat(inf[x]).as("MBeanOperationInfo should not be null").isNotNull();
@ -128,8 +128,8 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
public void testOperationInvocation() throws Exception{
ObjectName objectName = ObjectNameManager.getInstance(getObjectName());
Object result = getServer().invoke(objectName, "add",
new Object[] {new Integer(20), new Integer(30)}, new String[] {"int", "int"});
assertThat(result).as("Incorrect result").isEqualTo(new Integer(50));
new Object[] {20, 30}, new String[] {"int", "int"});
assertThat(result).as("Incorrect result").isEqualTo(50);
}
@Test
@ -150,12 +150,12 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
ModelMBeanOperationInfo get = info.getOperation("getName");
assertThat(get).as("get operation should not be null").isNotNull();
assertThat(new Integer(4)).as("get operation should have visibility of four").isEqualTo(get.getDescriptor().getFieldValue("visibility"));
assertThat(Integer.valueOf(4)).as("get operation should have visibility of four").isEqualTo(get.getDescriptor().getFieldValue("visibility"));
assertThat(get.getDescriptor().getFieldValue("role")).as("get operation should have role \"getter\"").isEqualTo("getter");
ModelMBeanOperationInfo set = info.getOperation("setName");
assertThat(set).as("set operation should not be null").isNotNull();
assertThat(new Integer(4)).as("set operation should have visibility of four").isEqualTo(set.getDescriptor().getFieldValue("visibility"));
assertThat(Integer.valueOf(4)).as("set operation should have visibility of four").isEqualTo(set.getDescriptor().getFieldValue("visibility"));
assertThat(set.getDescriptor().getFieldValue("role")).as("set operation should have role \"setter\"").isEqualTo("setter");
}
@ -163,12 +163,12 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
public void testNotificationMetadata() throws Exception {
ModelMBeanInfo info = (ModelMBeanInfo) getMBeanInfo();
MBeanNotificationInfo[] notifications = info.getNotifications();
assertThat(notifications.length).as("Incorrect number of notifications").isEqualTo(1);
assertThat(notifications).as("Incorrect number of notifications").hasSize(1);
assertThat(notifications[0].getName()).as("Incorrect notification name").isEqualTo("My Notification");
String[] notifTypes = notifications[0].getNotifTypes();
assertThat(notifTypes.length).as("Incorrect number of notification types").isEqualTo(2);
assertThat(notifTypes).as("Incorrect number of notification types").hasSize(2);
assertThat(notifTypes[0]).as("Notification type.foo not found").isEqualTo("type.foo");
assertThat(notifTypes[1]).as("Notification type.bar not found").isEqualTo("type.bar");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -41,7 +41,7 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
* @author Chris Beams
*/
@EnabledForTestGroups(LONG_RUNNING)
public class ScriptFactoryPostProcessorTests {
class ScriptFactoryPostProcessorTests {
private static final String MESSAGE_TEXT = "Bingo";
@ -79,18 +79,18 @@ public class ScriptFactoryPostProcessorTests {
@Test
public void testDoesNothingWhenPostProcessingNonScriptFactoryTypeBeforeInstantiation() throws Exception {
void testDoesNothingWhenPostProcessingNonScriptFactoryTypeBeforeInstantiation() {
assertThat(new ScriptFactoryPostProcessor().postProcessBeforeInstantiation(getClass(), "a.bean")).isNull();
}
@Test
public void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() throws Exception {
void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() {
assertThatIllegalStateException().isThrownBy(() ->
new ScriptFactoryPostProcessor().setBeanFactory(mock(BeanFactory.class)));
}
@Test
public void testChangeScriptWithRefreshableBeanFunctionality() throws Exception {
void testChangeScriptWithRefreshableBeanFunctionality() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
@ -111,7 +111,7 @@ public class ScriptFactoryPostProcessorTests {
}
@Test
public void testChangeScriptWithNoRefreshableBeanFunctionality() throws Exception {
void testChangeScriptWithNoRefreshableBeanFunctionality() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(false);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
@ -131,7 +131,7 @@ public class ScriptFactoryPostProcessorTests {
}
@Test
public void testRefreshedScriptReferencePropagatesToCollaborators() throws Exception {
void testRefreshedScriptReferencePropagatesToCollaborators() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class);
@ -159,7 +159,7 @@ public class ScriptFactoryPostProcessorTests {
}
@Test
public void testReferencesAcrossAContainerHierarchy() throws Exception {
void testReferencesAcrossAContainerHierarchy() throws Exception {
GenericApplicationContext businessContext = new GenericApplicationContext();
businessContext.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition());
businessContext.refresh();
@ -175,13 +175,13 @@ public class ScriptFactoryPostProcessorTests {
}
@Test
public void testScriptHavingAReferenceToAnotherBean() throws Exception {
void testScriptHavingAReferenceToAnotherBean() throws Exception {
// just tests that the (singleton) script-backed bean is able to be instantiated with references to its collaborators
new ClassPathXmlApplicationContext("org/springframework/scripting/support/groovyReferences.xml");
}
@Test
public void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception {
void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class);
@ -202,13 +202,12 @@ public class ScriptFactoryPostProcessorTests {
// needs The Sundays compiler; must NOT throw any exception here...
source.setScript("I keep hoping you are the same as me, and I'll send you letters and come to your house for tea");
Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(() ->
refreshedMessenger.getMessage())
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(refreshedMessenger::getMessage)
.matches(ex -> ex.contains(ScriptCompilationException.class));
}
@Test
public void testPrototypeScriptedBean() throws Exception {
void testPrototypeScriptedBean() throws Exception {
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition());
@ -236,7 +235,7 @@ public class ScriptFactoryPostProcessorTests {
private static BeanDefinition createScriptFactoryPostProcessor(boolean isRefreshable) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ScriptFactoryPostProcessor.class);
if (isRefreshable) {
builder.addPropertyValue("defaultRefreshCheckDelay", new Long(1));
builder.addPropertyValue("defaultRefreshCheckDelay", 1L);
}
return builder.getBeanDefinition();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -36,17 +36,17 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Stephane Nicoll
* @since 07.03.2006
*/
public class DataBinderFieldAccessTests {
class DataBinderFieldAccessTests {
@Test
public void bindingNoErrors() throws Exception {
void bindingNoErrors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
binder.initDirectFieldAccess();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
pvs.addPropertyValue(new PropertyValue("age", new Integer(32)));
pvs.addPropertyValue(new PropertyValue("age", 32));
pvs.addPropertyValue(new PropertyValue("nonExisting", "someValue"));
binder.bind(pvs);
@ -62,21 +62,21 @@ public class DataBinderFieldAccessTests {
}
@Test
public void bindingNoErrorsNotIgnoreUnknown() throws Exception {
void bindingNoErrorsNotIgnoreUnknown() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
binder.initDirectFieldAccess();
binder.setIgnoreUnknownFields(false);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
pvs.addPropertyValue(new PropertyValue("age", new Integer(32)));
pvs.addPropertyValue(new PropertyValue("age", 32));
pvs.addPropertyValue(new PropertyValue("nonExisting", "someValue"));
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() ->
binder.bind(pvs));
}
@Test
public void bindingWithErrors() throws Exception {
void bindingWithErrors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
binder.initDirectFieldAccess();
@ -105,7 +105,7 @@ public class DataBinderFieldAccessTests {
}
@Test
public void nestedBindingWithDefaultConversionNoErrors() throws Exception {
void nestedBindingWithDefaultConversionNoErrors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
@ -122,7 +122,7 @@ public class DataBinderFieldAccessTests {
}
@Test
public void nestedBindingWithDisabledAutoGrow() throws Exception {
void nestedBindingWithDisabledAutoGrow() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
binder.setAutoGrowNestedPaths(false);
@ -135,7 +135,7 @@ public class DataBinderFieldAccessTests {
}
@Test
public void bindingWithErrorsAndCustomEditors() throws Exception {
void bindingWithErrorsAndCustomEditors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
binder.initDirectFieldAccess();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -77,10 +77,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Rob Harrop
* @author Kazuki Shimizu
*/
public class DataBinderTests {
class DataBinderTests {
@Test
public void testBindingNoErrors() throws BindException {
void testBindingNoErrors() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
@ -115,7 +115,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithDefaultConversionNoErrors() throws BindException {
void testBindingWithDefaultConversionNoErrors() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
@ -131,7 +131,7 @@ public class DataBinderTests {
}
@Test
public void testNestedBindingWithDefaultConversionNoErrors() throws BindException {
void testNestedBindingWithDefaultConversionNoErrors() throws BindException {
TestBean rod = new TestBean(new TestBean());
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
@ -147,7 +147,7 @@ public class DataBinderTests {
}
@Test
public void testBindingNoErrorsNotIgnoreUnknown() {
void testBindingNoErrorsNotIgnoreUnknown() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
binder.setIgnoreUnknownFields(false);
@ -160,7 +160,7 @@ public class DataBinderTests {
}
@Test
public void testBindingNoErrorsWithInvalidField() {
void testBindingNoErrorsWithInvalidField() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
@ -171,7 +171,7 @@ public class DataBinderTests {
}
@Test
public void testBindingNoErrorsWithIgnoreInvalid() {
void testBindingNoErrorsWithIgnoreInvalid() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
binder.setIgnoreInvalidFields(true);
@ -183,7 +183,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithErrors() {
void testBindingWithErrors() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
@ -245,7 +245,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithSystemFieldError() {
void testBindingWithSystemFieldError() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
@ -257,7 +257,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithErrorsAndCustomEditors() {
void testBindingWithErrorsAndCustomEditors() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
binder.registerCustomEditor(String.class, "touchy", new PropertyEditorSupport() {
@ -325,7 +325,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithCustomEditorOnObjectField() {
void testBindingWithCustomEditorOnObjectField() {
BeanWithObjectProperty tb = new BeanWithObjectProperty();
DataBinder binder = new DataBinder(tb);
binder.registerCustomEditor(Integer.class, "object", new CustomNumberEditor(Integer.class, true));
@ -336,7 +336,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithFormatter() {
void testBindingWithFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@ -349,18 +349,18 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(1.2));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(1.2f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1,2");
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class);
assertThat(editor).isNotNull();
editor.setValue(new Float(1.4));
editor.setValue(1.4f);
assertThat(editor.getAsText()).isEqualTo("1,4");
editor = binder.getBindingResult().findEditor("myFloat", null);
assertThat(editor).isNotNull();
editor.setAsText("1,6");
assertThat(editor.getValue()).isEqualTo(new Float(1.6));
assertThat(editor.getValue()).isEqualTo(1.6f);
}
finally {
LocaleContextHolder.resetLocaleContext();
@ -368,7 +368,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithFormatter() {
void testBindingErrorWithFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@ -381,7 +381,7 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(0.0));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(0.0f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1x2");
assertThat(binder.getBindingResult().hasFieldErrors("myFloat")).isTrue();
}
@ -391,7 +391,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithParseExceptionFromFormatter() {
void testBindingErrorWithParseExceptionFromFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@ -419,7 +419,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithRuntimeExceptionFromFormatter() {
void testBindingErrorWithRuntimeExceptionFromFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@ -447,7 +447,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithFormatterAgainstList() {
void testBindingWithFormatterAgainstList() {
BeanWithIntegerList tb = new BeanWithIntegerList();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@ -469,7 +469,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithFormatterAgainstList() {
void testBindingErrorWithFormatterAgainstList() {
BeanWithIntegerList tb = new BeanWithIntegerList();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@ -492,7 +492,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithFormatterAgainstFields() {
void testBindingWithFormatterAgainstFields() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@ -506,18 +506,18 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(1.2));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(1.2f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1,2");
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class);
assertThat(editor).isNotNull();
editor.setValue(new Float(1.4));
editor.setValue(1.4f);
assertThat(editor.getAsText()).isEqualTo("1,4");
editor = binder.getBindingResult().findEditor("myFloat", null);
assertThat(editor).isNotNull();
editor.setAsText("1,6");
assertThat(editor.getValue()).isEqualTo(new Float(1.6));
assertThat(editor.getValue()).isEqualTo(1.6f);
}
finally {
LocaleContextHolder.resetLocaleContext();
@ -525,7 +525,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithFormatterAgainstFields() {
void testBindingErrorWithFormatterAgainstFields() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
binder.initDirectFieldAccess();
@ -539,7 +539,7 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(0.0));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(0.0f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1x2");
assertThat(binder.getBindingResult().hasFieldErrors("myFloat")).isTrue();
}
@ -549,7 +549,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithCustomFormatter() {
void testBindingWithCustomFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
binder.addCustomFormatter(new NumberStyleFormatter(), Float.class);
@ -559,12 +559,12 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(1.2));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(1.2f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1,2");
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class);
assertThat(editor).isNotNull();
editor.setValue(new Float(1.4));
editor.setValue(1.4f);
assertThat(editor.getAsText()).isEqualTo("1,4");
editor = binder.getBindingResult().findEditor("myFloat", null);
@ -578,7 +578,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithCustomFormatter() {
void testBindingErrorWithCustomFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
binder.addCustomFormatter(new NumberStyleFormatter());
@ -588,7 +588,7 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(0.0));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(0.0f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1x2");
assertThat(binder.getBindingResult().hasFieldErrors("myFloat")).isTrue();
assertThat(binder.getBindingResult().getFieldError("myFloat").getCode()).isEqualTo("typeMismatch");
@ -599,7 +599,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithParseExceptionFromCustomFormatter() {
void testBindingErrorWithParseExceptionFromCustomFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
@ -624,7 +624,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithRuntimeExceptionFromCustomFormatter() {
void testBindingErrorWithRuntimeExceptionFromCustomFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
@ -649,7 +649,7 @@ public class DataBinderTests {
}
@Test
public void testConversionWithInappropriateStringEditor() {
void testConversionWithInappropriateStringEditor() {
DataBinder dataBinder = new DataBinder(null);
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
dataBinder.setConversionService(conversionService);
@ -662,7 +662,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithAllowedFields() throws BindException {
void testBindingWithAllowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
binder.setAllowedFields("name", "myparam");
@ -677,7 +677,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithDisallowedFields() throws BindException {
void testBindingWithDisallowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
binder.setDisallowedFields("age");
@ -695,7 +695,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithAllowedAndDisallowedFields() throws BindException {
void testBindingWithAllowedAndDisallowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
binder.setAllowedFields("name", "myparam");
@ -709,12 +709,12 @@ public class DataBinderTests {
assertThat(rod.getName().equals("Rod")).as("changed name correctly").isTrue();
assertThat(rod.getAge() == 0).as("did not change age").isTrue();
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
assertThat(disallowedFields.length).isEqualTo(1);
assertThat(disallowedFields).hasSize(1);
assertThat(disallowedFields[0]).isEqualTo("age");
}
@Test
public void testBindingWithOverlappingAllowedAndDisallowedFields() throws BindException {
void testBindingWithOverlappingAllowedAndDisallowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
binder.setAllowedFields("name", "age");
@ -728,12 +728,12 @@ public class DataBinderTests {
assertThat(rod.getName().equals("Rod")).as("changed name correctly").isTrue();
assertThat(rod.getAge() == 0).as("did not change age").isTrue();
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
assertThat(disallowedFields.length).isEqualTo(1);
assertThat(disallowedFields).hasSize(1);
assertThat(disallowedFields[0]).isEqualTo("age");
}
@Test
public void testBindingWithAllowedFieldsUsingAsterisks() throws BindException {
void testBindingWithAllowedFieldsUsingAsterisks() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
binder.setAllowedFields("nam*", "*ouchy");
@ -750,7 +750,7 @@ public class DataBinderTests {
assertThat("Rod".equals(rod.getTouchy())).as("changed touchy correctly").isTrue();
assertThat(rod.getAge() == 0).as("did not change age").isTrue();
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
assertThat(disallowedFields.length).isEqualTo(1);
assertThat(disallowedFields).hasSize(1);
assertThat(disallowedFields[0]).isEqualTo("age");
Map<?,?> m = binder.getBindingResult().getModel();
@ -760,7 +760,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithAllowedAndDisallowedMapFields() throws BindException {
void testBindingWithAllowedAndDisallowedMapFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
binder.setAllowedFields("someMap[key1]", "someMap[key2]");
@ -779,7 +779,7 @@ public class DataBinderTests {
assertThat(rod.getSomeMap().get("key3")).isNull();
assertThat(rod.getSomeMap().get("key4")).isNull();
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
assertThat(disallowedFields.length).isEqualTo(2);
assertThat(disallowedFields).hasSize(2);
assertThat(ObjectUtils.containsElement(disallowedFields, "someMap[key3]")).isTrue();
assertThat(ObjectUtils.containsElement(disallowedFields, "someMap[key4]")).isTrue();
}
@ -788,7 +788,7 @@ public class DataBinderTests {
* Tests for required field, both null, non-existing and empty strings.
*/
@Test
public void testBindingWithRequiredFields() {
void testBindingWithRequiredFields() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
@ -819,7 +819,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithRequiredMapFields() {
void testBindingWithRequiredMapFields() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
@ -839,7 +839,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithNestedObjectCreation() {
void testBindingWithNestedObjectCreation() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "person");
@ -860,7 +860,7 @@ public class DataBinderTests {
}
@Test
public void testCustomEditorWithOldValueAccess() {
void testCustomEditorWithOldValueAccess() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
@ -885,7 +885,7 @@ public class DataBinderTests {
}
@Test
public void testCustomEditorForSingleProperty() {
void testCustomEditorForSingleProperty() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
DataBinder binder = new DataBinder(tb, "tb");
@ -925,7 +925,7 @@ public class DataBinderTests {
}
@Test
public void testCustomEditorForPrimitiveProperty() {
void testCustomEditorForPrimitiveProperty() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
@ -949,7 +949,7 @@ public class DataBinderTests {
}
@Test
public void testCustomEditorForAllStringProperties() {
void testCustomEditorForAllStringProperties() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
@ -981,7 +981,7 @@ public class DataBinderTests {
}
@Test
public void testCustomFormatterForSingleProperty() {
void testCustomFormatterForSingleProperty() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
DataBinder binder = new DataBinder(tb, "tb");
@ -1021,7 +1021,7 @@ public class DataBinderTests {
}
@Test
public void testCustomFormatterForPrimitiveProperty() {
void testCustomFormatterForPrimitiveProperty() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
@ -1045,7 +1045,7 @@ public class DataBinderTests {
}
@Test
public void testCustomFormatterForAllStringProperties() {
void testCustomFormatterForAllStringProperties() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
@ -1077,7 +1077,7 @@ public class DataBinderTests {
}
@Test
public void testJavaBeanPropertyConventions() {
void testJavaBeanPropertyConventions() {
Book book = new Book();
DataBinder binder = new DataBinder(book);
@ -1101,7 +1101,7 @@ public class DataBinderTests {
}
@Test
public void testOptionalProperty() {
void testOptionalProperty() {
OptionalHolder bean = new OptionalHolder();
DataBinder binder = new DataBinder(bean);
binder.setConversionService(new DefaultConversionService());
@ -1111,7 +1111,7 @@ public class DataBinderTests {
pvs.add("name", null);
binder.bind(pvs);
assertThat(bean.getId()).isEqualTo("1");
assertThat(bean.getName().isPresent()).isFalse();
assertThat(bean.getName()).isEmpty();
pvs = new MutablePropertyValues();
pvs.add("id", "2");
@ -1122,7 +1122,7 @@ public class DataBinderTests {
}
@Test
public void testValidatorNoErrors() throws Exception {
void testValidatorNoErrors() throws Exception {
TestBean tb = new TestBean();
tb.setAge(33);
tb.setName("Rod");
@ -1183,7 +1183,7 @@ public class DataBinderTests {
}
@Test
public void testValidatorWithErrors() {
void testValidatorWithErrors() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
@ -1252,7 +1252,7 @@ public class DataBinderTests {
}
@Test
public void testValidatorWithErrorsAndCodesPrefix() {
void testValidatorWithErrorsAndCodesPrefix() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
@ -1324,7 +1324,7 @@ public class DataBinderTests {
}
@Test
public void testValidatorWithNestedObjectNull() {
void testValidatorWithNestedObjectNull() {
TestBean tb = new TestBean();
Errors errors = new BeanPropertyBindingResult(tb, "tb");
Validator testValidator = new TestBeanValidator();
@ -1343,7 +1343,7 @@ public class DataBinderTests {
}
@Test
public void testNestedValidatorWithoutNestedPath() {
void testNestedValidatorWithoutNestedPath() {
TestBean tb = new TestBean();
tb.setName("XXX");
Errors errors = new BeanPropertyBindingResult(tb, "tb");
@ -1357,13 +1357,13 @@ public class DataBinderTests {
}
@Test
public void testBindingStringArrayToIntegerSet() {
void testBindingStringArrayToIntegerSet() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(Set.class, new CustomCollectionEditor(TreeSet.class) {
@Override
protected Object convertElement(Object element) {
return new Integer(element.toString());
return Integer.valueOf(element.toString());
}
});
MutablePropertyValues pvs = new MutablePropertyValues();
@ -1386,7 +1386,7 @@ public class DataBinderTests {
}
@Test
public void testBindingNullToEmptyCollection() {
void testBindingNullToEmptyCollection() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(Set.class, new CustomCollectionEditor(TreeSet.class, true));
@ -1400,7 +1400,7 @@ public class DataBinderTests {
}
@Test
public void testBindingToIndexedField() {
void testBindingToIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(String.class, "array.name", new PropertyEditorSupport() {
@ -1439,7 +1439,7 @@ public class DataBinderTests {
}
@Test
public void testBindingToNestedIndexedField() {
void testBindingToNestedIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
@ -1470,7 +1470,7 @@ public class DataBinderTests {
}
@Test
public void testEditorForNestedIndexedField() {
void testEditorForNestedIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
@ -1496,7 +1496,7 @@ public class DataBinderTests {
}
@Test
public void testSpecificEditorForNestedIndexedField() {
void testSpecificEditorForNestedIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
@ -1522,7 +1522,7 @@ public class DataBinderTests {
}
@Test
public void testInnerSpecificEditorForNestedIndexedField() {
void testInnerSpecificEditorForNestedIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
@ -1548,7 +1548,7 @@ public class DataBinderTests {
}
@Test
public void testDirectBindingToIndexedField() {
void testDirectBindingToIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(TestBean.class, "array", new PropertyEditorSupport() {
@ -1601,7 +1601,7 @@ public class DataBinderTests {
}
@Test
public void testDirectBindingToEmptyIndexedFieldWithRegisteredSpecificEditor() {
void testDirectBindingToEmptyIndexedFieldWithRegisteredSpecificEditor() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(TestBean.class, "map[key0]", new PropertyEditorSupport() {
@ -1632,7 +1632,7 @@ public class DataBinderTests {
}
@Test
public void testDirectBindingToEmptyIndexedFieldWithRegisteredGenericEditor() {
void testDirectBindingToEmptyIndexedFieldWithRegisteredGenericEditor() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
@ -1663,7 +1663,7 @@ public class DataBinderTests {
}
@Test
public void testCustomEditorWithSubclass() {
void testCustomEditorWithSubclass() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
@ -1697,7 +1697,7 @@ public class DataBinderTests {
}
@Test
public void testBindToStringArrayWithArrayEditor() {
void testBindToStringArrayWithArrayEditor() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(String[].class, "stringArray", new PropertyEditorSupport() {
@ -1717,7 +1717,7 @@ public class DataBinderTests {
}
@Test
public void testBindToStringArrayWithComponentEditor() {
void testBindToStringArrayWithComponentEditor() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(String.class, "stringArray", new PropertyEditorSupport() {
@ -1737,7 +1737,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrors() {
void testBindingErrors() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
@ -1764,7 +1764,7 @@ public class DataBinderTests {
}
@Test
public void testAddAllErrors() {
void testAddAllErrors() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
@ -1784,7 +1784,7 @@ public class DataBinderTests {
@Test
@SuppressWarnings("unchecked")
public void testBindingWithResortedList() {
void testBindingWithResortedList() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
MutablePropertyValues pvs = new MutablePropertyValues();
@ -1802,7 +1802,7 @@ public class DataBinderTests {
}
@Test
public void testRejectWithoutDefaultMessage() {
void testRejectWithoutDefaultMessage() {
TestBean tb = new TestBean();
tb.setName("myName");
tb.setAge(99);
@ -1820,7 +1820,7 @@ public class DataBinderTests {
}
@Test
public void testBindExceptionSerializable() throws Exception {
void testBindExceptionSerializable() throws Exception {
SerializablePerson tb = new SerializablePerson();
tb.setName("myName");
tb.setAge(99);
@ -1849,7 +1849,7 @@ public class DataBinderTests {
}
@Test
public void testTrackDisallowedFields() {
void testTrackDisallowedFields() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.setAllowedFields("name", "age");
@ -1864,12 +1864,12 @@ public class DataBinderTests {
assertThat(testBean.getName()).isEqualTo(name);
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
assertThat(disallowedFields.length).isEqualTo(1);
assertThat(disallowedFields).hasSize(1);
assertThat(disallowedFields[0]).isEqualTo("beanName");
}
@Test
public void testAutoGrowWithinDefaultLimit() {
void testAutoGrowWithinDefaultLimit() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
@ -1877,11 +1877,11 @@ public class DataBinderTests {
mpvs.add("friends[4]", "");
binder.bind(mpvs);
assertThat(testBean.getFriends().size()).isEqualTo(5);
assertThat(testBean.getFriends()).hasSize(5);
}
@Test
public void testAutoGrowBeyondDefaultLimit() {
void testAutoGrowBeyondDefaultLimit() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
@ -1894,7 +1894,7 @@ public class DataBinderTests {
}
@Test
public void testAutoGrowWithinCustomLimit() {
void testAutoGrowWithinCustomLimit() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.setAutoGrowCollectionLimit(10);
@ -1903,11 +1903,11 @@ public class DataBinderTests {
mpvs.add("friends[4]", "");
binder.bind(mpvs);
assertThat(testBean.getFriends().size()).isEqualTo(5);
assertThat(testBean.getFriends()).hasSize(5);
}
@Test
public void testAutoGrowBeyondCustomLimit() {
void testAutoGrowBeyondCustomLimit() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.setAutoGrowCollectionLimit(10);
@ -1921,7 +1921,7 @@ public class DataBinderTests {
}
@Test
public void testNestedGrowingList() {
void testNestedGrowingList() {
Form form = new Form();
DataBinder binder = new DataBinder(form, "form");
MutablePropertyValues mpv = new MutablePropertyValues();
@ -1937,7 +1937,7 @@ public class DataBinderTests {
}
@Test
public void testFieldErrorAccessVariations() {
void testFieldErrorAccessVariations() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
assertThat(binder.getBindingResult().getGlobalError()).isNull();
@ -1958,7 +1958,7 @@ public class DataBinderTests {
}
@Test // SPR-14888
public void testSetAutoGrowCollectionLimit() {
void testSetAutoGrowCollectionLimit() {
BeanWithIntegerList tb = new BeanWithIntegerList();
DataBinder binder = new DataBinder(tb);
binder.setAutoGrowCollectionLimit(257);
@ -1968,11 +1968,11 @@ public class DataBinderTests {
binder.bind(pvs);
assertThat(tb.getIntegerList().size()).isEqualTo(257);
assertThat(tb.getIntegerList().get(256)).isEqualTo(Integer.valueOf(1));
assertThat(binder.getBindingResult().getFieldValue("integerList[256]")).isEqualTo(Integer.valueOf(1));
assertThat(binder.getBindingResult().getFieldValue("integerList[256]")).isEqualTo(1);
}
@Test // SPR-14888
public void testSetAutoGrowCollectionLimitAfterInitialization() {
void testSetAutoGrowCollectionLimitAfterInitialization() {
DataBinder binder = new DataBinder(new BeanWithIntegerList());
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
assertThatIllegalStateException().isThrownBy(() ->
@ -1981,7 +1981,7 @@ public class DataBinderTests {
}
@Test // SPR-15009
public void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAccess() {
void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAccess() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
DefaultMessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver();
@ -1998,7 +1998,7 @@ public class DataBinderTests {
}
@Test // SPR-15009
public void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForDirectFieldAccess() {
void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForDirectFieldAccess() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
DefaultMessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver();
@ -2013,7 +2013,7 @@ public class DataBinderTests {
}
@Test // SPR-15009
public void testSetCustomMessageCodesResolverAfterInitializeBindingResult() {
void testSetCustomMessageCodesResolverAfterInitializeBindingResult() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.initBeanPropertyAccess();
@ -2028,7 +2028,7 @@ public class DataBinderTests {
}
@Test // SPR-15009
public void testSetMessageCodesResolverIsNullAfterInitializeBindingResult() {
void testSetMessageCodesResolverIsNullAfterInitializeBindingResult() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.initBeanPropertyAccess();
@ -2042,7 +2042,7 @@ public class DataBinderTests {
}
@Test // SPR-15009
public void testCallSetMessageCodesResolverTwice() {
void testCallSetMessageCodesResolverTwice() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
@ -2053,7 +2053,7 @@ public class DataBinderTests {
}
@Test // gh-24347
public void overrideBindingResultType() {
void overrideBindingResultType() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.initDirectFieldAccess();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -18,7 +18,6 @@ package org.springframework.util;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@ -109,7 +108,7 @@ class ObjectUtilsTests {
Set<String> set = new HashSet<>();
set.add("foo");
assertThat(isEmpty(set)).isFalse();
assertThat(isEmpty(Arrays.asList("foo"))).isFalse();
assertThat(isEmpty(Collections.singletonList("foo"))).isFalse();
}
@Test
@ -159,7 +158,7 @@ class ObjectUtilsTests {
void toObjectArrayWithEmptyPrimitiveArray() {
Object[] objects = ObjectUtils.toObjectArray(new byte[] {});
assertThat(objects).isNotNull();
assertThat(objects.length).isEqualTo(0);
assertThat(objects).hasSize(0);
}
@Test
@ -179,7 +178,7 @@ class ObjectUtilsTests {
String[] array = new String[] {"foo", "bar"};
String newElement = "baz";
Object[] newArray = ObjectUtils.addObjectToArray(array, newElement);
assertThat(newArray.length).isEqualTo(3);
assertThat(newArray).hasSize(3);
assertThat(newArray[2]).isEqualTo(newElement);
}
@ -188,7 +187,7 @@ class ObjectUtilsTests {
String[] array = new String[0];
String newElement = "foo";
String[] newArray = ObjectUtils.addObjectToArray(array, newElement);
assertThat(newArray.length).isEqualTo(1);
assertThat(newArray).hasSize(1);
assertThat(newArray[0]).isEqualTo(newElement);
}
@ -198,7 +197,7 @@ class ObjectUtilsTests {
String[] array = new String[] {existingElement};
String newElement = "bar";
String[] newArray = ObjectUtils.addObjectToArray(array, newElement);
assertThat(newArray.length).isEqualTo(2);
assertThat(newArray).hasSize(2);
assertThat(newArray[0]).isEqualTo(existingElement);
assertThat(newArray[1]).isEqualTo(newElement);
}
@ -208,8 +207,8 @@ class ObjectUtilsTests {
String[] array = new String[] {null};
String newElement = "bar";
String[] newArray = ObjectUtils.addObjectToArray(array, newElement);
assertThat(newArray.length).isEqualTo(2);
assertThat(newArray[0]).isEqualTo(null);
assertThat(newArray).hasSize(2);
assertThat(newArray[0]).isNull();
assertThat(newArray[1]).isEqualTo(newElement);
}
@ -217,15 +216,15 @@ class ObjectUtilsTests {
void addObjectToNullArray() throws Exception {
String newElement = "foo";
String[] newArray = ObjectUtils.addObjectToArray(null, newElement);
assertThat(newArray.length).isEqualTo(1);
assertThat(newArray).hasSize(1);
assertThat(newArray[0]).isEqualTo(newElement);
}
@Test
void addNullObjectToNullArray() throws Exception {
Object[] newArray = ObjectUtils.addObjectToArray(null, null);
assertThat(newArray.length).isEqualTo(1);
assertThat(newArray[0]).isEqualTo(null);
assertThat(newArray).hasSize(1);
assertThat(newArray[0]).isNull();
}
@Test
@ -260,7 +259,7 @@ class ObjectUtilsTests {
@Deprecated
void hashCodeWithFloat() {
float flt = 34.8f;
int expected = (new Float(flt)).hashCode();
int expected = (Float.valueOf(flt)).hashCode();
assertThat(ObjectUtils.hashCode(flt)).isEqualTo(expected);
}
@ -268,7 +267,7 @@ class ObjectUtilsTests {
@Deprecated
void hashCodeWithLong() {
long lng = 883L;
int expected = (new Long(lng)).hashCode();
int expected = (Long.valueOf(lng)).hashCode();
assertThat(ObjectUtils.hashCode(lng)).isEqualTo(expected);
}
@ -282,7 +281,7 @@ class ObjectUtilsTests {
@Test
void identityToStringWithNullObject() {
assertThat(ObjectUtils.identityToString(null)).isEqualTo("");
assertThat(ObjectUtils.identityToString(null)).isEmpty();
}
@Test

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -41,11 +41,11 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("rawtypes")
public class IndexingTests {
class IndexingTests {
@Test
@SuppressWarnings("unchecked")
public void indexIntoGenericPropertyContainingMap() {
void indexIntoGenericPropertyContainingMap() {
Map<String, String> property = new HashMap<>();
property.put("foo", "bar");
this.property = property;
@ -63,7 +63,7 @@ public class IndexingTests {
@Test
@SuppressWarnings("unchecked")
public void indexIntoGenericPropertyContainingMapObject() {
void indexIntoGenericPropertyContainingMapObject() {
Map<String, Map<String, String>> property = new HashMap<>();
Map<String, String> map = new HashMap<>();
map.put("foo", "bar");
@ -112,7 +112,7 @@ public class IndexingTests {
}
@Test
public void setGenericPropertyContainingMap() {
void setGenericPropertyContainingMap() {
Map<String, String> property = new HashMap<>();
property.put("foo", "bar");
this.property = property;
@ -127,7 +127,7 @@ public class IndexingTests {
}
@Test
public void setPropertyContainingMap() {
void setPropertyContainingMap() {
Map<Integer, Integer> property = new HashMap<>();
property.put(9, 3);
this.parameterizedMap = property;
@ -144,7 +144,7 @@ public class IndexingTests {
public Map<Integer, Integer> parameterizedMap;
@Test
public void setPropertyContainingMapAutoGrow() {
void setPropertyContainingMapAutoGrow() {
SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, false));
Expression expression = parser.parseExpression("parameterizedMap");
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("java.util.Map<java.lang.Integer, java.lang.Integer>");
@ -156,7 +156,7 @@ public class IndexingTests {
}
@Test
public void indexIntoGenericPropertyContainingList() {
void indexIntoGenericPropertyContainingList() {
List<String> property = new ArrayList<>();
property.add("bar");
this.property = property;
@ -169,7 +169,7 @@ public class IndexingTests {
}
@Test
public void setGenericPropertyContainingList() {
void setGenericPropertyContainingList() {
List<Integer> property = new ArrayList<>();
property.add(3);
this.property = property;
@ -184,7 +184,7 @@ public class IndexingTests {
}
@Test
public void setGenericPropertyContainingListAutogrow() {
void setGenericPropertyContainingListAutogrow() {
List<Integer> property = new ArrayList<>();
this.property = property;
SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
@ -203,7 +203,7 @@ public class IndexingTests {
public List<BigDecimal> decimals;
@Test
public void autoGrowListOfElementsWithoutDefaultConstructor() {
void autoGrowListOfElementsWithoutDefaultConstructor() {
this.decimals = new ArrayList<>();
SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
parser.parseExpression("decimals[0]").setValue(this, "123.4");
@ -211,7 +211,7 @@ public class IndexingTests {
}
@Test
public void indexIntoPropertyContainingListContainingNullElement() {
void indexIntoPropertyContainingListContainingNullElement() {
this.decimals = new ArrayList<>();
this.decimals.add(null);
this.decimals.add(BigDecimal.ONE);
@ -221,7 +221,7 @@ public class IndexingTests {
}
@Test
public void indexIntoPropertyContainingList() {
void indexIntoPropertyContainingList() {
List<Integer> property = new ArrayList<>();
property.add(3);
this.parameterizedList = property;
@ -236,7 +236,7 @@ public class IndexingTests {
public List<Integer> parameterizedList;
@Test
public void indexIntoPropertyContainingListOfList() {
void indexIntoPropertyContainingListOfList() {
List<List<Integer>> property = new ArrayList<>();
property.add(Arrays.asList(3));
this.parameterizedListOfList = property;
@ -251,7 +251,7 @@ public class IndexingTests {
public List<List<Integer>> parameterizedListOfList;
@Test
public void setPropertyContainingList() {
void setPropertyContainingList() {
List<Integer> property = new ArrayList<>();
property.add(3);
this.parameterizedList = property;
@ -266,7 +266,7 @@ public class IndexingTests {
}
@Test
public void indexIntoGenericPropertyContainingNullList() {
void indexIntoGenericPropertyContainingNullList() {
SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
SpelExpressionParser parser = new SpelExpressionParser(configuration);
Expression expression = parser.parseExpression("property");
@ -282,7 +282,7 @@ public class IndexingTests {
}
@Test
public void indexIntoGenericPropertyContainingGrowingList() {
void indexIntoGenericPropertyContainingGrowingList() {
List<String> property = new ArrayList<>();
this.property = property;
SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
@ -300,7 +300,7 @@ public class IndexingTests {
}
@Test
public void indexIntoGenericPropertyContainingGrowingList2() {
void indexIntoGenericPropertyContainingGrowingList2() {
List<String> property2 = new ArrayList<>();
this.property2 = property2;
SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
@ -320,7 +320,7 @@ public class IndexingTests {
public List property2;
@Test
public void indexIntoGenericPropertyContainingArray() {
void indexIntoGenericPropertyContainingArray() {
String[] property = new String[] { "bar" };
this.property = property;
SpelExpressionParser parser = new SpelExpressionParser();
@ -332,7 +332,7 @@ public class IndexingTests {
}
@Test
public void emptyList() {
void emptyList() {
listOfScalarNotGeneric = new ArrayList();
SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("listOfScalarNotGeneric");
@ -342,7 +342,7 @@ public class IndexingTests {
@SuppressWarnings("unchecked")
@Test
public void resolveCollectionElementType() {
void resolveCollectionElementType() {
listNotGeneric = new ArrayList(2);
listNotGeneric.add(5);
listNotGeneric.add(6);
@ -353,7 +353,7 @@ public class IndexingTests {
}
@Test
public void resolveCollectionElementTypeNull() {
void resolveCollectionElementTypeNull() {
SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("listNotGeneric");
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.List<?>");
@ -370,7 +370,7 @@ public class IndexingTests {
@SuppressWarnings("unchecked")
@Test
public void resolveMapKeyValueTypes() {
void resolveMapKeyValueTypes() {
mapNotGeneric = new HashMap();
mapNotGeneric.put("baseAmount", 3.11);
mapNotGeneric.put("bonusAmount", 7.17);
@ -384,12 +384,12 @@ public class IndexingTests {
@SuppressWarnings("unchecked")
@Test
public void testListOfScalar() {
void testListOfScalar() {
listOfScalarNotGeneric = new ArrayList(1);
listOfScalarNotGeneric.add("5");
SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("listOfScalarNotGeneric[0]");
assertThat(expression.getValue(this, Integer.class)).isEqualTo(new Integer(5));
assertThat(expression.getValue(this, Integer.class)).isEqualTo(Integer.valueOf(5));
}
public List listOfScalarNotGeneric;
@ -397,7 +397,7 @@ public class IndexingTests {
@SuppressWarnings("unchecked")
@Test
public void testListsOfMap() {
void testListsOfMap() {
listOfMapsNotGeneric = new ArrayList();
Map map = new HashMap();
map.put("fruit", "apple");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller
* @author Giovanni Dall'Oglio Risso
*/
public class OperatorTests extends AbstractExpressionTests {
class OperatorTests extends AbstractExpressionTests {
@Test
public void testEqual() {
void testEqual() {
evaluate("3 == 5", false, Boolean.class);
evaluate("5 == 3", false, Boolean.class);
evaluate("6 == 6", true, Boolean.class);
@ -85,7 +85,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testNotEqual() {
void testNotEqual() {
evaluate("3 != 5", true, Boolean.class);
evaluate("5 != 3", true, Boolean.class);
evaluate("6 != 6", false, Boolean.class);
@ -134,7 +134,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testLessThan() {
void testLessThan() {
evaluate("5 < 5", false, Boolean.class);
evaluate("3 < 5", true, Boolean.class);
evaluate("5 < 3", false, Boolean.class);
@ -176,7 +176,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testLessThanOrEqual() {
void testLessThanOrEqual() {
evaluate("3 <= 5", true, Boolean.class);
evaluate("5 <= 3", false, Boolean.class);
evaluate("6 <= 6", true, Boolean.class);
@ -225,7 +225,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testGreaterThan() {
void testGreaterThan() {
evaluate("3 > 5", false, Boolean.class);
evaluate("5 > 3", true, Boolean.class);
evaluate("3L > 5L", false, Boolean.class);
@ -266,7 +266,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testGreaterThanOrEqual() {
void testGreaterThanOrEqual() {
evaluate("3 >= 5", false, Boolean.class);
evaluate("5 >= 3", true, Boolean.class);
evaluate("6 >= 6", true, Boolean.class);
@ -315,27 +315,27 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testIntegerLiteral() {
void testIntegerLiteral() {
evaluate("3", 3, Integer.class);
}
@Test
public void testRealLiteral() {
void testRealLiteral() {
evaluate("3.5", 3.5d, Double.class);
}
@Test
public void testMultiplyStringInt() {
void testMultiplyStringInt() {
evaluate("'a' * 5", "aaaaa", String.class);
}
@Test
public void testMultiplyDoubleDoubleGivesDouble() {
void testMultiplyDoubleDoubleGivesDouble() {
evaluate("3.0d * 5.0d", 15.0d, Double.class);
}
@Test
public void testMixedOperandsBigDecimal() {
void testMixedOperandsBigDecimal() {
evaluate("3 * new java.math.BigDecimal('5')", new BigDecimal("15"), BigDecimal.class);
evaluate("3L * new java.math.BigDecimal('5')", new BigDecimal("15"), BigDecimal.class);
evaluate("3.0d * new java.math.BigDecimal('5')", new BigDecimal("15.0"), BigDecimal.class);
@ -361,19 +361,19 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testMathOperatorAdd02() {
void testMathOperatorAdd02() {
evaluate("'hello' + ' ' + 'world'", "hello world", String.class);
}
@Test
public void testMathOperatorsInChains() {
void testMathOperatorsInChains() {
evaluate("1+2+3",6,Integer.class);
evaluate("2*3*4",24,Integer.class);
evaluate("12-1-2",9,Integer.class);
}
@Test
public void testIntegerArithmetic() {
void testIntegerArithmetic() {
evaluate("2 + 4", "6", Integer.class);
evaluate("5 - 4", "1", Integer.class);
evaluate("3 * 5", 15, Integer.class);
@ -388,7 +388,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testPlus() throws Exception {
void testPlus() {
evaluate("7 + 2", "9", Integer.class);
evaluate("3.0f + 5.0f", 8.0f, Float.class);
evaluate("3.0d + 5.0d", 8.0d, Double.class);
@ -419,7 +419,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testMinus() throws Exception {
void testMinus() {
evaluate("'c' - 2", "a", String.class);
evaluate("3.0f - 5.0f", -2.0f, Float.class);
evaluateAndCheckError("'ab' - 2", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
@ -437,7 +437,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testModulus() {
void testModulus() {
evaluate("3%2",1,Integer.class);
evaluate("3L%2L",1L,Long.class);
evaluate("3.0f%2.0f",1f,Float.class);
@ -448,7 +448,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testDivide() {
void testDivide() {
evaluate("3.0f / 5.0f", 0.6f, Float.class);
evaluate("4L/2L",2L,Long.class);
evaluate("3.0f div 5.0f", 0.6f, Float.class);
@ -461,17 +461,17 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testMathOperatorDivide_ConvertToDouble() {
evaluateAndAskForReturnType("8/4", new Double(2.0), Double.class);
void testMathOperatorDivide_ConvertToDouble() {
evaluateAndAskForReturnType("8/4", 2.0, Double.class);
}
@Test
public void testMathOperatorDivide04_ConvertToFloat() {
evaluateAndAskForReturnType("8/4", new Float(2.0), Float.class);
void testMathOperatorDivide04_ConvertToFloat() {
evaluateAndAskForReturnType("8/4", 2.0F, Float.class);
}
@Test
public void testDoubles() {
void testDoubles() {
evaluate("3.0d == 5.0d", false, Boolean.class);
evaluate("3.0d == 3.0d", true, Boolean.class);
evaluate("3.0d != 5.0d", true, Boolean.class);
@ -484,7 +484,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testBigDecimals() {
void testBigDecimals() {
evaluate("3 + new java.math.BigDecimal('5')", new BigDecimal("8"), BigDecimal.class);
evaluate("3 - new java.math.BigDecimal('5')", new BigDecimal("-2"), BigDecimal.class);
evaluate("3 * new java.math.BigDecimal('5')", new BigDecimal("15"), BigDecimal.class);
@ -495,7 +495,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testOperatorNames() throws Exception {
void testOperatorNames() {
Operator node = getOperatorNode((SpelExpression)parser.parseExpression("1==3"));
assertThat(node.getOperatorName()).isEqualTo("==");
@ -534,13 +534,13 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testOperatorOverloading() {
void testOperatorOverloading() {
evaluateAndCheckError("'a' * '2'", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
evaluateAndCheckError("'a' ^ '2'", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
}
@Test
public void testPower() {
void testPower() {
evaluate("3^2",9,Integer.class);
evaluate("3.0d^2.0d",9.0d,Double.class);
evaluate("3L^2L",9L,Long.class);
@ -549,7 +549,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testMixedOperands_FloatsAndDoubles() {
void testMixedOperands_FloatsAndDoubles() {
evaluate("3.0d + 5.0f", 8.0d, Double.class);
evaluate("3.0D - 5.0f", -2.0d, Double.class);
evaluate("3.0f * 5.0d", 15.0d, Double.class);
@ -558,7 +558,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testMixedOperands_DoublesAndInts() {
void testMixedOperands_DoublesAndInts() {
evaluate("3.0d + 5", 8.0d, Double.class);
evaluate("3.0D - 5", -2.0d, Double.class);
evaluate("3.0f * 5", 15.0f, Float.class);
@ -569,7 +569,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testStrings() {
void testStrings() {
evaluate("'abc' == 'abc'", true, Boolean.class);
evaluate("'abc' == 'def'", false, Boolean.class);
evaluate("'abc' != 'abc'", false, Boolean.class);
@ -577,7 +577,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testLongs() {
void testLongs() {
evaluate("3L == 4L", false, Boolean.class);
evaluate("3L == 3L", true, Boolean.class);
evaluate("3L != 4L", true, Boolean.class);
@ -588,7 +588,7 @@ public class OperatorTests extends AbstractExpressionTests {
}
@Test
public void testBigIntegers() {
void testBigIntegers() {
evaluate("3 + new java.math.BigInteger('5')", new BigInteger("8"), BigInteger.class);
evaluate("3 - new java.math.BigInteger('5')", new BigInteger("-2"), BigInteger.class);
evaluate("3 * new java.math.BigInteger('5')", new BigInteger("15"), BigInteger.class);

View File

@ -128,7 +128,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@Test
public void typeReference() throws Exception {
void typeReference() {
expression = parse("T(String)");
assertThat(expression.getValue()).isEqualTo(String.class);
assertCanCompile(expression);
@ -196,7 +196,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@SuppressWarnings("unchecked")
@Test
public void operatorInstanceOf() throws Exception {
void operatorInstanceOf() {
expression = parse("'xyz' instanceof T(String)");
assertThat(expression.getValue()).isEqualTo(true);
assertCanCompile(expression);
@ -245,7 +245,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void operatorInstanceOf_SPR14250() throws Exception {
void operatorInstanceOf_SPR14250() throws Exception {
// primitive left operand - should get boxed, return true
expression = parse("3 instanceof T(Integer)");
assertThat(expression.getValue()).isEqualTo(true);
@ -292,7 +292,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void stringLiteral() throws Exception {
void stringLiteral() throws Exception {
expression = parser.parseExpression("'abcde'");
assertThat(expression.getValue(new TestClass1(), String.class)).isEqualTo("abcde");
assertCanCompile(expression);
@ -307,18 +307,18 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void nullLiteral() throws Exception {
void nullLiteral() throws Exception {
expression = parser.parseExpression("null");
Object resultI = expression.getValue(new TestClass1(), Object.class);
assertCanCompile(expression);
Object resultC = expression.getValue(new TestClass1(), Object.class);
assertThat(resultI).isEqualTo(null);
assertThat(resultC).isEqualTo(null);
assertThat(resultC).isEqualTo(null);
assertThat(resultI).isNull();
assertThat(resultC).isNull();
assertThat(resultC).isNull();
}
@Test
public void realLiteral() throws Exception {
void realLiteral() throws Exception {
expression = parser.parseExpression("3.4d");
double resultI = expression.getValue(new TestClass1(), Double.TYPE);
assertCanCompile(expression);
@ -332,7 +332,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@SuppressWarnings("rawtypes")
@Test
public void inlineList() throws Exception {
void inlineList() throws Exception {
expression = parser.parseExpression("'abcde'.substring({1,3,4}[0])");
Object o = expression.getValue();
assertThat(o).isEqualTo("bcde");
@ -371,7 +371,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@SuppressWarnings("rawtypes")
@Test
public void nestedInlineLists() throws Exception {
void nestedInlineLists() throws Exception {
Object o = null;
expression = parser.parseExpression("{{1,2,3},{4,5,6},{7,8,9}}");
@ -446,7 +446,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void intLiteral() throws Exception {
void intLiteral() throws Exception {
expression = parser.parseExpression("42");
int resultI = expression.getValue(new TestClass1(), Integer.TYPE);
assertCanCompile(expression);
@ -477,7 +477,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void longLiteral() throws Exception {
void longLiteral() throws Exception {
expression = parser.parseExpression("99L");
long resultI = expression.getValue(new TestClass1(), Long.TYPE);
assertCanCompile(expression);
@ -487,24 +487,24 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void booleanLiteral() throws Exception {
void booleanLiteral() throws Exception {
expression = parser.parseExpression("true");
boolean resultI = expression.getValue(1, Boolean.TYPE);
assertThat(resultI).isEqualTo(true);
assertThat(resultI).isTrue();
assertThat(SpelCompiler.compile(expression)).isTrue();
boolean resultC = expression.getValue(1, Boolean.TYPE);
assertThat(resultC).isEqualTo(true);
assertThat(resultC).isTrue();
expression = parser.parseExpression("false");
resultI = expression.getValue(1, Boolean.TYPE);
assertThat(resultI).isEqualTo(false);
assertThat(resultI).isFalse();
assertThat(SpelCompiler.compile(expression)).isTrue();
resultC = expression.getValue(1, Boolean.TYPE);
assertThat(resultC).isEqualTo(false);
assertThat(resultC).isFalse();
}
@Test
public void floatLiteral() throws Exception {
void floatLiteral() throws Exception {
expression = parser.parseExpression("3.4f");
float resultI = expression.getValue(new TestClass1(), Float.TYPE);
assertCanCompile(expression);
@ -517,42 +517,42 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void opOr() throws Exception {
void opOr() throws Exception {
Expression expression = parser.parseExpression("false or false");
boolean resultI = expression.getValue(1, Boolean.TYPE);
SpelCompiler.compile(expression);
boolean resultC = expression.getValue(1, Boolean.TYPE);
assertThat(resultI).isEqualTo(false);
assertThat(resultC).isEqualTo(false);
assertThat(resultI).isFalse();
assertThat(resultC).isFalse();
expression = parser.parseExpression("false or true");
resultI = expression.getValue(1, Boolean.TYPE);
assertCanCompile(expression);
resultC = expression.getValue(1, Boolean.TYPE);
assertThat(resultI).isEqualTo(true);
assertThat(resultC).isEqualTo(true);
assertThat(resultI).isTrue();
assertThat(resultC).isTrue();
expression = parser.parseExpression("true or false");
resultI = expression.getValue(1, Boolean.TYPE);
assertCanCompile(expression);
resultC = expression.getValue(1, Boolean.TYPE);
assertThat(resultI).isEqualTo(true);
assertThat(resultC).isEqualTo(true);
assertThat(resultI).isTrue();
assertThat(resultC).isTrue();
expression = parser.parseExpression("true or true");
resultI = expression.getValue(1, Boolean.TYPE);
assertCanCompile(expression);
resultC = expression.getValue(1, Boolean.TYPE);
assertThat(resultI).isEqualTo(true);
assertThat(resultC).isEqualTo(true);
assertThat(resultI).isTrue();
assertThat(resultC).isTrue();
TestClass4 tc = new TestClass4();
expression = parser.parseExpression("getfalse() or gettrue()");
resultI = expression.getValue(tc, Boolean.TYPE);
assertCanCompile(expression);
resultC = expression.getValue(tc, Boolean.TYPE);
assertThat(resultI).isEqualTo(true);
assertThat(resultC).isEqualTo(true);
assertThat(resultI).isTrue();
assertThat(resultC).isTrue();
// Can't compile this as we aren't going down the getfalse() branch in our evaluation
expression = parser.parseExpression("gettrue() or getfalse()");
@ -584,29 +584,29 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
boolean resultI = expression.getValue(1, Boolean.TYPE);
SpelCompiler.compile(expression);
boolean resultC = expression.getValue(1, Boolean.TYPE);
assertThat(resultI).isEqualTo(false);
assertThat(resultC).isEqualTo(false);
assertThat(resultI).isFalse();
assertThat(resultC).isFalse();
expression = parser.parseExpression("false and true");
resultI = expression.getValue(1, Boolean.TYPE);
SpelCompiler.compile(expression);
resultC = expression.getValue(1, Boolean.TYPE);
assertThat(resultI).isEqualTo(false);
assertThat(resultC).isEqualTo(false);
assertThat(resultI).isFalse();
assertThat(resultC).isFalse();
expression = parser.parseExpression("true and false");
resultI = expression.getValue(1, Boolean.TYPE);
SpelCompiler.compile(expression);
resultC = expression.getValue(1, Boolean.TYPE);
assertThat(resultI).isEqualTo(false);
assertThat(resultC).isEqualTo(false);
assertThat(resultI).isFalse();
assertThat(resultC).isFalse();
expression = parser.parseExpression("true and true");
resultI = expression.getValue(1, Boolean.TYPE);
SpelCompiler.compile(expression);
resultC = expression.getValue(1, Boolean.TYPE);
assertThat(resultI).isEqualTo(true);
assertThat(resultC).isEqualTo(true);
assertThat(resultI).isTrue();
assertThat(resultC).isTrue();
TestClass4 tc = new TestClass4();
@ -3481,7 +3481,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
assertThat(tc8.s).isEqualTo("123");
assertThat(tc8.d).isCloseTo(4.0d, within(0.5d));
assertThat(tc8.z).isEqualTo(true);
assertThat(tc8.z).isTrue();
// no-arg ctor
expression = parser.parseExpression("new " + testclass8 + "()");
@ -3507,7 +3507,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void methodReferenceReflectiveMethodSelectionWithVarargs() throws Exception {
void methodReferenceReflectiveMethodSelectionWithVarargs() throws Exception {
TestClass10 tc = new TestClass10();
// Should call the non varargs version of concat
@ -3526,11 +3526,11 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
expression = parser.parseExpression("concat()");
assertCantCompile(expression);
expression.getValue(tc);
assertThat(tc.s).isEqualTo("");
assertThat(tc.s).isEmpty();
assertCanCompile(expression);
tc.reset();
expression.getValue(tc);
assertThat(tc.s).isEqualTo("");
assertThat(tc.s).isEmpty();
tc.reset();
// Should call the non varargs version of concat
@ -3549,27 +3549,27 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
expression = parser.parseExpression("concat2()");
assertCantCompile(expression);
expression.getValue(tc);
assertThat(tc.s).isEqualTo("");
assertThat(tc.s).isEmpty();
assertCanCompile(expression);
tc.reset();
expression.getValue(tc);
assertThat(tc.s).isEqualTo("");
assertThat(tc.s).isEmpty();
tc.reset();
}
@Test
public void methodReferenceVarargs() throws Exception {
void methodReferenceVarargs() {
TestClass5 tc = new TestClass5();
// varargs string
expression = parser.parseExpression("eleven()");
assertCantCompile(expression);
expression.getValue(tc);
assertThat(tc.s).isEqualTo("");
assertThat(tc.s).isEmpty();
assertCanCompile(expression);
tc.reset();
expression.getValue(tc);
assertThat(tc.s).isEqualTo("");
assertThat(tc.s).isEmpty();
tc.reset();
// varargs string
@ -3840,7 +3840,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void methodReference() throws Exception {
void methodReference() {
TestClass5 tc = new TestClass5();
// non-static method, no args, void return
@ -3985,7 +3985,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void errorHandling() throws Exception {
void errorHandling() {
TestClass5 tc = new TestClass5();
// changing target
@ -4040,7 +4040,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void methodReference_staticMethod() throws Exception {
void methodReference_staticMethod() {
Expression expression = parser.parseExpression("T(Integer).valueOf(42)");
int resultI = expression.getValue(new TestClass1(), Integer.TYPE);
assertCanCompile(expression);
@ -4050,7 +4050,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void methodReference_literalArguments_int() throws Exception {
void methodReference_literalArguments_int() {
Expression expression = parser.parseExpression("'abcd'.substring(1,3)");
String resultI = expression.getValue(new TestClass1(), String.class);
assertCanCompile(expression);
@ -4060,7 +4060,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void methodReference_simpleInstanceMethodNoArg() throws Exception {
void methodReference_simpleInstanceMethodNoArg() {
Expression expression = parser.parseExpression("toString()");
String resultI = expression.getValue(42, String.class);
assertCanCompile(expression);
@ -4070,7 +4070,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void methodReference_simpleInstanceMethodNoArgReturnPrimitive() throws Exception {
void methodReference_simpleInstanceMethodNoArgReturnPrimitive() {
expression = parser.parseExpression("intValue()");
int resultI = expression.getValue(42, Integer.TYPE);
assertThat(resultI).isEqualTo(42);
@ -4080,7 +4080,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void methodReference_simpleInstanceMethodOneArgReturnPrimitive1() throws Exception {
void methodReference_simpleInstanceMethodOneArgReturnPrimitive1() {
Expression expression = parser.parseExpression("indexOf('b')");
int resultI = expression.getValue("abc", Integer.TYPE);
assertCanCompile(expression);
@ -4090,7 +4090,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void methodReference_simpleInstanceMethodOneArgReturnPrimitive2() throws Exception {
void methodReference_simpleInstanceMethodOneArgReturnPrimitive2() {
expression = parser.parseExpression("charAt(2)");
char resultI = expression.getValue("abc", Character.TYPE);
assertThat(resultI).isEqualTo('c');
@ -4100,7 +4100,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void compoundExpression() throws Exception {
void compoundExpression() {
Payload payload = new Payload();
expression = parser.parseExpression("DR[0]");
assertThat(expression.getValue(payload).toString()).isEqualTo("instanceof Two");
@ -4137,7 +4137,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void mixingItUp_indexerOpEqTernary() throws Exception {
void mixingItUp_indexerOpEqTernary() {
Map<String, String> m = new HashMap<>();
m.put("andy","778");
@ -4150,7 +4150,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void propertyReference() throws Exception {
void propertyReference() {
TestClass6 tc = new TestClass6();
// non static field
@ -4190,7 +4190,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void propertyReferenceVisibility_SPR12771() {
void propertyReferenceVisibility_SPR12771() {
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.setVariable("httpServletRequest", HttpServlet3RequestFactory.getOne());
// Without a fix compilation was inserting a checkcast to a private type
@ -4202,7 +4202,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@SuppressWarnings("unchecked")
@Test
public void indexer() throws Exception {
void indexer() {
String[] sss = new String[] {"a","b","c"};
Number[] ns = new Number[] {2,8,9};
int[] is = new int[] {8,9,10};
@ -4509,7 +4509,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void plusNeedingCheckcast_SPR12426() {
void plusNeedingCheckcast_SPR12426() {
expression = parser.parseExpression("object + ' world'");
Object v = expression.getValue(new FooObject());
assertThat(v).isEqualTo("hello world");
@ -4524,7 +4524,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void mixingItUp_propertyAccessIndexerOpLtTernaryRootNull() throws Exception {
void mixingItUp_propertyAccessIndexerOpLtTernaryRootNull() {
Payload payload = new Payload();
expression = parser.parseExpression("DR[0].three");
@ -4552,7 +4552,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void variantGetter() throws Exception {
void variantGetter() throws Exception {
Payload2Holder holder = new Payload2Holder();
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.addPropertyAccessor(new MyAccessor());
@ -4566,7 +4566,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void compilerWithGenerics_12040() {
void compilerWithGenerics_12040() {
expression = parser.parseExpression("payload!=2");
assertThat(expression.getValue(new GenericMessageTestHelper<>(4), Boolean.class)).isTrue();
assertCanCompile(expression);
@ -4675,7 +4675,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
// The new helper class here uses an upper bound on the generic
@Test
public void compilerWithGenerics_12040_2() {
void compilerWithGenerics_12040_2() {
expression = parser.parseExpression("payload/2");
assertThat(expression.getValue(new GenericMessageTestHelper2<>(4))).isEqualTo(2);
assertCanCompile(expression);
@ -4719,7 +4719,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
// The other numeric operators
@Test
public void compilerWithGenerics_12040_3() {
void compilerWithGenerics_12040_3() {
expression = parser.parseExpression("payload >= 2");
assertThat(expression.getValue(new GenericMessageTestHelper2<>(4), Boolean.TYPE)).isTrue();
assertCanCompile(expression);
@ -4762,7 +4762,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void indexerMapAccessor_12045() throws Exception {
void indexerMapAccessor_12045() throws Exception {
SpelParserConfiguration spc = new SpelParserConfiguration(
SpelCompilerMode.IMMEDIATE,getClass().getClassLoader());
SpelExpressionParser sep = new SpelExpressionParser(spc);
@ -4791,7 +4791,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void elvisOperator_SPR15192() {
void elvisOperator_SPR15192() {
SpelParserConfiguration configuration = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null);
Expression exp;
@ -4875,7 +4875,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void elvisOperator_SPR17214() throws Exception {
void elvisOperator_SPR17214() {
SpelParserConfiguration spc = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null);
SpelExpressionParser sep = new SpelExpressionParser(spc);
@ -4923,7 +4923,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void testNullComparison_SPR22358() {
void testNullComparison_SPR22358() {
SpelParserConfiguration configuration = new SpelParserConfiguration(SpelCompilerMode.OFF, null);
SpelExpressionParser parser = new SpelExpressionParser(configuration);
StandardEvaluationContext ctx = new StandardEvaluationContext();
@ -5004,7 +5004,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void ternaryOperator_SPR15192() {
void ternaryOperator_SPR15192() {
SpelParserConfiguration configuration = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null);
Expression exp;
StandardEvaluationContext context = new StandardEvaluationContext();
@ -5048,9 +5048,9 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
// null condition
exp = new SpelExpressionParser(configuration).parseExpression("3==3?null:4L");
assertThat(exp.getValue(context, new Foo(), String.class)).isEqualTo(null);
assertThat(exp.getValue(context, new Foo(), String.class)).isNull();
assertCanCompile(exp);
assertThat(exp.getValue(context, new Foo(), String.class)).isEqualTo(null);
assertThat(exp.getValue(context, new Foo(), String.class)).isNull();
assertIsCompiled(exp);
// variable access returning primitive
@ -5078,7 +5078,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
@Test
public void repeatedCompilation() throws Exception {
void repeatedCompilation() throws Exception {
// Verifying that after a number of compilations, the classloaders
// used to load the compiled expressions are discarded/replaced.
// See SpelCompiler.loadClass()
@ -6204,9 +6204,9 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
public Reg(int v) {
this._value = v;
this._valueL = new Long(v);
this._valueD = new Double(v);
this._valueF = new Float(v);
this._valueL = Long.valueOf(v);
this._valueD = (double) v;
this._valueF = (float) v;
}
public Integer getValue() {
@ -6243,16 +6243,16 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
public void setValue(Integer value) {
_value = value;
_valueL = value==null?null:new Long(value);
_valueD = value==null?null:new Double(value);
_valueF = value==null?null:new Float(value);
_valueL = value==null?null:Long.valueOf(value);
_valueD = value==null?null:Double.valueOf(value);
_valueF = value==null?null:Float.valueOf(value);
}
public void setValue2(Integer value) {
_value2 = value;
_valueL2 = value==null?null:new Long(value);
_valueD2 = value==null?null:new Double(value);
_valueF2 = value==null?null:new Float(value);
_valueL2 = value==null?null:Long.valueOf(value);
_valueD2 = value==null?null:Double.valueOf(value);
_valueF2 = value==null?null:Float.valueOf(value);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -74,35 +74,35 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Phillip Webb
* @author Sam Brannen
*/
public class SpelReproTests extends AbstractExpressionTests {
class SpelReproTests extends AbstractExpressionTests {
@Test
public void NPE_SPR5661() {
void NPE_SPR5661() {
evaluate("joinThreeStrings('a',null,'c')", "anullc", String.class);
}
@Test
public void SWF1086() {
void SWF1086() {
evaluate("printDouble(T(java.math.BigDecimal).valueOf(14.35))", "14.35", String.class);
}
@Test
public void doubleCoercion() {
void doubleCoercion() {
evaluate("printDouble(14.35)", "14.35", String.class);
}
@Test
public void doubleArrayCoercion() {
void doubleArrayCoercion() {
evaluate("printDoubles(getDoublesAsStringList())", "{14.35, 15.45}", String.class);
}
@Test
public void SPR5899() {
void SPR5899() {
StandardEvaluationContext context = new StandardEvaluationContext(new Spr5899Class());
Expression expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull(12)");
assertThat(expr.getValue(context)).isEqualTo(12);
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull(null)");
assertThat(expr.getValue(context)).isEqualTo(null);
assertThat(expr.getValue(context)).isNull();
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull2(null)");
assertThatExceptionOfType(EvaluationException.class).isThrownBy(
expr::getValue);
@ -133,7 +133,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR5905_InnerTypeReferences() {
void SPR5905_InnerTypeReferences() {
StandardEvaluationContext context = new StandardEvaluationContext(new Spr5899Class());
Expression expr = new SpelExpressionParser().parseRaw("T(java.util.Map$Entry)");
assertThat(expr.getValue(context)).isEqualTo(Map.Entry.class);
@ -146,7 +146,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR5804() {
void SPR5804() {
Map<String, String> m = new HashMap<>();
m.put("foo", "bar");
StandardEvaluationContext context = new StandardEvaluationContext(m); // root is a map instance
@ -156,7 +156,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR5847() {
void SPR5847() {
StandardEvaluationContext context = new StandardEvaluationContext(new TestProperties());
String name = null;
Expression expr = null;
@ -192,7 +192,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void NPE_SPR5673() {
void NPE_SPR5673() {
ParserContext hashes = TemplateExpressionParsingTests.HASH_DELIMITED_PARSER_CONTEXT;
ParserContext dollars = TemplateExpressionParsingTests.DEFAULT_TEMPLATE_PARSER_CONTEXT;
@ -227,7 +227,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void propertyAccessOnNullTarget_SPR5663() throws AccessException {
void propertyAccessOnNullTarget_SPR5663() throws AccessException {
PropertyAccessor accessor = new ReflectivePropertyAccessor();
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
assertThat(accessor.canRead(context, null, "abc")).isFalse();
@ -239,7 +239,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void nestedProperties_SPR6923() {
void nestedProperties_SPR6923() {
StandardEvaluationContext context = new StandardEvaluationContext(new Foo());
Expression expr = new SpelExpressionParser().parseRaw("resource.resource.server");
String name = expr.getValue(context, String.class);
@ -248,7 +248,7 @@ public class SpelReproTests extends AbstractExpressionTests {
/** Should be accessing Goo.getKey because 'bar' field evaluates to "key" */
@Test
public void indexingAsAPropertyAccess_SPR6968_1() {
void indexingAsAPropertyAccess_SPR6968_1() {
StandardEvaluationContext context = new StandardEvaluationContext(new Goo());
String name = null;
Expression expr = null;
@ -261,7 +261,7 @@ public class SpelReproTests extends AbstractExpressionTests {
/** Should be accessing Goo.getKey because 'bar' variable evaluates to "key" */
@Test
public void indexingAsAPropertyAccess_SPR6968_2() {
void indexingAsAPropertyAccess_SPR6968_2() {
StandardEvaluationContext context = new StandardEvaluationContext(new Goo());
context.setVariable("bar", "key");
String name = null;
@ -275,7 +275,7 @@ public class SpelReproTests extends AbstractExpressionTests {
/** $ related identifiers */
@Test
public void dollarPrefixedIdentifier_SPR7100() {
void dollarPrefixedIdentifier_SPR7100() {
Holder h = new Holder();
StandardEvaluationContext context = new StandardEvaluationContext(h);
context.addPropertyAccessor(new MapAccessor());
@ -315,7 +315,7 @@ public class SpelReproTests extends AbstractExpressionTests {
/** Should be accessing Goo.wibble field because 'bar' variable evaluates to "wibble" */
@Test
public void indexingAsAPropertyAccess_SPR6968_3() {
void indexingAsAPropertyAccess_SPR6968_3() {
StandardEvaluationContext context = new StandardEvaluationContext(new Goo());
context.setVariable("bar", "wibble");
String name = null;
@ -333,7 +333,7 @@ public class SpelReproTests extends AbstractExpressionTests {
* "wibble"
*/
@Test
public void indexingAsAPropertyAccess_SPR6968_4() {
void indexingAsAPropertyAccess_SPR6968_4() {
Goo g = Goo.instance;
StandardEvaluationContext context = new StandardEvaluationContext(g);
context.setVariable("bar", "wibble");
@ -348,7 +348,7 @@ public class SpelReproTests extends AbstractExpressionTests {
/** Should be accessing Goo.setKey field because 'bar' variable evaluates to "key" */
@Test
public void indexingAsAPropertyAccess_SPR6968_5() {
void indexingAsAPropertyAccess_SPR6968_5() {
Goo g = Goo.instance;
StandardEvaluationContext context = new StandardEvaluationContext(g);
Expression expr = null;
@ -360,7 +360,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void dollars() {
void dollars() {
StandardEvaluationContext context = new StandardEvaluationContext(new XX());
Expression expr = null;
expr = new SpelExpressionParser().parseRaw("m['$foo']");
@ -369,7 +369,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void dollars2() {
void dollars2() {
StandardEvaluationContext context = new StandardEvaluationContext(new XX());
Expression expr = null;
expr = new SpelExpressionParser().parseRaw("m[$foo]");
@ -421,7 +421,7 @@ public class SpelReproTests extends AbstractExpressionTests {
};
@Test
public void beanResolution() {
void beanResolution() {
StandardEvaluationContext context = new StandardEvaluationContext(new XX());
Expression expr = null;
@ -443,12 +443,12 @@ public class SpelReproTests extends AbstractExpressionTests {
// bean does not exist
expr = new SpelExpressionParser().parseRaw("@bar");
assertThat(expr.getValue(context, String.class)).isEqualTo(null);
assertThat(expr.getValue(context, String.class)).isNull();
// bean name will cause AccessException
expr = new SpelExpressionParser().parseRaw("@goo");
try {
assertThat(expr.getValue(context, String.class)).isEqualTo(null);
assertThat(expr.getValue(context, String.class)).isNull();
}
catch (SpelEvaluationException see) {
assertThat(see.getMessageCode()).isEqualTo(SpelMessage.EXCEPTION_DURING_BEAN_RESOLUTION);
@ -472,7 +472,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void elvis_SPR7209_1() {
void elvis_SPR7209_1() {
StandardEvaluationContext context = new StandardEvaluationContext(new XX());
Expression expr = null;
@ -482,14 +482,14 @@ public class SpelReproTests extends AbstractExpressionTests {
expr = new SpelExpressionParser().parseRaw("?:'default'");
assertThat(expr.getValue()).isEqualTo("default");
expr = new SpelExpressionParser().parseRaw("?:");
assertThat(expr.getValue()).isEqualTo(null);
assertThat(expr.getValue()).isNull();
// Different parts of ternary expression are null
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
new SpelExpressionParser().parseRaw("(?'abc':'default')").getValue(context))
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.TYPE_CONVERSION_ERROR));
expr = new SpelExpressionParser().parseRaw("(false?'abc':null)");
assertThat(expr.getValue()).isEqualTo(null);
assertThat(expr.getValue()).isNull();
// Assignment
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
@ -498,7 +498,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void elvis_SPR7209_2() {
void elvis_SPR7209_2() {
Expression expr = null;
// Have empty string treated as null for elvis
expr = new SpelExpressionParser().parseRaw("?:'default'");
@ -510,7 +510,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void mapOfMap_SPR7244() {
void mapOfMap_SPR7244() {
Map<String, Object> map = new LinkedHashMap<>();
map.put("uri", "http:");
Map<String, String> nameMap = new LinkedHashMap<>();
@ -531,7 +531,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void projectionTypeDescriptors_1() {
void projectionTypeDescriptors_1() {
StandardEvaluationContext context = new StandardEvaluationContext(new C());
SpelExpressionParser parser = new SpelExpressionParser();
String el1 = "ls.![#this.equals('abc')]";
@ -540,11 +540,11 @@ public class SpelReproTests extends AbstractExpressionTests {
// value is list containing [true,false]
assertThat(value.get(0).getClass()).isEqualTo(Boolean.class);
TypeDescriptor evaluated = exp.getValueTypeDescriptor(context);
assertThat(evaluated.getElementTypeDescriptor()).isEqualTo(null);
assertThat(evaluated.getElementTypeDescriptor()).isNull();
}
@Test
public void projectionTypeDescriptors_2() {
void projectionTypeDescriptors_2() {
StandardEvaluationContext context = new StandardEvaluationContext(new C());
SpelExpressionParser parser = new SpelExpressionParser();
String el1 = "as.![#this.equals('abc')]";
@ -557,7 +557,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void projectionTypeDescriptors_3() {
void projectionTypeDescriptors_3() {
StandardEvaluationContext context = new StandardEvaluationContext(new C());
SpelExpressionParser parser = new SpelExpressionParser();
String el1 = "ms.![key.equals('abc')]";
@ -566,11 +566,11 @@ public class SpelReproTests extends AbstractExpressionTests {
// value is list containing [true,false]
assertThat(value.get(0).getClass()).isEqualTo(Boolean.class);
TypeDescriptor evaluated = exp.getValueTypeDescriptor(context);
assertThat(evaluated.getElementTypeDescriptor()).isEqualTo(null);
assertThat(evaluated.getElementTypeDescriptor()).isNull();
}
@Test
public void greaterThanWithNulls_SPR7840() {
void greaterThanWithNulls_SPR7840() {
List<D> list = new ArrayList<>();
list.add(new D("aaa"));
list.add(new D("bbb"));
@ -605,7 +605,7 @@ public class SpelReproTests extends AbstractExpressionTests {
* than a unboxing conversion.
*/
@Test
public void conversionPriority_SPR8224() throws Exception {
void conversionPriority_SPR8224() throws Exception {
@SuppressWarnings("unused")
class ConversionPriority1 {
@ -637,7 +637,7 @@ public class SpelReproTests extends AbstractExpressionTests {
ConversionPriority1 target = new ConversionPriority1();
MethodExecutor me = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target, "getX", args);
// MethodInvoker chooses getX(int i) when passing Integer
final int actual = (Integer) me.execute(emptyEvalContext, target, new Integer(42)).getValue();
final int actual = (Integer) me.execute(emptyEvalContext, target, Integer.valueOf(42)).getValue();
// Compiler chooses getX(Number i) when passing Integer
final int compiler = target.getX(INTEGER);
// Fails!
@ -646,7 +646,7 @@ public class SpelReproTests extends AbstractExpressionTests {
ConversionPriority2 target2 = new ConversionPriority2();
MethodExecutor me2 = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target2, "getX", args);
// MethodInvoker chooses getX(int i) when passing Integer
int actual2 = (Integer) me2.execute(emptyEvalContext, target2, new Integer(42)).getValue();
int actual2 = (Integer) me2.execute(emptyEvalContext, target2, Integer.valueOf(42)).getValue();
// Compiler chooses getX(Number i) when passing Integer
int compiler2 = target2.getX(INTEGER);
// Fails!
@ -659,7 +659,7 @@ public class SpelReproTests extends AbstractExpressionTests {
* method accepting 'long' is ok.
*/
@Test
public void wideningPrimitiveConversion_SPR8224() throws Exception {
void wideningPrimitiveConversion_SPR8224() throws Exception {
class WideningPrimitiveConversion {
public int getX(long i) {
@ -667,7 +667,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
}
final Integer INTEGER_VALUE = Integer.valueOf(7);
final Integer INTEGER_VALUE = 7;
WideningPrimitiveConversion target = new WideningPrimitiveConversion();
EvaluationContext emptyEvalContext = new StandardEvaluationContext();
@ -682,7 +682,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void varargsAgainstProxy_SPR16122() {
void varargsAgainstProxy_SPR16122() {
SpelExpressionParser parser = new SpelExpressionParser();
Expression expr = parser.parseExpression("process('a', 'b')");
@ -696,7 +696,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void testCompiledExpressionForProxy_SPR16191() {
void testCompiledExpressionForProxy_SPR16191() {
SpelExpressionParser expressionParser =
new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null));
Expression expression = expressionParser.parseExpression("#target.process(#root)");
@ -715,7 +715,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void varargsAndPrimitives_SPR8174() throws Exception {
void varargsAndPrimitives_SPR8174() throws Exception {
EvaluationContext emptyEvalContext = new StandardEvaluationContext();
List<TypeDescriptor> args = new ArrayList<>();
@ -763,7 +763,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void reservedWords_SPR8228() {
void reservedWords_SPR8228() {
// "DIV","EQ","GE","GT","LE","LT","MOD","NE","NOT"
@SuppressWarnings("unused")
@ -814,7 +814,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void reservedWordProperties_SPR9862() {
void reservedWordProperties_SPR9862() {
StandardEvaluationContext context = new StandardEvaluationContext();
SpelExpressionParser parser = new SpelExpressionParser();
SpelExpression expression = parser.parseRaw("T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST");
@ -829,7 +829,7 @@ public class SpelReproTests extends AbstractExpressionTests {
* in evaluation of SPEL expressions for a given context.
*/
@Test
public void propertyAccessorOrder_SPR8211() {
void propertyAccessorOrder_SPR8211() {
ExpressionParser expressionParser = new SpelExpressionParser();
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new ContextObject());
@ -849,7 +849,7 @@ public class SpelReproTests extends AbstractExpressionTests {
* determines the set of methods for a type.
*/
@Test
public void customStaticFunctions_SPR9038() {
void customStaticFunctions_SPR9038() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
List<MethodResolver> methodResolvers = new ArrayList<>();
@ -873,7 +873,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void array() {
void array() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Expression expression = null;
@ -902,7 +902,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatFunctionResolver() {
void SPR9486_floatFunctionResolver() {
Number expectedResult = Math.abs(-10.2f);
ExpressionParser parser = new SpelExpressionParser();
SPR9486_FunctionsClass testObject = new SPR9486_FunctionsClass();
@ -914,7 +914,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_addFloatWithDouble() {
void SPR9486_addFloatWithDouble() {
Number expectedNumber = 10.21f + 10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -924,7 +924,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_addFloatWithFloat() {
void SPR9486_addFloatWithFloat() {
Number expectedNumber = 10.21f + 10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -934,7 +934,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_subtractFloatWithDouble() {
void SPR9486_subtractFloatWithDouble() {
Number expectedNumber = 10.21f - 10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -944,7 +944,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_subtractFloatWithFloat() {
void SPR9486_subtractFloatWithFloat() {
Number expectedNumber = 10.21f - 10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -954,7 +954,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_multiplyFloatWithDouble() {
void SPR9486_multiplyFloatWithDouble() {
Number expectedNumber = 10.21f * 10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -964,7 +964,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_multiplyFloatWithFloat() {
void SPR9486_multiplyFloatWithFloat() {
Number expectedNumber = 10.21f * 10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -974,7 +974,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatDivideByFloat() {
void SPR9486_floatDivideByFloat() {
Number expectedNumber = -10.21f / -10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -984,7 +984,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatDivideByDouble() {
void SPR9486_floatDivideByDouble() {
Number expectedNumber = -10.21f / -10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -994,7 +994,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatEqFloatUnaryMinus() {
void SPR9486_floatEqFloatUnaryMinus() {
Boolean expectedResult = -10.21f == -10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1004,7 +1004,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatEqDoubleUnaryMinus() {
void SPR9486_floatEqDoubleUnaryMinus() {
Boolean expectedResult = -10.21f == -10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1014,7 +1014,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatEqFloat() {
void SPR9486_floatEqFloat() {
Boolean expectedResult = 10.215f == 10.2109f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1024,7 +1024,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatEqDouble() {
void SPR9486_floatEqDouble() {
Boolean expectedResult = 10.215f == 10.2109;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1034,7 +1034,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatNotEqFloat() {
void SPR9486_floatNotEqFloat() {
Boolean expectedResult = 10.215f != 10.2109f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1044,7 +1044,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatNotEqDouble() {
void SPR9486_floatNotEqDouble() {
Boolean expectedResult = 10.215f != 10.2109;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1054,7 +1054,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatLessThanFloat() {
void SPR9486_floatLessThanFloat() {
Boolean expectedNumber = -10.21f < -10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1064,7 +1064,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatLessThanDouble() {
void SPR9486_floatLessThanDouble() {
Boolean expectedNumber = -10.21f < -10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1074,7 +1074,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatLessThanOrEqualFloat() {
void SPR9486_floatLessThanOrEqualFloat() {
Boolean expectedNumber = -10.21f <= -10.22f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1084,7 +1084,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatLessThanOrEqualDouble() {
void SPR9486_floatLessThanOrEqualDouble() {
Boolean expectedNumber = -10.21f <= -10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1094,7 +1094,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatGreaterThanFloat() {
void SPR9486_floatGreaterThanFloat() {
Boolean expectedNumber = -10.21f > -10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1104,7 +1104,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatGreaterThanDouble() {
void SPR9486_floatGreaterThanDouble() {
Boolean expectedResult = -10.21f > -10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1114,7 +1114,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatGreaterThanOrEqualFloat() {
void SPR9486_floatGreaterThanOrEqualFloat() {
Boolean expectedNumber = -10.21f >= -10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1124,7 +1124,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatGreaterThanEqualDouble() {
void SPR9486_floatGreaterThanEqualDouble() {
Boolean expectedResult = -10.21f >= -10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1134,7 +1134,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatModulusFloat() {
void SPR9486_floatModulusFloat() {
Number expectedResult = 10.21f % 10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1144,7 +1144,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatModulusDouble() {
void SPR9486_floatModulusDouble() {
Number expectedResult = 10.21f % 10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1154,7 +1154,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatPowerFloat() {
void SPR9486_floatPowerFloat() {
Number expectedResult = Math.pow(10.21f, -10.2f);
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1164,7 +1164,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9486_floatPowerDouble() {
void SPR9486_floatPowerDouble() {
Number expectedResult = Math.pow(10.21f, 10.2);
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
@ -1174,7 +1174,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9994_bridgeMethods() throws Exception {
void SPR9994_bridgeMethods() throws Exception {
ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
StandardEvaluationContext context = new StandardEvaluationContext();
GenericImplementation target = new GenericImplementation();
@ -1187,7 +1187,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR10162_onlyBridgeMethod() throws Exception {
void SPR10162_onlyBridgeMethod() throws Exception {
ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
StandardEvaluationContext context = new StandardEvaluationContext();
Object target = new OnlyBridgeMethod();
@ -1197,7 +1197,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR10091_simpleTestValueType() {
void SPR10091_simpleTestValueType() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
Class<?> valueType = parser.parseExpression("simpleProperty").getValueType(evaluationContext);
@ -1205,7 +1205,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR10091_simpleTestValue() {
void SPR10091_simpleTestValue() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
Object value = parser.parseExpression("simpleProperty").getValue(evaluationContext);
@ -1213,7 +1213,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR10091_primitiveTestValueType() {
void SPR10091_primitiveTestValueType() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
Class<?> valueType = parser.parseExpression("primitiveProperty").getValueType(evaluationContext);
@ -1221,7 +1221,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR10091_primitiveTestValue() {
void SPR10091_primitiveTestValue() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
Object value = parser.parseExpression("primitiveProperty").getValue(evaluationContext);
@ -1229,7 +1229,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR16123() {
void SPR16123() {
ExpressionParser parser = new SpelExpressionParser();
parser.parseExpression("simpleProperty").setValue(new BooleanHolder(), null);
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
@ -1237,7 +1237,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR10146_malformedExpressions() {
void SPR10146_malformedExpressions() {
doTestSpr10146("/foo", "EL1070E: Problem parsing left operand");
doTestSpr10146("*foo", "EL1070E: Problem parsing left operand");
doTestSpr10146("%foo", "EL1070E: Problem parsing left operand");
@ -1255,7 +1255,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR10125() {
void SPR10125() {
StandardEvaluationContext context = new StandardEvaluationContext();
String fromInterface = parser.parseExpression("T(" + StaticFinalImpl1.class.getName() + ").VALUE").getValue(
context, String.class);
@ -1266,7 +1266,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR10210() {
void SPR10210() {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("bridgeExample", new org.springframework.expression.spel.spr10210.D());
Expression parseExpression = parser.parseExpression("#bridgeExample.bridgeMethod()");
@ -1274,14 +1274,14 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR10328() {
void SPR10328() {
assertThatExceptionOfType(SpelParseException.class).isThrownBy(() ->
parser.parseExpression("$[]"))
.withMessageContaining("EL1071E: A required selection expression has not been specified");
}
@Test
public void SPR10452() {
void SPR10452() {
SpelParserConfiguration configuration = new SpelParserConfiguration(false, false);
ExpressionParser parser = new SpelExpressionParser(configuration);
@ -1306,7 +1306,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9495() {
void SPR9495() {
SpelParserConfiguration configuration = new SpelParserConfiguration(false, false);
ExpressionParser parser = new SpelExpressionParser(configuration);
@ -1347,7 +1347,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR10486() {
void SPR10486() {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Spr10486 rootObject = new Spr10486();
@ -1358,7 +1358,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR11142() {
void SPR11142() {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Spr11142 rootObject = new Spr11142();
@ -1369,7 +1369,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9194() {
void SPR9194() {
TestClass2 one = new TestClass2("abc");
TestClass2 two = new TestClass2("abc");
Map<String, TestClass2> map = new HashMap<>();
@ -1382,7 +1382,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR11348() {
void SPR11348() {
Collection<String> coll = new LinkedHashSet<>();
coll.add("one");
coll.add("two");
@ -1399,14 +1399,14 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR11445_simple() {
void SPR11445_simple() {
StandardEvaluationContext context = new StandardEvaluationContext(new Spr11445Class());
Expression expr = new SpelExpressionParser().parseRaw("echo(parameter())");
assertThat(expr.getValue(context)).isEqualTo(1);
}
@Test
public void SPR11445_beanReference() {
void SPR11445_beanReference() {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new Spr11445Class());
Expression expr = new SpelExpressionParser().parseRaw("@bean.echo(@bean.parameter())");
@ -1415,14 +1415,14 @@ public class SpelReproTests extends AbstractExpressionTests {
@Test
@SuppressWarnings("unchecked")
public void SPR11494() {
void SPR11494() {
Expression exp = new SpelExpressionParser().parseExpression("T(java.util.Arrays).asList('a','b')");
List<String> list = (List<String>) exp.getValue();
assertThat(list).hasSize(2);
}
@Test
public void SPR11609() {
void SPR11609() {
StandardEvaluationContext sec = new StandardEvaluationContext();
sec.addPropertyAccessor(new MapAccessor());
Expression exp = new SpelExpressionParser().parseExpression(
@ -1431,7 +1431,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR9735() {
void SPR9735() {
Item item = new Item();
item.setName("parent");
@ -1453,7 +1453,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR12502() {
void SPR12502() {
SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("#root.getClass().getName()");
assertThat(expression.getValue(new UnnamedUser())).isEqualTo(UnnamedUser.class.getName());
@ -1462,7 +1462,7 @@ public class SpelReproTests extends AbstractExpressionTests {
@Test
@SuppressWarnings("rawtypes")
public void SPR12522() {
void SPR12522() {
SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("T(java.util.Arrays).asList('')");
Object value = expression.getValue();
@ -1471,7 +1471,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR12803() {
void SPR12803() {
StandardEvaluationContext sec = new StandardEvaluationContext();
sec.setVariable("iterable", Collections.emptyList());
SpelExpressionParser parser = new SpelExpressionParser();
@ -1480,7 +1480,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR12808() {
void SPR12808() {
SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("T(org.springframework.expression.spel.SpelReproTests.DistanceEnforcer).from(#no)");
StandardEvaluationContext sec = new StandardEvaluationContext();
@ -1496,7 +1496,7 @@ public class SpelReproTests extends AbstractExpressionTests {
@Test
@SuppressWarnings("rawtypes")
public void SPR13055() {
void SPR13055() {
List<Map<String, Object>> myPayload = new ArrayList<>();
Map<String, Object> v1 = new HashMap<>();
@ -1527,7 +1527,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void AccessingFactoryBean_spr9511() {
void AccessingFactoryBean_spr9511() {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new MyBeanResolver());
Expression expr = new SpelExpressionParser().parseRaw("@foo");
@ -1551,7 +1551,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR12035() {
void SPR12035() {
ExpressionParser parser = new SpelExpressionParser();
Expression expression1 = parser.parseExpression("list.?[ value>2 ].size()!=0");
@ -1562,7 +1562,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR13055_maps() {
void SPR13055_maps() {
EvaluationContext context = new StandardEvaluationContext();
ExpressionParser parser = new SpelExpressionParser();
@ -1578,7 +1578,7 @@ public class SpelReproTests extends AbstractExpressionTests {
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void SPR10417() {
void SPR10417() {
List list1 = new ArrayList();
list1.add("a");
list1.add("b");
@ -1619,7 +1619,7 @@ public class SpelReproTests extends AbstractExpressionTests {
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void SPR10417_maps() {
void SPR10417_maps() {
Map map1 = new HashMap();
map1.put("A", 65);
map1.put("B", 66);
@ -1642,7 +1642,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR13918() {
void SPR13918() {
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("encoding", "UTF-8");
@ -1652,7 +1652,7 @@ public class SpelReproTests extends AbstractExpressionTests {
}
@Test
public void SPR16032() {
void SPR16032() {
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("str", "a\0b");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -32,7 +32,6 @@ import javax.jms.Session;
import javax.jms.TextMessage;
import org.junit.jupiter.api.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.jms.support.converter.MessageConversionException;
@ -51,7 +50,7 @@ import static org.mockito.Mockito.verify;
* @author Juergen Hoeller
* @author Chris Beams
*/
public class MessageListenerAdapterTests {
class MessageListenerAdapterTests {
private static final String TEXT = "I fancy a good cuppa right now";
@ -65,7 +64,7 @@ public class MessageListenerAdapterTests {
@Test
public void testWithMessageContentsDelegateForTextMessage() throws Exception {
void testWithMessageContentsDelegateForTextMessage() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
// TextMessage contents must be unwrapped...
given(textMessage.getText()).willReturn(TEXT);
@ -79,17 +78,14 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithMessageContentsDelegateForBytesMessage() throws Exception {
void testWithMessageContentsDelegateForBytesMessage() throws Exception {
BytesMessage bytesMessage = mock(BytesMessage.class);
// BytesMessage contents must be unwrapped...
given(bytesMessage.getBodyLength()).willReturn(new Long(TEXT.getBytes().length));
given(bytesMessage.readBytes(any(byte[].class))).willAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
byte[] bytes = (byte[]) invocation.getArguments()[0];
ByteArrayInputStream inputStream = new ByteArrayInputStream(TEXT.getBytes());
return inputStream.read(bytes);
}
given(bytesMessage.getBodyLength()).willReturn(Long.valueOf(TEXT.getBytes().length));
given(bytesMessage.readBytes(any(byte[].class))).willAnswer((Answer<Integer>) invocation -> {
byte[] bytes = (byte[]) invocation.getArguments()[0];
ByteArrayInputStream inputStream = new ByteArrayInputStream(TEXT.getBytes());
return inputStream.read(bytes);
});
MessageContentsDelegate delegate = mock(MessageContentsDelegate.class);
@ -101,7 +97,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithMessageContentsDelegateForObjectMessage() throws Exception {
void testWithMessageContentsDelegateForObjectMessage() throws Exception {
ObjectMessage objectMessage = mock(ObjectMessage.class);
given(objectMessage.getObject()).willReturn(NUMBER);
@ -114,7 +110,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithMessageContentsDelegateForObjectMessageWithPlainObject() throws Exception {
void testWithMessageContentsDelegateForObjectMessageWithPlainObject() throws Exception {
ObjectMessage objectMessage = mock(ObjectMessage.class);
given(objectMessage.getObject()).willReturn(OBJECT);
@ -127,7 +123,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithMessageDelegate() throws Exception {
void testWithMessageDelegate() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
MessageDelegate delegate = mock(MessageDelegate.class);
@ -141,7 +137,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWhenTheAdapterItselfIsTheDelegate() throws Exception {
void testWhenTheAdapterItselfIsTheDelegate() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
// TextMessage contents must be unwrapped...
given(textMessage.getText()).willReturn(TEXT);
@ -152,7 +148,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testRainyDayWithNoApplicableHandlingMethods() throws Exception {
void testRainyDayWithNoApplicableHandlingMethods() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
// TextMessage contents must be unwrapped...
given(textMessage.getText()).willReturn(TEXT);
@ -164,7 +160,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testThatAnExceptionThrownFromTheHandlingMethodIsSimplySwallowedByDefault() throws Exception {
void testThatAnExceptionThrownFromTheHandlingMethodIsSimplySwallowedByDefault() throws Exception {
final IllegalArgumentException exception = new IllegalArgumentException();
TextMessage textMessage = mock(TextMessage.class);
@ -189,7 +185,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testThatTheDefaultMessageConverterisIndeedTheSimpleMessageConverter() throws Exception {
void testThatTheDefaultMessageConverterisIndeedTheSimpleMessageConverter() throws Exception {
MessageListenerAdapter adapter = new MessageListenerAdapter();
assertThat(adapter.getMessageConverter()).as("The default [MessageConverter] must never be null.").isNotNull();
boolean condition = adapter.getMessageConverter() instanceof SimpleMessageConverter;
@ -197,19 +193,19 @@ public class MessageListenerAdapterTests {
}
@Test
public void testThatWhenNoDelegateIsSuppliedTheDelegateIsAssumedToBeTheMessageListenerAdapterItself() throws Exception {
void testThatWhenNoDelegateIsSuppliedTheDelegateIsAssumedToBeTheMessageListenerAdapterItself() throws Exception {
MessageListenerAdapter adapter = new MessageListenerAdapter();
assertThat(adapter.getDelegate()).isSameAs(adapter);
}
@Test
public void testThatTheDefaultMessageHandlingMethodNameIsTheConstantDefault() throws Exception {
void testThatTheDefaultMessageHandlingMethodNameIsTheConstantDefault() throws Exception {
MessageListenerAdapter adapter = new MessageListenerAdapter();
assertThat(adapter.getDefaultListenerMethod()).isEqualTo(MessageListenerAdapter.ORIGINAL_DEFAULT_LISTENER_METHOD);
}
@Test
public void testWithResponsiveMessageDelegate_DoesNotSendReturnTextMessageIfNoSessionSupplied() throws Exception {
void testWithResponsiveMessageDelegate_DoesNotSendReturnTextMessageIfNoSessionSupplied() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
given(delegate.handleMessage(textMessage)).willReturn(TEXT);
@ -221,7 +217,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateWithDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
void testWithResponsiveMessageDelegateWithDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
Queue destination = mock(Queue.class);
TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...
@ -256,7 +252,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
Queue destination = mock(Queue.class);
TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...
@ -289,7 +285,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateNoDefaultDestinationAndNoReplyToDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
void testWithResponsiveMessageDelegateNoDefaultDestinationAndNoReplyToDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
final TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...
given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
@ -318,7 +314,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied_AndSendingThrowsJMSException() throws Exception {
void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied_AndSendingThrowsJMSException() throws Exception {
Queue destination = mock(Queue.class);
final TextMessage sentTextMessage = mock(TextMessage.class);
@ -354,7 +350,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateDoesNotSendReturnTextMessageWhenSessionSupplied_AndListenerMethodThrowsException() throws Exception {
void testWithResponsiveMessageDelegateDoesNotSendReturnTextMessageWhenSessionSupplied_AndListenerMethodThrowsException() throws Exception {
final TextMessage message = mock(TextMessage.class);
final QueueSession session = mock(QueueSession.class);
@ -372,7 +368,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
void testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
final TextMessage sentTextMessage = mock(TextMessage.class);
final Session session = mock(Session.class);
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
@ -391,7 +387,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
void testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
Queue destination = mock(Queue.class);
final TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -31,7 +31,6 @@ import javax.jms.TextMessage;
import com.fasterxml.jackson.annotation.JsonView;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.core.MethodParameter;
@ -49,7 +48,7 @@ import static org.mockito.Mockito.verify;
* @author Dave Syer
* @author Stephane Nicoll
*/
public class MappingJackson2MessageConverterTests {
class MappingJackson2MessageConverterTests {
private MappingJackson2MessageConverter converter;
@ -66,7 +65,7 @@ public class MappingJackson2MessageConverterTests {
@Test
public void toBytesMessage() throws Exception {
void toBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class);
Date toBeMarshalled = new Date();
@ -80,7 +79,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void fromBytesMessage() throws Exception {
void fromBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
@ -89,21 +88,16 @@ public class MappingJackson2MessageConverterTests {
given(bytesMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName());
given(bytesMessageMock.propertyExists("__encoding__")).willReturn(false);
given(bytesMessageMock.getBodyLength()).willReturn(new Long(bytes.length));
given(bytesMessageMock.getBodyLength()).willReturn(Long.valueOf(bytes.length));
given(bytesMessageMock.readBytes(any(byte[].class))).willAnswer(
new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
return byteStream.read((byte[]) invocation.getArguments()[0]);
}
});
(Answer<Integer>) invocation -> byteStream.read((byte[]) invocation.getArguments()[0]));
Object result = converter.fromMessage(bytesMessageMock);
assertThat(unmarshalled).as("Invalid result").isEqualTo(result);
}
@Test
public void toTextMessageWithObject() throws Exception {
void toTextMessageWithObject() throws Exception {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
Date toBeMarshalled = new Date();
@ -115,7 +109,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithMap() throws Exception {
void toTextMessageWithMap() throws Exception {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
Map<String, String> toBeMarshalled = new HashMap<>();
@ -128,7 +122,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void fromTextMessage() throws Exception {
void fromTextMessage() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
MyBean unmarshalled = new MyBean("bar");
@ -141,7 +135,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void fromTextMessageWithUnknownProperty() throws Exception {
void fromTextMessageWithUnknownProperty() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
MyBean unmarshalled = new MyBean("bar");
@ -154,7 +148,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void fromTextMessageAsObject() throws Exception {
void fromTextMessageAsObject() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
@ -167,7 +161,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void fromTextMessageAsMap() throws Exception {
void fromTextMessageAsMap() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
@ -180,7 +174,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithReturnType() throws JMSException, NoSuchMethodException {
void toTextMessageWithReturnType() throws JMSException, NoSuchMethodException {
Method method = this.getClass().getDeclaredMethod("summary");
MethodParameter returnType = new MethodParameter(method, -1);
testToTextMessageWithReturnType(returnType);
@ -188,13 +182,13 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithNullReturnType() throws JMSException, NoSuchMethodException {
void toTextMessageWithNullReturnType() throws JMSException, NoSuchMethodException {
testToTextMessageWithReturnType(null);
verify(sessionMock).createTextMessage("{\"name\":\"test\",\"description\":\"lengthy description\"}");
}
@Test
public void toTextMessageWithReturnTypeAndNoJsonView() throws JMSException, NoSuchMethodException {
void toTextMessageWithReturnTypeAndNoJsonView() throws JMSException, NoSuchMethodException {
Method method = this.getClass().getDeclaredMethod("none");
MethodParameter returnType = new MethodParameter(method, -1);
@ -203,7 +197,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithReturnTypeAndMultipleJsonViews() throws JMSException, NoSuchMethodException {
void toTextMessageWithReturnTypeAndMultipleJsonViews() throws JMSException, NoSuchMethodException {
Method method = this.getClass().getDeclaredMethod("invalid");
MethodParameter returnType = new MethodParameter(method, -1);
@ -222,7 +216,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithJsonViewClass() throws JMSException {
void toTextMessageWithJsonViewClass() throws JMSException {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
@ -236,7 +230,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithAnotherJsonViewClass() throws JMSException {
void toTextMessageWithAnotherJsonViewClass() throws JMSException {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);

View File

@ -83,7 +83,7 @@ public class EscapedErrorsTests {
FieldError ageError = errors.getFieldError("age");
assertThat("message: &lt;tag&gt;".equals(ageError.getDefaultMessage())).as("Age error message escaped").isTrue();
assertThat("AGE_NOT_SET <tag>".equals(ageError.getCode())).as("Age error code not escaped").isTrue();
assertThat((new Integer(0)).equals(errors.getFieldValue("age"))).as("Age value not escaped").isTrue();
assertThat((Integer.valueOf(0)).equals(errors.getFieldValue("age"))).as("Age value not escaped").isTrue();
FieldError ageErrorInList = errors.getFieldErrors("age").get(0);
assertThat(ageError.getDefaultMessage().equals(ageErrorInList.getDefaultMessage())).as("Same name error in list").isTrue();
FieldError ageError2 = errors.getFieldErrors("age").get(1);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -47,7 +47,7 @@ class ServletRequestUtilsTests {
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredIntParameter(request, "param2"));
assertThat(ServletRequestUtils.getIntParameter(request, "param3")).isEqualTo(null);
assertThat(ServletRequestUtils.getIntParameter(request, "param3")).isNull();
assertThat(ServletRequestUtils.getIntParameter(request, "param3", 6)).isEqualTo(6);
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredIntParameter(request, "param3"));
@ -66,7 +66,7 @@ class ServletRequestUtilsTests {
int[] array = new int[] {1, 2, 3};
int[] values = ServletRequestUtils.getRequiredIntParameters(request, "param");
assertThat(3).isEqualTo(values.length);
assertThat(values).hasSize(3);
for (int i = 0; i < array.length; i++) {
assertThat(array[i]).isEqualTo(values[i]);
}
@ -81,7 +81,7 @@ class ServletRequestUtilsTests {
request.addParameter("param2", "e");
request.addParameter("paramEmpty", "");
assertThat(ServletRequestUtils.getLongParameter(request, "param1")).isEqualTo(new Long(5L));
assertThat(ServletRequestUtils.getLongParameter(request, "param1")).isEqualTo(Long.valueOf(5L));
assertThat(ServletRequestUtils.getLongParameter(request, "param1", 6L)).isEqualTo(5L);
assertThat(ServletRequestUtils.getRequiredIntParameter(request, "param1")).isEqualTo(5L);
@ -89,7 +89,7 @@ class ServletRequestUtilsTests {
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredLongParameter(request, "param2"));
assertThat(ServletRequestUtils.getLongParameter(request, "param3")).isEqualTo(null);
assertThat(ServletRequestUtils.getLongParameter(request, "param3")).isNull();
assertThat(ServletRequestUtils.getLongParameter(request, "param3", 6L)).isEqualTo(6L);
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredLongParameter(request, "param3"));
@ -128,7 +128,7 @@ class ServletRequestUtilsTests {
request.addParameter("param2", "e");
request.addParameter("paramEmpty", "");
assertThat(ServletRequestUtils.getFloatParameter(request, "param1").equals(new Float(5.5f))).isTrue();
assertThat(ServletRequestUtils.getFloatParameter(request, "param1")).isEqualTo(Float.valueOf(5.5f));
assertThat(ServletRequestUtils.getFloatParameter(request, "param1", 6.5f) == 5.5f).isTrue();
assertThat(ServletRequestUtils.getRequiredFloatParameter(request, "param1") == 5.5f).isTrue();
@ -136,7 +136,7 @@ class ServletRequestUtilsTests {
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredFloatParameter(request, "param2"));
assertThat(ServletRequestUtils.getFloatParameter(request, "param3") == null).isTrue();
assertThat(ServletRequestUtils.getFloatParameter(request, "param3")).isNull();
assertThat(ServletRequestUtils.getFloatParameter(request, "param3", 6.5f) == 6.5f).isTrue();
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredFloatParameter(request, "param3"));
@ -166,7 +166,7 @@ class ServletRequestUtilsTests {
request.addParameter("param2", "e");
request.addParameter("paramEmpty", "");
assertThat(ServletRequestUtils.getDoubleParameter(request, "param1").equals(new Double(5.5))).isTrue();
assertThat(ServletRequestUtils.getDoubleParameter(request, "param1")).isEqualTo(Double.valueOf(5.5));
assertThat(ServletRequestUtils.getDoubleParameter(request, "param1", 6.5) == 5.5).isTrue();
assertThat(ServletRequestUtils.getRequiredDoubleParameter(request, "param1") == 5.5).isTrue();
@ -174,7 +174,7 @@ class ServletRequestUtilsTests {
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredDoubleParameter(request, "param2"));
assertThat(ServletRequestUtils.getDoubleParameter(request, "param3") == null).isTrue();
assertThat(ServletRequestUtils.getDoubleParameter(request, "param3")).isNull();
assertThat(ServletRequestUtils.getDoubleParameter(request, "param3", 6.5) == 6.5).isTrue();
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredDoubleParameter(request, "param3"));
@ -212,7 +212,7 @@ class ServletRequestUtilsTests {
assertThat(ServletRequestUtils.getBooleanParameter(request, "param2", true)).isFalse();
assertThat(ServletRequestUtils.getRequiredBooleanParameter(request, "param2")).isFalse();
assertThat(ServletRequestUtils.getBooleanParameter(request, "param3") == null).isTrue();
assertThat(ServletRequestUtils.getBooleanParameter(request, "param3")).isNull();
assertThat(ServletRequestUtils.getBooleanParameter(request, "param3", true)).isTrue();
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredBooleanParameter(request, "param3"));
@ -235,14 +235,14 @@ class ServletRequestUtilsTests {
boolean[] array = new boolean[] {true, true, false, true, false};
boolean[] values = ServletRequestUtils.getRequiredBooleanParameters(request, "param");
assertThat(array.length).isEqualTo(values.length);
assertThat(array).hasSameSizeAs(values);
for (int i = 0; i < array.length; i++) {
assertThat(array[i]).isEqualTo(values[i]);
}
array = new boolean[] {false, true, false};
values = ServletRequestUtils.getRequiredBooleanParameters(request, "param2");
assertThat(array.length).isEqualTo(values.length);
assertThat(array).hasSameSizeAs(values);
for (int i = 0; i < array.length; i++) {
assertThat(array[i]).isEqualTo(values[i]);
}

View File

@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @author Sebastien Deleuze
* @author Sam Brannen
*/
public class CorsConfigurationTests {
class CorsConfigurationTests {
@Test
public void setNullValues() {
void setNullValues() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedOrigins(null);
assertThat(config.getAllowedOrigins()).isNull();
@ -55,7 +55,7 @@ public class CorsConfigurationTests {
}
@Test
public void setValues() {
void setValues() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.addAllowedOriginPattern("http://*.example.com");
@ -71,11 +71,11 @@ public class CorsConfigurationTests {
assertThat(config.getAllowedMethods()).containsExactly("*");
assertThat(config.getExposedHeaders()).containsExactly("*");
assertThat(config.getAllowCredentials()).isTrue();
assertThat(config.getMaxAge()).isEqualTo(new Long(123));
assertThat(config.getMaxAge()).isEqualTo(Long.valueOf(123));
}
@Test
public void combineWithNull() {
void combineWithNull() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedOrigins(Collections.singletonList("*"));
config.combine(null);
@ -84,7 +84,7 @@ public class CorsConfigurationTests {
}
@Test
public void combineWithNullProperties() {
void combineWithNullProperties() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.setAllowedOriginPatterns(Collections.singletonList("http://*.example.com"));
@ -103,12 +103,12 @@ public class CorsConfigurationTests {
assertThat(config.getAllowedHeaders()).containsExactly("header1");
assertThat(config.getExposedHeaders()).containsExactly("header3");
assertThat(config.getAllowedMethods()).containsExactly(HttpMethod.GET.name());
assertThat(config.getMaxAge()).isEqualTo(new Long(123));
assertThat(config.getMaxAge()).isEqualTo(Long.valueOf(123));
assertThat(config.getAllowCredentials()).isTrue();
}
@Test // SPR-15772
public void combineWithDefaultPermitValues() {
void combineWithDefaultPermitValues() {
CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues();
CorsConfiguration other = new CorsConfiguration();
other.addAllowedOrigin("https://domain.com");
@ -147,7 +147,7 @@ public class CorsConfigurationTests {
}
@Test
public void combinePatternWithDefaultPermitValues() {
void combinePatternWithDefaultPermitValues() {
CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues();
CorsConfiguration other = new CorsConfiguration();
other.addAllowedOriginPattern("http://*.com");
@ -164,7 +164,7 @@ public class CorsConfigurationTests {
}
@Test
public void combinePatternWithDefaultPermitValuesAndCustomOrigin() {
void combinePatternWithDefaultPermitValuesAndCustomOrigin() {
CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues();
config.setAllowedOrigins(Collections.singletonList("https://domain.com"));
@ -183,7 +183,7 @@ public class CorsConfigurationTests {
}
@Test
public void combineWithAsteriskWildCard() {
void combineWithAsteriskWildCard() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
@ -219,7 +219,7 @@ public class CorsConfigurationTests {
}
@Test // SPR-14792
public void combineWithDuplicatedElements() {
void combineWithDuplicatedElements() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("https://domain1.com");
config.addAllowedOrigin("https://domain2.com");
@ -249,7 +249,7 @@ public class CorsConfigurationTests {
}
@Test
public void combine() {
void combine() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("https://domain1.com");
config.addAllowedOriginPattern("http://*.domain1.com");
@ -274,14 +274,14 @@ public class CorsConfigurationTests {
assertThat(config.getAllowedHeaders()).containsExactly("header1", "header2");
assertThat(config.getExposedHeaders()).containsExactly("header3", "header4");
assertThat(config.getAllowedMethods()).containsExactly(HttpMethod.GET.name(), HttpMethod.PUT.name());
assertThat(config.getMaxAge()).isEqualTo(new Long(456));
assertThat(config.getMaxAge()).isEqualTo(Long.valueOf(456));
assertThat(config).isNotNull();
assertThat(config.getAllowCredentials()).isFalse();
assertThat(config.getAllowedOriginPatterns()).containsExactly("http://*.domain1.com", "http://*.domain2.com");
}
@Test
public void checkOriginAllowed() {
void checkOriginAllowed() {
// "*" matches
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
@ -306,7 +306,7 @@ public class CorsConfigurationTests {
}
@Test
public void checkOriginNotAllowed() {
void checkOriginNotAllowed() {
CorsConfiguration config = new CorsConfiguration();
assertThat(config.checkOrigin(null)).isNull();
assertThat(config.checkOrigin("https://domain.com")).isNull();
@ -322,7 +322,7 @@ public class CorsConfigurationTests {
}
@Test
public void checkOriginPatternAllowed() {
void checkOriginPatternAllowed() {
CorsConfiguration config = new CorsConfiguration();
assertThat(config.checkOrigin("https://domain.com")).isNull();
@ -349,7 +349,7 @@ public class CorsConfigurationTests {
}
@Test
public void checkOriginPatternNotAllowed() {
void checkOriginPatternNotAllowed() {
CorsConfiguration config = new CorsConfiguration();
assertThat(config.checkOrigin(null)).isNull();
assertThat(config.checkOrigin("https://domain.com")).isNull();
@ -367,7 +367,7 @@ public class CorsConfigurationTests {
}
@Test
public void checkMethodAllowed() {
void checkMethodAllowed() {
CorsConfiguration config = new CorsConfiguration();
assertThat(config.checkHttpMethod(HttpMethod.GET)).containsExactly(HttpMethod.GET, HttpMethod.HEAD);
@ -380,7 +380,7 @@ public class CorsConfigurationTests {
}
@Test
public void checkMethodNotAllowed() {
void checkMethodNotAllowed() {
CorsConfiguration config = new CorsConfiguration();
assertThat(config.checkHttpMethod(null)).isNull();
assertThat(config.checkHttpMethod(HttpMethod.DELETE)).isNull();
@ -390,7 +390,7 @@ public class CorsConfigurationTests {
}
@Test
public void checkHeadersAllowed() {
void checkHeadersAllowed() {
CorsConfiguration config = new CorsConfiguration();
assertThat(config.checkHeaders(Collections.emptyList())).isEqualTo(Collections.emptyList());
@ -403,7 +403,7 @@ public class CorsConfigurationTests {
}
@Test
public void checkHeadersNotAllowed() {
void checkHeadersNotAllowed() {
CorsConfiguration config = new CorsConfiguration();
assertThat(config.checkHeaders(null)).isNull();
assertThat(config.checkHeaders(Collections.singletonList("header1"))).isNull();
@ -417,7 +417,7 @@ public class CorsConfigurationTests {
}
@Test // SPR-15772
public void changePermitDefaultValues() {
void changePermitDefaultValues() {
CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues();
config.addAllowedOrigin("https://domain.com");
config.addAllowedHeader("header1");
@ -429,7 +429,7 @@ public class CorsConfigurationTests {
}
@Test
public void permitDefaultDoesntSetOriginWhenPatternPresent() {
void permitDefaultDoesntSetOriginWhenPatternPresent() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOriginPattern("http://*.com");
config = config.applyPermitDefaultValues();

View File

@ -159,7 +159,7 @@ class CrossOriginTests {
assertThat(config.getAllowCredentials()).isNull();
assertThat(config.getAllowedHeaders()).containsExactly("*");
assertThat(CollectionUtils.isEmpty(config.getExposedHeaders())).isTrue();
assertThat(config.getMaxAge()).isEqualTo(new Long(1800));
assertThat(config.getMaxAge()).isEqualTo(Long.valueOf(1800));
}
@PathPatternsParameterizedTest
@ -173,7 +173,7 @@ class CrossOriginTests {
assertThat(config.getAllowedOrigins()).containsExactly("https://site1.com", "https://site2.com");
assertThat(config.getAllowedHeaders()).containsExactly("header1", "header2");
assertThat(config.getExposedHeaders()).containsExactly("header3", "header4");
assertThat(config.getMaxAge()).isEqualTo(new Long(123));
assertThat(config.getMaxAge()).isEqualTo(Long.valueOf(123));
assertThat(config.getAllowCredentials()).isFalse();
}
@ -315,7 +315,7 @@ class CrossOriginTests {
assertThat(config.getAllowCredentials()).isNull();
assertThat(config.getAllowedHeaders()).containsExactly("*");
assertThat(CollectionUtils.isEmpty(config.getExposedHeaders())).isTrue();
assertThat(config.getMaxAge()).isEqualTo(new Long(1800));
assertThat(config.getMaxAge()).isEqualTo(Long.valueOf(1800));
}
@PathPatternsParameterizedTest
@ -389,7 +389,7 @@ class CrossOriginTests {
assertThat(chain).isNotNull();
if (isPreFlightRequest) {
Object handler = chain.getHandler();
assertThat(handler.getClass().getSimpleName().equals("PreFlightHandler")).isTrue();
assertThat(handler.getClass().getSimpleName()).isEqualTo("PreFlightHandler");
DirectFieldAccessor accessor = new DirectFieldAccessor(handler);
return (CorsConfiguration)accessor.getPropertyValue("config");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rossen Stoyanchev
* @since 3.1
*/
public class RedirectAttributesModelMapTests {
class RedirectAttributesModelMapTests {
private RedirectAttributesModelMap redirectAttributes;
@ -54,13 +54,13 @@ public class RedirectAttributesModelMapTests {
}
@Test
public void addAttributePrimitiveType() {
void addAttributePrimitiveType() {
this.redirectAttributes.addAttribute("speed", 65);
assertThat(this.redirectAttributes.get("speed")).isEqualTo("65");
}
@Test
public void addAttributeCustomType() {
void addAttributeCustomType() {
String attrName = "person";
this.redirectAttributes.addAttribute(attrName, new TestBean("Fred"));
@ -73,7 +73,7 @@ public class RedirectAttributesModelMapTests {
}
@Test
public void addAttributeToString() {
void addAttributeToString() {
String attrName = "person";
RedirectAttributesModelMap model = new RedirectAttributesModelMap();
model.addAttribute(attrName, new TestBean("Fred"));
@ -82,22 +82,22 @@ public class RedirectAttributesModelMapTests {
}
@Test
public void addAttributeValue() {
void addAttributeValue() {
this.redirectAttributes.addAttribute(new TestBean("Fred"));
assertThat(this.redirectAttributes.get("testBean")).isEqualTo("Fred");
}
@Test
public void addAllAttributesList() {
this.redirectAttributes.addAllAttributes(Arrays.asList(new TestBean("Fred"), new Integer(5)));
void addAllAttributesList() {
this.redirectAttributes.addAllAttributes(Arrays.asList(new TestBean("Fred"), 5));
assertThat(this.redirectAttributes.get("testBean")).isEqualTo("Fred");
assertThat(this.redirectAttributes.get("integer")).isEqualTo("5");
}
@Test
public void addAttributesMap() {
void addAttributesMap() {
Map<String, Object> map = new HashMap<>();
map.put("person", new TestBean("Fred"));
map.put("age", 33);
@ -108,7 +108,7 @@ public class RedirectAttributesModelMapTests {
}
@Test
public void mergeAttributes() {
void mergeAttributes() {
Map<String, Object> map = new HashMap<>();
map.put("person", new TestBean("Fred"));
map.put("age", 33);
@ -121,14 +121,14 @@ public class RedirectAttributesModelMapTests {
}
@Test
public void put() {
void put() {
this.redirectAttributes.put("testBean", new TestBean("Fred"));
assertThat(this.redirectAttributes.get("testBean")).isEqualTo("Fred");
}
@Test
public void putAll() {
void putAll() {
Map<String, Object> map = new HashMap<>();
map.put("person", new TestBean("Fred"));
map.put("age", 33);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -50,10 +50,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Alef Arendsen
* @author Mark Fisher
*/
public class BindTagTests extends AbstractTagTests {
class BindTagTests extends AbstractTagTests {
@Test
public void bindTagWithoutErrors() throws JspException {
void bindTagWithoutErrors() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
@ -76,7 +76,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithGlobalErrors() throws JspException {
void bindTagWithGlobalErrors() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
errors.reject("code1", "message1");
@ -116,7 +116,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithGlobalErrorsAndNoDefaultMessage() throws JspException {
void bindTagWithGlobalErrorsAndNoDefaultMessage() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
errors.reject("code1");
@ -150,7 +150,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithGlobalErrorsAndDefaultMessageOnly() throws JspException {
void bindTagWithGlobalErrorsAndDefaultMessageOnly() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
errors.reject(null, "message1");
@ -186,7 +186,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindStatusGetErrorMessagesAsString() throws JspException {
void bindStatusGetErrorMessagesAsString() throws JspException {
// one error (should not include delimiter)
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
@ -225,7 +225,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithFieldErrors() throws JspException {
void bindTagWithFieldErrors() throws JspException {
PageContext pc = createPageContext();
TestBean tb = new TestBean();
tb.setName("name1");
@ -263,7 +263,7 @@ public class BindTagTests extends AbstractTagTests {
status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat("age".equals(status.getExpression())).as("Correct expression").isTrue();
assertThat(new Integer(0).equals(status.getValue())).as("Correct value").isTrue();
assertThat(Integer.valueOf(0).equals(status.getValue())).as("Correct value").isTrue();
assertThat("0".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorCodes().length == 1).as("Correct errorCodes").isTrue();
@ -295,7 +295,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithFieldErrorsAndNoDefaultMessage() throws JspException {
void bindTagWithFieldErrorsAndNoDefaultMessage() throws JspException {
PageContext pc = createPageContext();
TestBean tb = new TestBean();
tb.setName("name1");
@ -328,7 +328,7 @@ public class BindTagTests extends AbstractTagTests {
status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat("age".equals(status.getExpression())).as("Correct expression").isTrue();
assertThat(new Integer(0).equals(status.getValue())).as("Correct value").isTrue();
assertThat(Integer.valueOf(0).equals(status.getValue())).as("Correct value").isTrue();
assertThat("0".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorCodes().length == 1).as("Correct errorCodes").isTrue();
@ -352,7 +352,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithFieldErrorsAndDefaultMessageOnly() throws JspException {
void bindTagWithFieldErrorsAndDefaultMessageOnly() throws JspException {
PageContext pc = createPageContext();
TestBean tb = new TestBean();
tb.setName("name1");
@ -386,7 +386,7 @@ public class BindTagTests extends AbstractTagTests {
status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat("age".equals(status.getExpression())).as("Correct expression").isTrue();
assertThat(new Integer(0).equals(status.getValue())).as("Correct value").isTrue();
assertThat(Integer.valueOf(0).equals(status.getValue())).as("Correct value").isTrue();
assertThat("0".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorMessages().length == 1).as("Correct errorMessages").isTrue();
@ -411,7 +411,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithNestedFieldErrors() throws JspException {
void bindTagWithNestedFieldErrors() throws JspException {
PageContext pc = createPageContext();
TestBean tb = new TestBean();
tb.setName("name1");
@ -439,7 +439,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void propertyExposing() throws JspException {
void propertyExposing() throws JspException {
PageContext pc = createPageContext();
TestBean tb = new TestBean();
tb.setName("name1");
@ -464,7 +464,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithIndexedProperties() throws JspException {
void bindTagWithIndexedProperties() throws JspException {
PageContext pc = createPageContext();
IndexedTestBean tb = new IndexedTestBean();
Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
@ -492,7 +492,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithMappedProperties() throws JspException {
void bindTagWithMappedProperties() throws JspException {
PageContext pc = createPageContext();
IndexedTestBean tb = new IndexedTestBean();
Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
@ -520,7 +520,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithIndexedPropertiesAndCustomEditor() throws JspException {
void bindTagWithIndexedPropertiesAndCustomEditor() throws JspException {
PageContext pc = createPageContext();
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new ServletRequestDataBinder(tb, "tb");
@ -549,7 +549,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithToStringAndHtmlEscaping() throws JspException {
void bindTagWithToStringAndHtmlEscaping() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
@ -568,7 +568,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithSetValueAndHtmlEscaping() throws JspException {
void bindTagWithSetValueAndHtmlEscaping() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
@ -583,7 +583,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithFieldButWithoutErrorsInstance() throws JspException {
void bindTagWithFieldButWithoutErrorsInstance() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
@ -596,7 +596,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithFieldButWithoutErrorsInstanceAndHtmlEscaping() throws JspException {
void bindTagWithFieldButWithoutErrorsInstanceAndHtmlEscaping() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
@ -610,7 +610,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithBeanButWithoutErrorsInstance() throws JspException {
void bindTagWithBeanButWithoutErrorsInstance() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
@ -623,7 +623,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindTagWithoutBean() throws JspException {
void bindTagWithoutBean() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
@ -634,7 +634,7 @@ public class BindTagTests extends AbstractTagTests {
@Test
public void bindErrorsTagWithoutErrors() throws JspException {
void bindErrorsTagWithoutErrors() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
@ -646,7 +646,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindErrorsTagWithErrors() throws JspException {
void bindErrorsTagWithErrors() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
errors.reject("test", null, "test");
@ -659,7 +659,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void bindErrorsTagWithoutBean() throws JspException {
void bindErrorsTagWithoutBean() throws JspException {
PageContext pc = createPageContext();
BindErrorsTag tag = new BindErrorsTag();
tag.setPageContext(pc);
@ -669,7 +669,7 @@ public class BindTagTests extends AbstractTagTests {
@Test
public void nestedPathDoEndTag() throws JspException {
void nestedPathDoEndTag() throws JspException {
PageContext pc = createPageContext();
NestedPathTag tag = new NestedPathTag();
tag.setPath("foo");
@ -681,7 +681,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void nestedPathDoEndTagWithNesting() throws JspException {
void nestedPathDoEndTagWithNesting() throws JspException {
PageContext pc = createPageContext();
NestedPathTag tag = new NestedPathTag();
tag.setPath("foo");
@ -701,7 +701,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void nestedPathDoStartTagInternal() throws JspException {
void nestedPathDoStartTagInternal() throws JspException {
PageContext pc = createPageContext();
NestedPathTag tag = new NestedPathTag();
tag.setPath("foo");
@ -713,7 +713,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void nestedPathDoStartTagInternalWithNesting() throws JspException {
void nestedPathDoStartTagInternalWithNesting() throws JspException {
PageContext pc = createPageContext();
NestedPathTag tag = new NestedPathTag();
tag.setPath("foo");
@ -746,7 +746,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void nestedPathWithBindTag() throws JspException {
void nestedPathWithBindTag() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
@ -788,7 +788,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void nestedPathWithBindTagWithIgnoreNestedPath() throws JspException {
void nestedPathWithBindTagWithIgnoreNestedPath() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb2").getBindingResult();
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb2", errors);
@ -810,7 +810,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void transformTagCorrectBehavior() throws JspException {
void transformTagCorrectBehavior() throws JspException {
// first set up the pagecontext and the bean
PageContext pc = createPageContext();
TestBean tb = new TestBean();
@ -855,7 +855,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void transformTagWithHtmlEscape() throws JspException {
void transformTagWithHtmlEscape() throws JspException {
// first set up the PageContext and the bean
PageContext pc = createPageContext();
TestBean tb = new TestBean();
@ -884,7 +884,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void transformTagOutsideBindTag() throws JspException {
void transformTagOutsideBindTag() throws JspException {
// first set up the pagecontext and the bean
PageContext pc = createPageContext();
TestBean tb = new TestBean();
@ -915,7 +915,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void transformTagNonExistingValue() throws JspException {
void transformTagNonExistingValue() throws JspException {
// first set up the pagecontext and the bean
PageContext pc = createPageContext();
TestBean tb = new TestBean();
@ -942,7 +942,7 @@ public class BindTagTests extends AbstractTagTests {
}
@Test
public void transformTagWithSettingOfScope() throws JspException {
void transformTagWithSettingOfScope() throws JspException {
// first set up the pagecontext and the bean
PageContext pc = createPageContext();
TestBean tb = new TestBean();
@ -997,7 +997,7 @@ public class BindTagTests extends AbstractTagTests {
*/
@SuppressWarnings("serial")
@Test
public void nestingInFormTag() throws JspException {
void nestingInFormTag() throws JspException {
PageContext pc = createPageContext();
TestBean tb = new TestBean();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -49,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @author Jeremy Grelle
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class CheckboxTagTests extends AbstractFormTagTests {
class CheckboxTagTests extends AbstractFormTagTests {
private CheckboxTag tag;
@ -68,7 +68,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withSingleValueBooleanObjectChecked() throws Exception {
void withSingleValueBooleanObjectChecked() throws Exception {
this.tag.setPath("someBoolean");
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
@ -91,7 +91,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withIndexedBooleanObjectNotChecked() throws Exception {
void withIndexedBooleanObjectNotChecked() throws Exception {
this.tag.setPath("someMap[key]");
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
@ -114,7 +114,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withSingleValueBooleanObjectCheckedAndDynamicAttributes() throws Exception {
void withSingleValueBooleanObjectCheckedAndDynamicAttributes() throws Exception {
String dynamicAttribute1 = "attr1";
String dynamicAttribute2 = "attr2";
@ -144,7 +144,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withSingleValueBooleanChecked() throws Exception {
void withSingleValueBooleanChecked() throws Exception {
this.tag.setPath("jedi");
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
@ -164,7 +164,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withSingleValueBooleanObjectUnchecked() throws Exception {
void withSingleValueBooleanObjectUnchecked() throws Exception {
this.bean.setSomeBoolean(Boolean.FALSE);
this.tag.setPath("someBoolean");
int result = this.tag.doStartTag();
@ -186,7 +186,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withSingleValueBooleanUnchecked() throws Exception {
void withSingleValueBooleanUnchecked() throws Exception {
this.bean.setJedi(false);
this.tag.setPath("jedi");
int result = this.tag.doStartTag();
@ -208,7 +208,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withSingleValueNull() throws Exception {
void withSingleValueNull() throws Exception {
this.bean.setName(null);
this.tag.setPath("name");
this.tag.setValue("Rob Harrop");
@ -231,7 +231,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withSingleValueNotNull() throws Exception {
void withSingleValueNotNull() throws Exception {
this.bean.setName("Rob Harrop");
this.tag.setPath("name");
this.tag.setValue("Rob Harrop");
@ -254,7 +254,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withSingleValueAndEditor() throws Exception {
void withSingleValueAndEditor() throws Exception {
this.bean.setName("Rob Harrop");
this.tag.setPath("name");
this.tag.setValue(" Rob Harrop");
@ -281,7 +281,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withMultiValueChecked() throws Exception {
void withMultiValueChecked() throws Exception {
this.tag.setPath("stringArray");
this.tag.setValue("foo");
int result = this.tag.doStartTag();
@ -303,7 +303,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withMultiValueUnchecked() throws Exception {
void withMultiValueUnchecked() throws Exception {
this.tag.setPath("stringArray");
this.tag.setValue("abc");
int result = this.tag.doStartTag();
@ -325,7 +325,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withMultiValueWithEditor() throws Exception {
void withMultiValueWithEditor() throws Exception {
this.tag.setPath("stringArray");
this.tag.setValue(" foo");
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
@ -353,7 +353,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withMultiValueIntegerWithEditor() throws Exception {
void withMultiValueIntegerWithEditor() throws Exception {
this.tag.setPath("someIntegerArray");
this.tag.setValue(" 1");
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
@ -381,7 +381,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withCollection() throws Exception {
void withCollection() throws Exception {
this.tag.setPath("someList");
this.tag.setValue("foo");
int result = this.tag.doStartTag();
@ -403,7 +403,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withObjectChecked() throws Exception {
void withObjectChecked() throws Exception {
this.tag.setPath("date");
this.tag.setValue(getDate());
@ -426,7 +426,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withObjectUnchecked() throws Exception {
void withObjectUnchecked() throws Exception {
this.tag.setPath("date");
Date date = new Date();
this.tag.setValue(date);
@ -450,7 +450,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void collectionOfColoursSelected() throws Exception {
void collectionOfColoursSelected() throws Exception {
this.tag.setPath("otherColours");
this.tag.setValue("RED");
@ -472,7 +472,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void collectionOfColoursNotSelected() throws Exception {
void collectionOfColoursNotSelected() throws Exception {
this.tag.setPath("otherColours");
this.tag.setValue("PURPLE");
@ -494,7 +494,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void collectionOfPetsAsString() throws Exception {
void collectionOfPetsAsString() throws Exception {
this.tag.setPath("pets");
this.tag.setValue("Spot");
@ -516,7 +516,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void collectionOfPetsAsStringNotSelected() throws Exception {
void collectionOfPetsAsStringNotSelected() throws Exception {
this.tag.setPath("pets");
this.tag.setValue("Santa's Little Helper");
@ -538,7 +538,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void collectionOfPets() throws Exception {
void collectionOfPets() throws Exception {
this.tag.setPath("pets");
this.tag.setValue(new Pet("Rudiger"));
@ -561,7 +561,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void collectionOfPetsNotSelected() throws Exception {
void collectionOfPetsNotSelected() throws Exception {
this.tag.setPath("pets");
this.tag.setValue(new Pet("Santa's Little Helper"));
@ -584,7 +584,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void collectionOfPetsWithEditor() throws Exception {
void collectionOfPetsWithEditor() throws Exception {
this.tag.setPath("pets");
this.tag.setValue(new ItemPet("Rudiger"));
@ -612,14 +612,14 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void withNullValue() throws Exception {
void withNullValue() throws Exception {
this.tag.setPath("name");
assertThatIllegalArgumentException().as("null value binding to a non-boolean").isThrownBy(
this.tag::doStartTag);
}
@Test
public void hiddenElementOmittedOnDisabled() throws Exception {
void hiddenElementOmittedOnDisabled() throws Exception {
this.tag.setPath("someBoolean");
this.tag.setDisabled(true);
int result = this.tag.doStartTag();
@ -642,7 +642,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
}
@Test
public void dynamicTypeAttribute() throws JspException {
void dynamicTypeAttribute() throws JspException {
assertThatIllegalArgumentException().isThrownBy(() ->
this.tag.setDynamicAttribute(null, "type", "email"))
.withMessage("Attribute type=\"email\" is not allowed");
@ -718,7 +718,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
@Override
public void setAsText(String text) {
this.count++;
setValue(new Integer(text.trim()));
setValue(Integer.valueOf(text.trim()));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
/**
* @author Rob Harrop
*/
public class HiddenInputTagTests extends AbstractFormTagTests {
class HiddenInputTagTests extends AbstractFormTagTests {
private HiddenInputTag tag;
@ -49,7 +49,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
}
@Test
public void render() throws Exception {
void render() throws Exception {
this.tag.setPath("name");
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
@ -65,7 +65,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
}
@Test
public void withCustomBinder() throws Exception {
void withCustomBinder() throws Exception {
this.tag.setPath("myFloat");
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
@ -84,14 +84,14 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
}
@Test
public void dynamicTypeAttribute() throws JspException {
void dynamicTypeAttribute() throws JspException {
assertThatIllegalArgumentException().isThrownBy(() ->
this.tag.setDynamicAttribute(null, "type", "email"))
.withMessage("Attribute type=\"email\" is not allowed");
}
@Test
public void disabledTrue() throws Exception {
void disabledTrue() throws Exception {
this.tag.setDisabled(true);
this.tag.doStartTag();
@ -107,7 +107,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
// SPR-8661
@Test
public void disabledFalse() throws Exception {
void disabledFalse() throws Exception {
this.tag.setDisabled(false);
this.tag.doStartTag();
@ -132,7 +132,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
protected TestBean createTestBean() {
this.bean = new TestBean();
bean.setName("Sally Greenwood");
bean.setMyFloat(new Float("12.34"));
bean.setMyFloat(Float.valueOf("12.34"));
return bean;
}

View File

@ -56,7 +56,7 @@ public class InputTagTests extends AbstractFormTagTests {
// set up test data
this.rob = new TestBean();
this.rob.setName("Rob");
this.rob.setMyFloat(new Float(12.34));
this.rob.setMyFloat(Float.valueOf(12.34f));
TestBean sally = new TestBean();
sally.setName("Sally");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -46,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Jeremy Grelle
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class OptionTagTests extends AbstractHtmlElementTagTests {
class OptionTagTests extends AbstractHtmlElementTagTests {
private static final String ARRAY_SOURCE = "abc,123,def";
@ -79,7 +79,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
@Test
public void canBeDisabledEvenWhenSelected() throws Exception {
void canBeDisabledEvenWhenSelected() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
@ -101,7 +101,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void renderNotSelected() throws Exception {
void renderNotSelected() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
@ -121,7 +121,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void renderWithDynamicAttributes() throws Exception {
void renderWithDynamicAttributes() throws Exception {
String dynamicAttribute1 = "attr1";
String dynamicAttribute2 = "attr2";
@ -149,7 +149,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void renderSelected() throws Exception {
void renderSelected() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
@ -172,7 +172,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withNoLabel() throws Exception {
void withNoLabel() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
@ -195,7 +195,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withoutContext() throws Exception {
void withoutContext() throws Exception {
this.tag.setParent(null);
this.tag.setValue("foo");
this.tag.setLabel("Foo");
@ -204,7 +204,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withPropertyEditor() throws Exception {
void withPropertyEditor() throws Exception {
String selectName = "testBean.stringArray";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@Override
@ -233,7 +233,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withPropertyEditorStringComparison() throws Exception {
void withPropertyEditorStringComparison() throws Exception {
final PropertyEditor testBeanEditor = new TestBeanPropertyEditor();
testBeanEditor.setValue(new TestBean("Sally"));
String selectName = "testBean.spouse";
@ -261,11 +261,11 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withCustomObjectSelected() throws Exception {
void withCustomObjectSelected() throws Exception {
String selectName = "testBean.someNumber";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue(new Float(12.34));
this.tag.setValue(12.34f);
this.tag.setLabel("GBP 12.34");
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(BodyTag.EVAL_BODY_BUFFERED);
@ -282,11 +282,11 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withCustomObjectNotSelected() throws Exception {
void withCustomObjectNotSelected() throws Exception {
String selectName = "testBean.someNumber";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue(new Float(12.35));
this.tag.setValue(12.35f);
this.tag.setLabel("GBP 12.35");
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(BodyTag.EVAL_BODY_BUFFERED);
@ -303,9 +303,9 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withCustomObjectAndEditorSelected() throws Exception {
void withCustomObjectAndEditorSelected() throws Exception {
final PropertyEditor floatEditor = new SimpleFloatEditor();
floatEditor.setValue(new Float("12.34"));
floatEditor.setValue(Float.valueOf("12.34"));
String selectName = "testBean.someNumber";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@Override
@ -315,7 +315,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue(new Float(12.34));
this.tag.setValue(12.34f);
this.tag.setLabel("12.34f");
int result = this.tag.doStartTag();
@ -331,7 +331,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withCustomObjectAndEditorNotSelected() throws Exception {
void withCustomObjectAndEditorNotSelected() throws Exception {
final PropertyEditor floatEditor = new SimpleFloatEditor();
String selectName = "testBean.someNumber";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@ -342,7 +342,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue(new Float(12.35));
this.tag.setValue(12.35f);
this.tag.setLabel("12.35f");
int result = this.tag.doStartTag();
@ -358,7 +358,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void asBodyTag() throws Exception {
void asBodyTag() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
@ -380,7 +380,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void asBodyTagSelected() throws Exception {
void asBodyTagSelected() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
@ -401,7 +401,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void asBodyTagCollapsed() throws Exception {
void asBodyTagCollapsed() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
@ -423,7 +423,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void asBodyTagWithEditor() throws Exception {
void asBodyTagWithEditor() throws Exception {
String selectName = "testBean.stringArray";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@Override
@ -447,7 +447,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void multiBind() throws Exception {
void multiBind() throws Exception {
BeanPropertyBindingResult result = new BeanPropertyBindingResult(new TestBean(), "testBean");
result.getPropertyAccessor().registerCustomEditor(TestBean.class, "friends", new FriendEditor());
exposeBindingResult(result);
@ -463,7 +463,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void optionTagNotNestedWithinSelectTag() throws Exception {
void optionTagNotNestedWithinSelectTag() throws Exception {
tag.setParent(null);
tag.setValue("foo");
assertThatIllegalStateException().as("when not nested within a <select/> tag").isThrownBy(
@ -486,7 +486,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
bean.setFavouriteColour(Colour.GREEN);
bean.setStringArray(ARRAY);
bean.setSpouse(new TestBean("Sally"));
bean.setSomeNumber(new Float("12.34"));
bean.setSomeNumber(Float.valueOf("12.34"));
List friends = new ArrayList();
friends.add(new TestBean("bar"));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -53,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Jeremy Grelle
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class OptionsTagTests extends AbstractHtmlElementTagTests {
class OptionsTagTests extends AbstractHtmlElementTagTests {
private static final String COMMAND_NAME = "testBean";
@ -87,7 +87,7 @@ public class OptionsTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withCollection() throws Exception {
void withCollection() throws Exception {
getPageContext().setAttribute(
SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false));
@ -117,7 +117,7 @@ public class OptionsTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withCollectionAndDynamicAttributes() throws Exception {
void withCollectionAndDynamicAttributes() throws Exception {
String dynamicAttribute1 = "attr1";
String dynamicAttribute2 = "attr2";
@ -155,11 +155,11 @@ public class OptionsTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withCollectionAndCustomEditor() throws Exception {
void withCollectionAndCustomEditor() throws Exception {
PropertyEditor propertyEditor = new SimpleFloatEditor();
TestBean target = new TestBean();
target.setMyFloat(new Float("12.34"));
target.setMyFloat(Float.valueOf("12.34"));
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
errors.getPropertyAccessor().registerCustomEditor(Float.class, propertyEditor);
@ -169,12 +169,12 @@ public class OptionsTagTests extends AbstractHtmlElementTagTests {
SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.myFloat", false));
List<Float> floats = new ArrayList<>();
floats.add(new Float("12.30"));
floats.add(new Float("12.31"));
floats.add(new Float("12.32"));
floats.add(new Float("12.33"));
floats.add(new Float("12.34"));
floats.add(new Float("12.35"));
floats.add(Float.valueOf("12.30"));
floats.add(Float.valueOf("12.31"));
floats.add(Float.valueOf("12.32"));
floats.add(Float.valueOf("12.33"));
floats.add(Float.valueOf("12.34"));
floats.add(Float.valueOf("12.35"));
this.tag.setItems(floats);
int result = this.tag.doStartTag();
@ -201,7 +201,7 @@ public class OptionsTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withItemsNullReference() throws Exception {
void withItemsNullReference() throws Exception {
getPageContext().setAttribute(
SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false));
@ -222,7 +222,7 @@ public class OptionsTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withoutItems() throws Exception {
void withoutItems() throws Exception {
this.tag.setItemValue("isoCode");
this.tag.setItemLabel("name");
this.selectTag.setPath("testBean");
@ -243,7 +243,7 @@ public class OptionsTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withoutItemsEnumParent() throws Exception {
void withoutItemsEnumParent() throws Exception {
BeanWithEnum testBean = new BeanWithEnum();
testBean.setTestEnum(TestEnum.VALUE_2);
getPageContext().getRequest().setAttribute("testBean", testBean);
@ -271,7 +271,7 @@ public class OptionsTagTests extends AbstractHtmlElementTagTests {
}
@Test
public void withoutItemsEnumParentWithExplicitLabelsAndValues() throws Exception {
void withoutItemsEnumParentWithExplicitLabelsAndValues() throws Exception {
BeanWithEnum testBean = new BeanWithEnum();
testBean.setTestEnum(TestEnum.VALUE_2);
getPageContext().getRequest().setAttribute("testBean", testBean);
@ -305,16 +305,16 @@ public class OptionsTagTests extends AbstractHtmlElementTagTests {
TestBean bean = new TestBean();
bean.setName("foo");
bean.setCountry("UK");
bean.setMyFloat(new Float("12.34"));
bean.setMyFloat(Float.valueOf("12.34"));
request.setAttribute(COMMAND_NAME, bean);
List floats = new ArrayList();
floats.add(new Float("12.30"));
floats.add(new Float("12.31"));
floats.add(new Float("12.32"));
floats.add(new Float("12.33"));
floats.add(new Float("12.34"));
floats.add(new Float("12.35"));
floats.add(Float.valueOf("12.30"));
floats.add(Float.valueOf("12.31"));
floats.add(Float.valueOf("12.32"));
floats.add(Float.valueOf("12.33"));
floats.add(Float.valueOf("12.34"));
floats.add(Float.valueOf("12.35"));
request.setAttribute("floats", floats);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @author Juergen Hoeller
* @author Jeremy Grelle
*/
public class RadioButtonTagTests extends AbstractFormTagTests {
class RadioButtonTagTests extends AbstractFormTagTests {
private RadioButtonTag tag;
@ -60,7 +60,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
@Test
public void withCheckedValue() throws Exception {
void withCheckedValue() throws Exception {
String dynamicAttribute1 = "attr1";
String dynamicAttribute2 = "attr2";
@ -84,7 +84,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
@Test
public void withCheckedValueAndDynamicAttributes() throws Exception {
void withCheckedValueAndDynamicAttributes() throws Exception {
this.tag.setPath("sex");
this.tag.setValue("M");
int result = this.tag.doStartTag();
@ -100,7 +100,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
@Test
public void withCheckedObjectValue() throws Exception {
void withCheckedObjectValue() throws Exception {
this.tag.setPath("myFloat");
this.tag.setValue(getFloat());
int result = this.tag.doStartTag();
@ -116,7 +116,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
@Test
public void withCheckedObjectValueAndEditor() throws Exception {
void withCheckedObjectValueAndEditor() throws Exception {
this.tag.setPath("myFloat");
this.tag.setValue("F12.99");
@ -138,8 +138,8 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
@Test
public void withUncheckedObjectValue() throws Exception {
Float value = new Float("99.45");
void withUncheckedObjectValue() throws Exception {
Float value = Float.valueOf("99.45");
this.tag.setPath("myFloat");
this.tag.setValue(value);
int result = this.tag.doStartTag();
@ -155,7 +155,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
@Test
public void withUncheckedValue() throws Exception {
void withUncheckedValue() throws Exception {
this.tag.setPath("sex");
this.tag.setValue("F");
int result = this.tag.doStartTag();
@ -171,7 +171,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
@Test
public void collectionOfPets() throws Exception {
void collectionOfPets() throws Exception {
this.tag.setPath("pets");
this.tag.setValue(new Pet("Rudiger"));
@ -194,7 +194,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
@Test
public void collectionOfPetsNotSelected() throws Exception {
void collectionOfPetsNotSelected() throws Exception {
this.tag.setPath("pets");
this.tag.setValue(new Pet("Santa's Little Helper"));
@ -217,7 +217,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
@Test
public void collectionOfPetsWithEditor() throws Exception {
void collectionOfPetsWithEditor() throws Exception {
this.tag.setPath("pets");
this.tag.setValue(new ItemPet("Rudiger"));
@ -245,7 +245,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
@Test
public void dynamicTypeAttribute() throws JspException {
void dynamicTypeAttribute() throws JspException {
assertThatIllegalArgumentException().isThrownBy(() ->
this.tag.setDynamicAttribute(null, "type", "email"))
.withMessage("Attribute type=\"email\" is not allowed");
@ -260,7 +260,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
}
private Float getFloat() {
return new Float("12.99");
return Float.valueOf("12.99");
}
@Override

View File

@ -429,9 +429,9 @@ public class SelectTagTests extends AbstractFormTagTests {
this.tag.setPath("myFloat");
Float[] array = new Float[] {
new Float("12.30"), new Float("12.32"), new Float("12.34"), new Float("12.36"),
new Float("12.38"), new Float("12.40"), new Float("12.42"), new Float("12.44"),
new Float("12.46"), new Float("12.48")
Float.valueOf("12.30"), Float.valueOf("12.32"), Float.valueOf("12.34"), Float.valueOf("12.36"),
Float.valueOf("12.38"), Float.valueOf("12.40"), Float.valueOf("12.42"), Float.valueOf("12.44"),
Float.valueOf("12.46"), Float.valueOf("12.48")
};
this.tag.setItems(array);
@ -1010,7 +1010,7 @@ public class SelectTagTests extends AbstractFormTagTests {
this.bean.setName("Rob");
this.bean.setCountry("UK");
this.bean.setSex("M");
this.bean.setMyFloat(new Float("12.34"));
this.bean.setMyFloat(Float.valueOf("12.34"));
this.bean.setSomeIntegerArray(new Integer[]{12, 34});
return this.bean;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2021 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.
@ -26,7 +26,7 @@ class SimpleFloatEditor extends PropertyEditorSupport {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(new Float(text));
setValue(Float.valueOf(text));
}
@Override

View File

@ -136,7 +136,7 @@ public class TextareaTagTests extends AbstractFormTagTests {
// set up test data
this.rob = new TestBean();
rob.setName("Rob");
rob.setMyFloat(new Float(12.34));
rob.setMyFloat(12.34f);
TestBean sally = new TestBean();
sally.setName("Sally");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@ -33,7 +33,7 @@ import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
public class RedirectViewUriTemplateTests {
class RedirectViewUriTemplateTests {
private MockHttpServletRequest request;
@ -48,7 +48,7 @@ public class RedirectViewUriTemplateTests {
}
@Test
public void uriTemplate() throws Exception {
void uriTemplate() throws Exception {
Map<String, Object> model = new HashMap<>();
model.put("foo", "bar");
@ -60,7 +60,7 @@ public class RedirectViewUriTemplateTests {
}
@Test
public void uriTemplateEncode() throws Exception {
void uriTemplateEncode() throws Exception {
Map<String, Object> model = new HashMap<>();
model.put("foo", "bar/bar baz");
@ -72,7 +72,7 @@ public class RedirectViewUriTemplateTests {
}
@Test
public void uriTemplateAndArrayQueryParam() throws Exception {
void uriTemplateAndArrayQueryParam() throws Exception {
Map<String, Object> model = new HashMap<>();
model.put("foo", "bar");
model.put("fooArr", new String[] { "baz", "bazz" });
@ -84,9 +84,9 @@ public class RedirectViewUriTemplateTests {
}
@Test
public void uriTemplateWithObjectConversion() throws Exception {
void uriTemplateWithObjectConversion() throws Exception {
Map<String, Object> model = new HashMap<>();
model.put("foo", new Long(611));
model.put("foo", 611L);
RedirectView redirectView = new RedirectView("/foo/{foo}");
redirectView.renderMergedOutputModel(model, this.request, this.response);
@ -95,7 +95,7 @@ public class RedirectViewUriTemplateTests {
}
@Test
public void uriTemplateReuseCurrentRequestVars() throws Exception {
void uriTemplateReuseCurrentRequestVars() throws Exception {
Map<String, Object> model = new HashMap<>();
model.put("key1", "value1");
model.put("name", "value2");
@ -115,25 +115,25 @@ public class RedirectViewUriTemplateTests {
}
@Test
public void uriTemplateNullValue() throws Exception {
void uriTemplateNullValue() throws Exception {
assertThatIllegalArgumentException().isThrownBy(() ->
new RedirectView("/{foo}").renderMergedOutputModel(new ModelMap(), this.request, this.response));
}
@Test
public void emptyRedirectString() throws Exception {
void emptyRedirectString() throws Exception {
Map<String, Object> model = new HashMap<>();
RedirectView redirectView = new RedirectView("");
redirectView.renderMergedOutputModel(model, this.request, this.response);
assertThat(this.response.getRedirectedUrl()).isEqualTo("");
assertThat(this.response.getRedirectedUrl()).isEmpty();
}
// SPR-9016
@Test
public void dontApplyUriVariables() throws Exception {
void dontApplyUriVariables() throws Exception {
String url = "/test#{'one','abc'}";
RedirectView redirectView = new RedirectView(url, true);
redirectView.setExpandUriTemplateVariables(false);