### Question:
VertexMetadata { public Iterable<String> toIterable(CSVRecord record) { return () -> new Iterator<String>() { int index = 0; @Override public boolean hasNext() { return index <= lastColumnIndex; } @Override public String next() { Header header = headers.get(index); if (header.equals(Token.LABEL)) { return Arrays.stream(record.get(index++).split(":")) .filter(s -> !s.isEmpty()) .collect(Collectors.joining(";")); } else { PropertyValue propertyValue = propertyValueParser.parse(record.get(index)); if (propertyValue.isMultiValued()) { header.setIsMultiValued(true); } header.updateDataType(propertyValue.dataType()); index++; return propertyValue.value(); } } }; } private  VertexMetadata(Headers headers, int lastColumnIndex, PropertyValueParser parser); static VertexMetadata parse(CSVRecord record, PropertyValueParser parser); List<String> headers(); boolean isVertex(CSVRecord record); Iterable<String> toIterable(CSVRecord record);  }### Answer:
@Test public void shouldWrapRecordWithVertexSpecificIterable() { String columnHeaders = "\"_id\",\"_labels\",\"address\",\"name\",\"index\",\"txid\",\"_start\",\"_end\",\"_type\",\"strength\",\"timestamp\""; VertexMetadata vertexMetadata = createVertexMetadata(columnHeaders); CSVRecord record = CSVUtils.firstRecord("\"1\",\"Person\",\"address\",\"name\",\"1\",\"1\",,,,,"); Iterable<String> vertex = vertexMetadata.toIterable(record); String expected = "1,Person,address,name,1,1"; assertEquals(expected, String.join(",", vertex)); }
@Test public void shouldRemoveLeadingColonFromLabel() { String columnHeaders = "\"_id\",\"_labels\",\"address\",\"name\",\"index\",\"txid\",\"_start\",\"_end\",\"_type\",\"strength\",\"timestamp\""; VertexMetadata vertexMetadata = createVertexMetadata(columnHeaders); CSVRecord record = CSVUtils.firstRecord("\"1\",\":Person\",\"address\",\"name\",\"1\",\"1\",,,,,"); Iterable<String> vertex = vertexMetadata.toIterable(record); String expected = "1,Person,address,name,1,1"; assertEquals(expected, String.join(",", vertex)); }
@Test public void shouldCreateSemicolonDelimitedListOfLabelsForMultipleLabelsInSource(){ String columnHeaders = "\"_id\",\"_labels\",\"address\",\"name\",\"index\",\"txid\""; VertexMetadata vertexMetadata = createVertexMetadata(columnHeaders); CSVRecord record = CSVUtils.firstRecord("\"1\",\":Person:Admin\",\"address\",\"name\",\"1\",\"1\""); Iterable<String> vertex = vertexMetadata.toIterable(record); String expected = "1,Person;Admin,address,name,1,1"; assertEquals(expected, String.join(",", vertex)); }
@Test public void shouldAllowEmptyLabels(){ String columnHeaders = "\"_id\",\"_labels\",\"address\",\"name\",\"index\",\"txid\""; VertexMetadata vertexMetadata = createVertexMetadata(columnHeaders); CSVRecord record = CSVUtils.firstRecord("\"1\",\"\",\"address\",\"name\",\"1\",\"1\""); Iterable<String> vertex = vertexMetadata.toIterable(record); String expected = "1,,address,name,1,1"; assertEquals(expected, String.join(",", vertex)); }