diff --git a/config/src/main/java/com/typesafe/config/ConfigValueFactory.java b/config/src/main/java/com/typesafe/config/ConfigValueFactory.java index e92bb772..d1f82e87 100644 --- a/config/src/main/java/com/typesafe/config/ConfigValueFactory.java +++ b/config/src/main/java/com/typesafe/config/ConfigValueFactory.java @@ -49,7 +49,13 @@ public final class ConfigValueFactory { * the one you unwrapped. The re-wrapped ConfigValue will lose some * information that was present in the original such as its origin, but it * will have matching values. - * + * + *
+ * If you pass in a ConfigValue
to this
+ * function, it will be returned unmodified. (The
+ * originDescription
will be ignored in this
+ * case.)
+ *
*
* This function throws if you supply a value that cannot be converted to a * ConfigValue, but supplying such a value is a bug in your program, so you diff --git a/config/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala b/config/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala index 8c962c56..444f13d8 100644 --- a/config/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala @@ -95,9 +95,17 @@ class PublicApiTest extends TestUtils { private def testFromValue(expectedValue: ConfigValue, createFrom: AnyRef) { assertEquals(expectedValue, ConfigValueFactory.fromAnyRef(createFrom)) - assertEquals(defaultValueDesc, ConfigValueFactory.fromAnyRef(createFrom).origin().description()) + assertEquals(expectedValue, ConfigValueFactory.fromAnyRef(createFrom, "foo")) - assertEquals("foo", ConfigValueFactory.fromAnyRef(createFrom, "foo").origin().description()) + + // description is ignored for createFrom that is already a ConfigValue + createFrom match { + case c: ConfigValue => + assertEquals(c.origin().description(), ConfigValueFactory.fromAnyRef(createFrom).origin().description()) + case _ => + assertEquals(defaultValueDesc, ConfigValueFactory.fromAnyRef(createFrom).origin().description()) + assertEquals("foo", ConfigValueFactory.fromAnyRef(createFrom, "foo").origin().description()) + } } @Test @@ -178,8 +186,29 @@ class PublicApiTest extends TestUtils { @Test def fromDuration() { - testFromValue(longValue(1000), Duration.ofMillis(1000)); - testFromValue(longValue(1000*60*60*24), Duration.ofDays(1)); + testFromValue(longValue(1000), Duration.ofMillis(1000)); + testFromValue(longValue(1000 * 60 * 60 * 24), Duration.ofDays(1)); + } + + @Test + def fromExistingConfigValue() { + testFromValue(longValue(1000), longValue(1000)); + testFromValue(stringValue("foo"), stringValue("foo")); + + val aMapValue = new SimpleConfigObject(fakeOrigin(), + Map("a" -> 1, "b" -> 2, "c" -> 3).mapValues(intValue(_): AbstractConfigValue).asJava) + + testFromValue(aMapValue, aMapValue) + } + + @Test + def fromExistingJavaListOfConfigValue() { + // you can mix "unwrapped" List with ConfigValue elements + val list = List(longValue(1), longValue(2), longValue(3)).asJava + testFromValue(new SimpleConfigList(fakeOrigin(), List(longValue(1): AbstractConfigValue, + longValue(2): AbstractConfigValue, + longValue(3): AbstractConfigValue).asJava), + list); } @Test