Skip to content

Commit

Permalink
#46 keep the column name in its original casing, only lowercase it fo…
Browse files Browse the repository at this point in the history
…r the lookup
  • Loading branch information
robert-bor committed Aug 26, 2014
1 parent fc1cc16 commit 2ff8182
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/csveed/bean/BeanProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,10 @@ public void mapIndexToProperty(int columnIndex, String propertyName) {
}

public void mapNameToProperty(String columnName, String propertyName) {
columnName = columnName.toLowerCase();
BeanProperty property = get(propertyName);
removeFromColumnName(property);
property.setColumnName(columnName);
nameToProperty.put(new Column(columnName), property);
nameToProperty.put(new Column(columnName.toLowerCase()), property);
}

protected BeanProperty get(String propertyName) {
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/csveed/bean/BeanWriterTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.csveed.bean;

import org.csveed.bean.conversion.Bean;
import org.csveed.report.CsvException;
import org.csveed.test.model.BeanWithMultipleStrings;
import org.junit.Test;

Expand Down Expand Up @@ -31,6 +33,47 @@ public void writeBeans() throws IOException {
writer.getBuffer().toString());
}

// https://github.com/robert-bor/CSVeed/issues/46
@Test
public void bug46ReportedByJnash67() throws IOException {
StringWriter writer = new StringWriter();
List<BeanWithMultipleStrings> beans = new ArrayList<BeanWithMultipleStrings>();
beans.add(createBean("row 1, cell 3", "row 1, cell 2", "row 1, cell 1"));
beans.add(createBean("row 2, cell 3", "row 2, cell 2", "row 2, cell 1"));
beans.add(createBean("row 3, cell 3", "row 3, cell 2", "row 3, cell 1"));
BeanInstructions bi = new BeanInstructionsImpl(BeanWithMultipleStrings.class);
bi.logSettings();
bi.mapColumnNameToProperty("Aap", "gamma");
bi.mapColumnNameToProperty("Noot", "beta");
bi.mapColumnNameToProperty("Mies", "alpha");
BeanWriter<BeanWithMultipleStrings> beanWriter =
new BeanWriterImpl<BeanWithMultipleStrings>(writer, bi);
// new BeanWriterImpl<BeanWithMultipleStrings>(writer, BeanWithMultipleStrings.class);
beanWriter.writeBeans(beans);
writer.close();
assertEquals(
"\"Aap\";\"Noot\";\"Mies\"\r"+
"\"row 1, cell 1\";\"row 1, cell 2\";\"row 1, cell 3\"\r"+
"\"row 2, cell 1\";\"row 2, cell 2\";\"row 2, cell 3\"\r"+
"\"row 3, cell 1\";\"row 3, cell 2\";\"row 3, cell 3\"\r",
writer.getBuffer().toString());
}

// https://github.com/robert-bor/CSVeed/issues/46
// @Test
// public void bug46ReportedByJnash67() {
// String[] pids = new String[] { "alpha", "beta", "gamma", "delta" };
// BeanInstructions bi = new BeanInstructionsImpl(Bean.class);
//// bi.setMapper(Bean.class);
// for (String pid : pids) {
// try {
// bi.mapColumnNameToProperty(pid, pid);
// } catch (CsvException ce) {
// ce.printStackTrace();
// }
// }
// }

private BeanWithMultipleStrings createBean(String alpha, String beta, String gamma) {
BeanWithMultipleStrings bean = new BeanWithMultipleStrings();
bean.setAlpha(alpha);
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] %m%n

log4j.rootLogger=ERROR, stdout
log4j.rootLogger=INFO, stdout

0 comments on commit 2ff8182

Please sign in to comment.