You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2012/03/17 21:10:47 UTC
svn commit: r1301990 - in /commons/proper/configuration/trunk/src: changes/
main/java/org/apache/commons/configuration/
test/java/org/apache/commons/configuration/
Author: oheger
Date: Sat Mar 17 20:10:46 2012
New Revision: 1301990
URL: http://svn.apache.org/viewvc?rev=1301990&view=rev
Log:
[CONFIGURATION-487] DataConfiguration.get() now also works for data types that do not require a type conversion.
Modified:
commons/proper/configuration/trunk/src/changes/changes.xml
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertyConverter.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDataConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertyConverter.java
Modified: commons/proper/configuration/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1301990&r1=1301989&r2=1301990&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/changes/changes.xml (original)
+++ commons/proper/configuration/trunk/src/changes/changes.xml Sat Mar 17 20:10:46 2012
@@ -27,6 +27,10 @@
<body>
<release version="1.9" date="in SVN"
description="TBD">
+ <action dev="oheger" type="fix" issue="CONFIGURATION-487">
+ DataConfiguration.get() now also works with String properties and if no
+ data type conversion is required.
+ </action>
<action dev="oheger" type="fix" issue="CONFIGURATION-481">
Variable substitution in configuration sources declared in a definition
file for DefaultConfigurationBuilder now works across multiple sources.
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertyConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertyConverter.java?rev=1301990&r1=1301989&r2=1301990&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertyConverter.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertyConverter.java Sat Mar 17 20:10:46 2012
@@ -97,6 +97,11 @@ public final class PropertyConverter
*/
static Object to(Class<?> cls, Object value, Object[] params) throws ConversionException
{
+ if (cls.isInstance(value))
+ {
+ return value; // no conversion needed
+ }
+
if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls))
{
return toBoolean(value);
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDataConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDataConfiguration.java?rev=1301990&r1=1301989&r2=1301990&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDataConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDataConfiguration.java Sat Mar 17 20:10:46 2012
@@ -2386,4 +2386,17 @@ public class TestDataConfiguration
// expected
}
}
+
+ /**
+ * Tests whether a string property can be obtained through get() if no type
+ * conversion is required.
+ */
+ @Test
+ public void testGetPropertyWithoutConversion()
+ {
+ String key = "test.str";
+ String value = "someTestValue";
+ conf.addProperty(key, value);
+ assertEquals("Wrong result", value, conf.get(String.class, key));
+ }
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertyConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertyConverter.java?rev=1301990&r1=1301989&r2=1301990&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertyConverter.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertyConverter.java Sat Mar 17 20:10:46 2012
@@ -338,4 +338,15 @@ public class TestPropertyConverter
{
PropertyConverter.toEnum(Integer.valueOf(-1), ENUM_CLASS);
}
+
+ /**
+ * Tests a trivial conversion: the value has already the desired type.
+ */
+ @Test
+ public void testToNoConversionNeeded()
+ {
+ String value = "testValue";
+ assertEquals("Wrong conversion result", value,
+ PropertyConverter.to(String.class, value, null));
+ }
}