Polish tests
See gh-27248
This commit is contained in:
@@ -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();
|
||||
@@ -357,8 +357,7 @@ public abstract class AbstractPropertyAccessorTests {
|
||||
AbstractPropertyAccessor accessor = createAccessor(target);
|
||||
try {
|
||||
accessor.getPropertyValue("spouse.bla");
|
||||
}
|
||||
catch (NotReadablePropertyException ex) {
|
||||
} catch (NotReadablePropertyException ex) {
|
||||
assertThat(ex.getMessage().contains(TestBean.class.getName())).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -478,8 +477,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 +489,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 +499,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 +590,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 +615,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 +723,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 +736,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 +762,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 +835,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 +848,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,21 +909,21 @@ 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();
|
||||
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();
|
||||
target.intArray[2] == 2 && target.intArray[3] == 3).as("correct values").isTrue();
|
||||
|
||||
accessor.setPropertyValue("intArray", 1);
|
||||
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 +946,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 +966,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 +985,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,12 +997,12 @@ 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();
|
||||
target.getArray()[2] == 3).as("correct values").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1018,7 +1017,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 +1077,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 +1104,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 +1121,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 +1158,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 +1235,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");
|
||||
@@ -1268,7 +1267,7 @@ public abstract class AbstractPropertyAccessorTests {
|
||||
badValues.add("map[key2]", "");
|
||||
assertThatExceptionOfType(PropertyBatchUpdateException.class).isThrownBy(() ->
|
||||
accessor.setPropertyValues(badValues))
|
||||
.satisfies(ex -> assertThat(ex.getPropertyAccessException("map[key2]")).isInstanceOf(TypeMismatchException.class));
|
||||
.satisfies(ex -> assertThat(ex.getPropertyAccessException("map[key2]")).isInstanceOf(TypeMismatchException.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1319,7 +1318,7 @@ public abstract class AbstractPropertyAccessorTests {
|
||||
assertThat(((TestBean) target.getMap().get(2)).getName()).isEqualTo("rob");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" }) // must work with raw map in this test
|
||||
@SuppressWarnings({"unchecked", "rawtypes"}) // must work with raw map in this test
|
||||
@Test
|
||||
public void setRawMapPropertyWithNoEditorRegistered() {
|
||||
IndexedTestBean target = new IndexedTestBean();
|
||||
@@ -1527,7 +1526,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 +1537,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 +1581,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");
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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.
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.beans.propertyeditors;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.*;
|
||||
import org.springframework.beans.testfixture.beans.*;
|
||||
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.beans.PropertyVetoException;
|
||||
@@ -64,10 +68,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 +84,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 +104,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 +113,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 +131,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 +149,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 +168,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 +187,7 @@ public class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBooleanEditorForPrimitiveType() {
|
||||
void testDefaultBooleanEditorForPrimitiveType() {
|
||||
BooleanTestBean tb = new BooleanTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
||||
@@ -229,7 +233,7 @@ public class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBooleanEditorForWrapperType() {
|
||||
void testDefaultBooleanEditorForWrapperType() {
|
||||
BooleanTestBean tb = new BooleanTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
||||
@@ -239,28 +243,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 +272,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 +283,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 +337,7 @@ public class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultNumberEditor() {
|
||||
void testDefaultNumberEditor() {
|
||||
NumberTestBean tb = new NumberTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
||||
@@ -350,34 +354,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 +411,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 +447,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 +462,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 +479,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 +494,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 +502,7 @@ public class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharacterEditor() {
|
||||
void testCharacterEditor() {
|
||||
CharBean cb = new CharBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(cb);
|
||||
|
||||
@@ -520,78 +524,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 +606,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 +617,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 +625,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 +633,7 @@ public class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileEditorWithRelativePath() {
|
||||
void testFileEditorWithRelativePath() {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
try {
|
||||
fileEditor.setAsText("myfile.txt");
|
||||
@@ -641,7 +645,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 +660,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 +680,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 +700,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,76 +720,76 @@ 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);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
editor.setAsText(invalidDate))
|
||||
.withMessageContaining("10");
|
||||
.withMessageContaining("10");
|
||||
}
|
||||
|
||||
@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 +799,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 +816,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 +833,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 +848,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 +908,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 +975,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 +1060,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 +1144,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 +1195,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 +1249,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 +1336,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 +1354,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 +1371,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 +1387,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 +1403,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 +1412,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 +1430,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 +1445,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);
|
||||
|
||||
Reference in New Issue
Block a user