CSVUtils { @Contract("null -> null") public static String getEscapedValueForCsv(String value) { if (value == null) { return null; } if (value.contains("\"")) { value = escapeDoubleQuote(value); } return quoteString(value); } private  CSVUtils(); @Contract("null -> null") static String getEscapedValueForCsv(String value); @Contract("null -> null; !null -> !null") static String escapeDoubleQuote(String value); @Contract(value = "null -> null; !null -> !null", pure = true) static String quoteString(String value);  }
@Test public void testGetEscapedValueForCsv() { Assert.assertNull(CSVUtils.getEscapedValueForCsv(null)); Assert.assertEquals("\"\"", CSVUtils.getEscapedValueForCsv("")); Assert.assertEquals("\"string\"", CSVUtils.getEscapedValueForCsv("string")); Assert.assertEquals("\"string with \"\"quotes\"\"\"", CSVUtils.getEscapedValueForCsv("string with \"quotes\"")); }