Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit 8ba293b

Browse files
committed
Add @test testRemoveAndAddColumns.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1560389 13f79535-47bb-0310-9956-ffa450edef68
1 parent e3ffcc5 commit 8ba293b

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/test/java/org/apache/commons/csv/CSVRecordTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@
2121
import static org.junit.Assert.assertNull;
2222
import static org.junit.Assert.assertTrue;
2323

24+
import java.io.IOException;
25+
import java.util.ArrayList;
26+
import java.util.Collections;
2427
import java.util.HashMap;
2528
import java.util.Map;
2629
import java.util.concurrent.ConcurrentHashMap;
2730

31+
import org.junit.Assert;
2832
import org.junit.Before;
2933
import org.junit.Test;
3034

3135
public class CSVRecordTest {
3236

3337
private enum EnumFixture { UNKNOWN_COLUMN }
34-
38+
3539
private String[] values;
3640
private CSVRecord record, recordWithHeader;
3741
private Map<String, Integer> header;
@@ -131,6 +135,20 @@ public void testPutInMap() {
131135
this.validateMap(map, false);
132136
}
133137

138+
@Test
139+
public void testRemoveAndAddColumns() throws IOException {
140+
// do:
141+
final CSVPrinter printer = new CSVPrinter(new StringBuilder(), CSVFormat.DEFAULT);
142+
final Map<String, String> map = recordWithHeader.toMap();
143+
map.remove("OldColumn");
144+
map.put("NewColumn", "NewValue");
145+
// check:
146+
final ArrayList<String> list = new ArrayList<String>(map.values());
147+
Collections.sort(list);
148+
printer.printRecord(list);
149+
Assert.assertEquals("A,B,C,NewValue" + CSVFormat.DEFAULT.getRecordSeparator(), printer.getOut().toString());
150+
}
151+
134152
@Test
135153
public void testToMap() {
136154
final Map<String, String> map = this.recordWithHeader.toMap();

0 commit comments

Comments
 (0)