|
21 | 21 | import static org.junit.Assert.assertNull; |
22 | 22 | import static org.junit.Assert.assertTrue; |
23 | 23 |
|
| 24 | +import java.io.IOException; |
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.Collections; |
24 | 27 | import java.util.HashMap; |
25 | 28 | import java.util.Map; |
26 | 29 | import java.util.concurrent.ConcurrentHashMap; |
27 | 30 |
|
| 31 | +import org.junit.Assert; |
28 | 32 | import org.junit.Before; |
29 | 33 | import org.junit.Test; |
30 | 34 |
|
31 | 35 | public class CSVRecordTest { |
32 | 36 |
|
33 | 37 | private enum EnumFixture { UNKNOWN_COLUMN } |
34 | | - |
| 38 | + |
35 | 39 | private String[] values; |
36 | 40 | private CSVRecord record, recordWithHeader; |
37 | 41 | private Map<String, Integer> header; |
@@ -131,6 +135,20 @@ public void testPutInMap() { |
131 | 135 | this.validateMap(map, false); |
132 | 136 | } |
133 | 137 |
|
| 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 | + |
134 | 152 | @Test |
135 | 153 | public void testToMap() { |
136 | 154 | final Map<String, String> map = this.recordWithHeader.toMap(); |
|
0 commit comments