mirror of
https://github.com/lightbend/config.git
synced 2025-03-22 23:30:27 +08:00
Small modifications to some tests
This commit is contained in:
parent
909b11854b
commit
90dd9b960c
@ -838,7 +838,7 @@ final class SimpleConfig implements Config, MergeableValue, Serializable {
|
|||||||
}
|
}
|
||||||
} else if (referenceType == ConfigValueType.LIST) {
|
} else if (referenceType == ConfigValueType.LIST) {
|
||||||
// objects may be convertible to lists if they have numeric keys
|
// objects may be convertible to lists if they have numeric keys
|
||||||
// empty strings may also be converted to lists
|
// strings may also be convertible to lists if empty
|
||||||
if (value instanceof SimpleConfigList || value instanceof SimpleConfigObject || value instanceof ConfigString) {
|
if (value instanceof SimpleConfigList || value instanceof SimpleConfigObject || value instanceof ConfigString) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,6 +11,7 @@ import com.typesafe.config.ConfigValue;
|
|||||||
public class ArraysConfig {
|
public class ArraysConfig {
|
||||||
|
|
||||||
List<Integer> empty;
|
List<Integer> empty;
|
||||||
|
List<Integer> fromEmptyString;
|
||||||
List<Integer> ofInt;
|
List<Integer> ofInt;
|
||||||
List<String> ofString;
|
List<String> ofString;
|
||||||
List<Double> ofDouble;
|
List<Double> ofDouble;
|
||||||
@ -33,6 +34,10 @@ public class ArraysConfig {
|
|||||||
this.empty = empty;
|
this.empty = empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Integer> getFromEmptyString() { return fromEmptyString; }
|
||||||
|
|
||||||
|
public void setFromEmptyString(List<Integer> fromEmptyString) { this.fromEmptyString = fromEmptyString; }
|
||||||
|
|
||||||
public List<Integer> getOfInt() {
|
public List<Integer> getOfInt() {
|
||||||
return ofInt;
|
return ofInt;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
"arrays" : {
|
"arrays" : {
|
||||||
"empty" : [],
|
"empty" : [],
|
||||||
|
"fromEmptyString": "",
|
||||||
"ofInt" : [1, 2, 3],
|
"ofInt" : [1, 2, 3],
|
||||||
"ofString" : [ ${strings.a}, ${strings.b}, ${strings.c} ],
|
"ofString" : [ ${strings.a}, ${strings.b}, ${strings.c} ],
|
||||||
"of-double" : [3.14, 4.14, 5.14],
|
"of-double" : [3.14, 4.14, 5.14],
|
||||||
|
@ -48,8 +48,7 @@ class ConfigBeanFactoryTest extends TestUtils {
|
|||||||
|
|
||||||
val expecteds = Seq(Missing("propNotListedInConfig", 77, "string"),
|
val expecteds = Seq(Missing("propNotListedInConfig", 77, "string"),
|
||||||
WrongType("shouldBeInt", 78, "number", "boolean"),
|
WrongType("shouldBeInt", 78, "number", "boolean"),
|
||||||
WrongType("should-be-boolean", 79, "boolean", "number"),
|
WrongType("should-be-boolean", 79, "boolean", "number"))
|
||||||
WrongType("should-be-list", 80, "list", "string"))
|
|
||||||
|
|
||||||
checkValidationException(e, expecteds)
|
checkValidationException(e, expecteds)
|
||||||
}
|
}
|
||||||
@ -90,6 +89,7 @@ class ConfigBeanFactoryTest extends TestUtils {
|
|||||||
val beanConfig: ArraysConfig = ConfigBeanFactory.create(loadConfig().getConfig("arrays"), classOf[ArraysConfig])
|
val beanConfig: ArraysConfig = ConfigBeanFactory.create(loadConfig().getConfig("arrays"), classOf[ArraysConfig])
|
||||||
assertNotNull(beanConfig)
|
assertNotNull(beanConfig)
|
||||||
assertEquals(List().asJava, beanConfig.getEmpty)
|
assertEquals(List().asJava, beanConfig.getEmpty)
|
||||||
|
assertEquals(List().asJava, beanConfig.getFromEmptyString)
|
||||||
assertEquals(List(1, 2, 3).asJava, beanConfig.getOfInt)
|
assertEquals(List(1, 2, 3).asJava, beanConfig.getOfInt)
|
||||||
assertEquals(List(32L, 42L, 52L).asJava, beanConfig.getOfLong)
|
assertEquals(List(32L, 42L, 52L).asJava, beanConfig.getOfLong)
|
||||||
assertEquals(List("a", "b", "c").asJava, beanConfig.getOfString)
|
assertEquals(List("a", "b", "c").asJava, beanConfig.getOfString)
|
||||||
|
@ -673,6 +673,10 @@ class ConfigTest extends TestUtils {
|
|||||||
conf.getObjectList("arrays.ofInt")
|
conf.getObjectList("arrays.ofInt")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
intercept[ConfigException.WrongType] {
|
||||||
|
conf.getList("strings.abcd")
|
||||||
|
}
|
||||||
|
|
||||||
intercept[ConfigException.WrongType] {
|
intercept[ConfigException.WrongType] {
|
||||||
conf.getMilliseconds("ints")
|
conf.getMilliseconds("ints")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user