Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/982#discussion_r214612451
--- Diff:
utils/common/src/test/java/org/apache/brooklyn/util/text/StringEscapesTest.java
---
@@ -115,4 +117,80 @@ public void testJavaLists() {
JavaStringEscapes.unwrapJsonishListIfPossible("\"\",,x,\"\""));
}
+ @Test
+ public void testJavaListString() {
+ Assert.assertEquals(MutableList.of("hello", "world"),
+ JavaStringEscapes.unwrapQuotedJavaStringList("\"hello\",
\"world\"", ","));
+ try {
+ JavaStringEscapes.unwrapQuotedJavaStringList("\"hello\",
world", ",");
+ Assert.fail("Should have thrown");
+ } catch (Exception e) { /* expected */ }
+
+ Assert.assertEquals(MutableList.of("hello", "world"),
+
JavaStringEscapes.unwrapJsonishListStringIfPossible("\"hello\", \"world\""));
+ Assert.assertEquals(MutableList.of("hello"),
+ JavaStringEscapes.unwrapJsonishListStringIfPossible("hello"));
+ Assert.assertEquals(MutableList.of("hello", "world"),
+ JavaStringEscapes.unwrapJsonishListStringIfPossible("hello,
world"));
+ Assert.assertEquals(MutableList.of("hello", "world"),
+
JavaStringEscapes.unwrapJsonishListStringIfPossible("\"hello\", world"));
+ Assert.assertEquals(MutableList.of("hello", "world"),
+ JavaStringEscapes.unwrapJsonishListStringIfPossible("[
\"hello\", world ]"));
+ // if can't parse e.g. because contains double quote, then returns
original string as single element list
+ Assert.assertEquals(MutableList.of("hello\", \"world\""),
+ JavaStringEscapes.unwrapJsonishListStringIfPossible("hello\",
\"world\""));
+ Assert.assertEquals(MutableList.of(),
+ JavaStringEscapes.unwrapJsonishListStringIfPossible(" "));
+ Assert.assertEquals(MutableList.of(""),
+ JavaStringEscapes.unwrapJsonishListStringIfPossible("\"\""));
+ Assert.assertEquals(MutableList.of("x"),
+ JavaStringEscapes.unwrapJsonishListStringIfPossible(",,x,"));
+ Assert.assertEquals(MutableList.of("","x",""),
+
JavaStringEscapes.unwrapJsonishListStringIfPossible("\"\",,x,\"\""));
+ }
+
+ @Test
+ public void testJavaListObject() {
+ Assert.assertEquals(MutableList.of("hello", "world"),
+ JavaStringEscapes.tryUnwrapJsonishList("\"hello\",
\"world\"").get());
+ Assert.assertEquals(MutableList.of("hello"),
+ JavaStringEscapes.tryUnwrapJsonishList("hello").get());
+ Assert.assertEquals(MutableList.of("hello", "world"),
+ JavaStringEscapes.tryUnwrapJsonishList("hello, world").get());
+ Assert.assertEquals(MutableList.of("hello", "world"),
+ JavaStringEscapes.tryUnwrapJsonishList("\"hello\",
world").get());
+ Assert.assertEquals(MutableList.of("hello", "world"),
+ JavaStringEscapes.tryUnwrapJsonishList("[ \"hello\", world
]").get());
+ Assert.assertEquals(MutableList.of(),
+ JavaStringEscapes.tryUnwrapJsonishList(" ").get());
+ Assert.assertEquals(MutableList.of(""),
+ JavaStringEscapes.tryUnwrapJsonishList("\"\"").get());
+ Assert.assertEquals(MutableList.of("","","x",""),
+ JavaStringEscapes.tryUnwrapJsonishList(",,x,").get());
+ Assert.assertEquals(MutableList.of("","","x",""),
+ JavaStringEscapes.tryUnwrapJsonishList("\"\",,x,\"\"").get());
+ Assert.assertEquals(MutableList.<Object>of(MutableMap.of("a",
1),MutableMap.of("b", 2)),
+ JavaStringEscapes.tryUnwrapJsonishList("[ a : 1, b : 2
]").get());
+
+ Assert.assertEquals(MutableList.<Object>of(1, 2, "buckle my shoe",
true, "true", null, "null", ","),
--- End diff --
Can't see any tests for doubles.
---