Add @Test testRemoveAndAddColumns.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1560389 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2014-01-22 15:49:14 +00:00
parent e3ffcc5cd7
commit 8ba293b934
1 changed files with 19 additions and 1 deletions

View File

@ -21,17 +21,21 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class CSVRecordTest {
private enum EnumFixture { UNKNOWN_COLUMN }
private String[] values;
private CSVRecord record, recordWithHeader;
private Map<String, Integer> header;
@ -131,6 +135,20 @@ public class CSVRecordTest {
this.validateMap(map, false);
}
@Test
public void testRemoveAndAddColumns() throws IOException {
// do:
final CSVPrinter printer = new CSVPrinter(new StringBuilder(), CSVFormat.DEFAULT);
final Map<String, String> map = recordWithHeader.toMap();
map.remove("OldColumn");
map.put("NewColumn", "NewValue");
// check:
final ArrayList<String> list = new ArrayList<String>(map.values());
Collections.sort(list);
printer.printRecord(list);
Assert.assertEquals("A,B,C,NewValue" + CSVFormat.DEFAULT.getRecordSeparator(), printer.getOut().toString());
}
@Test
public void testToMap() {
final Map<String, String> map = this.recordWithHeader.toMap();