From 2bd30a49ad890c8f0d02550a7cecb12f41c1102b Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Wed, 23 Sep 2009 18:36:11 +0000 Subject: [PATCH] more tests --- .../core/convert/support/MapEntryConverter.java | 2 +- .../support/GenericConversionServiceTests.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapEntryConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapEntryConverter.java index e6b183154b..f2204715ef 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapEntryConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapEntryConverter.java @@ -38,7 +38,7 @@ class MapEntryConverter { if (this.valueConverter == null) { throw new ConverterNotFoundException(sourceValueType, targetValueType); } - this.targetKeyType = targetKeyType; + this.sourceValueType = sourceValueType; this.targetValueType = targetValueType; } } diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java index 61a5f3a577..2721b3efee 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java @@ -417,6 +417,21 @@ public class GenericConversionServiceTests { assertEquals(new Integer(3), result[0]); } + @Test + public void convertObjectToMap() { + Map result = conversionService.convert("foo=bar bar=baz", Map.class); + assertEquals("bar", result.get("foo")); + assertEquals("baz", result.get("bar")); + } + + @Test + public void convertObjectToMapWithConversion() throws Exception { + conversionService.addConverterFactory(new NumberToNumberConverterFactory()); + Map result = (Map) conversionService.convert(1L, TypeDescriptor.valueOf(Integer.class), new TypeDescriptor( + getClass().getField("genericMap2"))); + assertEquals(new Long(1), result.get(1L)); + } + @Test public void convertStringArrayToMap() { Map result = conversionService.convert(new String[] { "foo=bar", "bar=baz", "baz=boop" }, Map.class);