### Question:
CsvWriter { public String buildLine(String[] nextLine) { final StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE); for (int i = 0; i < nextLine.length; i++) { if (i != 0) { sb.append(_configuration.getSeparatorChar()); } final String nextElement = nextLine[i]; if (nextElement == null) { continue; } final char quoteChar = _configuration.getQuoteChar(); if (quoteChar != CsvConfiguration.NOT_A_CHAR) { sb.append(quoteChar); } sb.append(valueNeedsEscaping(nextElement) ? processValue(nextElement) : nextElement); if (quoteChar != CsvConfiguration.NOT_A_CHAR) { sb.append(quoteChar); } } sb.append('\n'); return sb.toString(); } CsvWriter(CsvConfiguration configuration); String buildLine(String[] nextLine); static final int INITIAL_STRING_SIZE; }### Answer:
@Test public void testBuildLineWithSeparatorInValue() throws Exception { CsvConfiguration configuration = new CsvConfiguration(1, "UTF-8", ',', '"', '\\'); CsvWriter writer = new CsvWriter(configuration); String line = writer.buildLine(new String[] {"0", "1,2", "3'4", "5\\6"}); assertEquals("\"0\",\"1,2\",\"3'4\",\"5\\\\6\"\n", line); }
@Test public void testBuildLineWithSeparatorInValueAndNoQuoteCharacterSet() throws Exception { CsvConfiguration configuration = new CsvConfiguration(1, "UTF-8", ',', CsvConfiguration.NOT_A_CHAR, '\\'); CsvWriter writer = new CsvWriter(configuration); String line = writer.buildLine(new String[] {"0", "1,2", "3'4", "5\\6"}); assertEquals("0,1\\,2,3'4,5\\\\6\n", line); }