CsvMapping { public CsvMappingResult<TEntity> map(String[] values) { TEntity entity = (TEntity) creator.create(); for (int pos = 0; pos < csvPropertyMappings.size(); pos++) { IndexToPropertyMapping indexToPropertyMapping = csvPropertyMappings.get(pos); int columnIndex = indexToPropertyMapping.getColumnIndex(); if (columnIndex >= values.length) { return new CsvMappingResult(new CsvMappingError(columnIndex, null, String.format("Column %s Out Of Range", columnIndex))); } String value = values[columnIndex]; if (!indexToPropertyMapping.getPropertyMapping().tryMapValue(entity, value)) { return new CsvMappingResult(new CsvMappingError(columnIndex, value, "Conversion failed")); } } return new CsvMappingResult(entity); } CsvMapping(IObjectCreator creator);  CsvMapping(IObjectCreator creator, ITypeConverterProvider typeConverterProvider); void mapProperty(int columnIndex, Type targetType, BiConsumer<TEntity, TProperty> setter); void mapProperty(int columnIndex, Type targetType, BiConsumer<TEntity, TProperty> setter, ITypeConverter<TProperty> converter); CsvMappingResult<TEntity> map(String[] values); @Override String toString();  }
@Test public void testMapProperty_CsvMappingResult_ToString() { IObjectCreator<SampleEntity> objectCreator = () -> new SampleEntity(); CsvMapping<SampleEntity> csvMapping = new SampleEntityMapping(objectCreator); CsvMappingResult<SampleEntity> result = csvMapping.map(new String[] {"1"}); Assert.assertEquals(null, result.getError()); Assert.assertEquals(1, result.getResult().A); }
@Test public void testMapProperty_TooFewData() { IObjectCreator<SampleEntity> objectCreator = () -> new SampleEntity(); CsvMapping<SampleEntity> csvMapping = new SampleEntityMapping(objectCreator); CsvMappingResult<SampleEntity> result = csvMapping.map(new String[] {}); Assert.assertNotNull(result.getError()); Assert.assertEquals(0, result.getError().getIndex()); Assert.assertEquals(null, result.getError().getValue()); Assert.assertEquals("Column 0 Out Of Range", result.getError().getMessage()); }