CSVFormatUtils { Map<String, String> compileParameterProperties(Separator separator, Map<String, String> updatedParameters) { List<String> header = separator.getHeaders().stream().map(Pair::getKey).collect(Collectors.toList()); String jsonHeader; try { jsonHeader = mapper.writeValueAsString(header); } catch (Exception e) { throw new TDPException(UNABLE_TO_SERIALIZE_TO_JSON, e); } updatedParameters.put(HEADER_COLUMNS_PARAMETER, jsonHeader); updatedParameters.put(HEADER_NB_LINES_PARAMETER, separator.isFirstLineAHeader() ? "1" : "0"); updatedParameters.put(SEPARATOR_PARAMETER, String.valueOf(separator.getSeparator())); updatedParameters.putIfAbsent(TEXT_ENCLOSURE_CHAR, defaultTextEnclosure); updatedParameters.putIfAbsent(ESCAPE_CHAR, defaultEscapeChar); return updatedParameters; }    }
@Test public void should_compile_parameters() { ReflectionTestUtils.setField(csvFormatUtils, "defaultTextEnclosure", "\""); ReflectionTestUtils.setField(csvFormatUtils, "defaultEscapeChar", "\u0000"); final Map<String, String> entryParameters = initMapParam(); final Separator separator = new Separator("|".charAt(0)); csvFormatUtils.compileParameterProperties(separator, entryParameters); assertEquals(5, entryParameters.size()); assertEquals("\u0000", entryParameters.get(ESCAPE_CHAR)); assertEquals("\"", entryParameters.get(TEXT_ENCLOSURE_CHAR)); assertEquals("|", entryParameters.get(SEPARATOR_PARAMETER)); assertEquals("0", entryParameters.get(HEADER_NB_LINES_PARAMETER)); assertEquals(null, entryParameters.get(HEADER_COLUMNS_PARAMETER)); }