### Question:
UtilsProcessService { public Map<String, List<ProcessKeyValue>> computeDataFromCsv(String dataFromCsv) { HashMap<String, List<ProcessKeyValue>> map = new HashMap<>(); if (dataFromCsv != null) { String[] tabSplitLine = dataFromCsv.split("\n"); for (String line : tabSplitLine) { String[] lineSplitBydelimiter = line.split(";"); if (lineSplitBydelimiter.length < 3) { return map; } List<ProcessKeyValue> listElem = new ArrayList<>(); try { for (int i = 1; i < lineSplitBydelimiter.length; i = i + 2) { listElem.add(ProcessKeyValue.builder().key(lineSplitBydelimiter[i]).value(lineSplitBydelimiter[i + 1]).build()); } map.put(lineSplitBydelimiter[0], listElem); } catch (Exception e) { log.error("Exception during parse CSV {}", e); return new HashMap<>(); } } } return map; }  Map<String, List<ProcessKeyValue>> computeDataFromCsv(String dataFromCsv);  }### Answer:
@Test public void should_Ok_OneLine() { UtilsProcessService utilsProcessService = new UtilsProcessService(); String data = "value;key1;value1;key2;value2"; Map<String, List<ProcessKeyValue>> map = utilsProcessService.computeDataFromCsv(data); assertThat(map.get("value").get(0).getKey()).isEqualTo("key1"); assertThat(map.get("value").get(0).getValue()).isEqualTo("value1"); assertThat(map.get("value").get(1).getKey()).isEqualTo("key2"); assertThat(map.get("value").get(1).getValue()).isEqualTo("value2"); }
@Test public void should_Ok_MultiLine() { UtilsProcessService utilsProcessService = new UtilsProcessService(); String data = "l0;key1;value1;key2;value2\nl1;key1;value1;key2;value2\nl2;key1;value1;key2;value2\nl3;key1;value1;type;typeTodefine\n"; Map<String, List<ProcessKeyValue>> map = utilsProcessService.computeDataFromCsv(data); assertThat(map.get("l0").get(0).getKey()).isEqualTo("key1"); assertThat(map.get("l0").get(0).getValue()).isEqualTo("value1"); assertThat(map.get("l3").get(1).getKey()).isEqualTo("type"); assertThat(map.get("l3").get(1).getValue()).isEqualTo("typeTodefine"); }
@Test public void should_Ko_OneLine() { UtilsProcessService utilsProcessService = new UtilsProcessService(); String data = "value;key1;key2;value2"; Map<String, List<ProcessKeyValue>> map = utilsProcessService.computeDataFromCsv(data); assertThat(map.size()).isEqualTo(0); }
@Test public void should_Ko_OneLine_ManyData() { UtilsProcessService utilsProcessService = new UtilsProcessService(); String data = "value;key1;key2;key2;value2;key3"; Map<String, List<ProcessKeyValue>> map = utilsProcessService.computeDataFromCsv(data); assertThat(map.size()).isEqualTo(0); }
@Test public void should_Ko_MultiLine() { UtilsProcessService utilsProcessService = new UtilsProcessService(); String data = "l0;key1;value1;key2;value2\nl1;key1;value1;key2;value2\nl2;key1;value1;key2\nl3;key1;value1;type;typeTodefine\n"; Map<String, List<ProcessKeyValue>> map = utilsProcessService.computeDataFromCsv(data); assertThat(map.size()).isEqualTo(0); }
@Test public void should_Ko_Empty() { UtilsProcessService utilsProcessService = new UtilsProcessService(); String data = ""; Map<String, List<ProcessKeyValue>> map = utilsProcessService.computeDataFromCsv(data); assertThat(map.size()).isEqualTo(0); }