JmxUtil { public static String quoteValueIfRequired(String unquotedValue) { String result; String quotedValue = ObjectName.quote(unquotedValue); if (quotedValue.substring(1, quotedValue.length() - 1).equals(unquotedValue)) { ObjectName on = null; try { on = new ObjectName("dummy", "dummy", unquotedValue); } catch (MalformedObjectNameException ignore) { } if (on != null){ result = unquotedValue; } else { result = quotedValue; } } else { result = quotedValue; } return result; } private  JmxUtil(); static String quoteValueIfRequired(String unquotedValue);  }
@Test public void quotation() throws Exception{ assertEquals("text", JmxUtil.quoteValueIfRequired("text")); TestCase.assertEquals("", JmxUtil.quoteValueIfRequired("")); assertTrue(JmxUtil.quoteValueIfRequired("text*with?chars").startsWith("\"")); }
@Test public void quoteAndComma() throws Exception{ assertTrue(JmxUtil.quoteValueIfRequired("text,withComma").startsWith("\"")); assertTrue(JmxUtil.quoteValueIfRequired("text=withEqual").startsWith("\"")); }