|
19 | 19 | import static org.junit.Assert.assertEquals; |
20 | 20 | import static org.junit.Assert.assertFalse; |
21 | 21 | import static org.junit.Assert.assertNotNull; |
| 22 | +import static org.junit.Assert.assertNotSame; |
22 | 23 | import static org.junit.Assert.assertNull; |
| 24 | +import static org.junit.Assert.assertSame; |
23 | 25 | import static org.junit.Assert.assertTrue; |
24 | 26 |
|
25 | 27 | import java.io.IOException; |
@@ -187,6 +189,62 @@ public void testToMapWithShortRecord() throws Exception { |
187 | 189 | } |
188 | 190 | } |
189 | 191 |
|
| 192 | + @Test |
| 193 | + public void isMutable() { |
| 194 | + assertFalse(record.isMutable()); |
| 195 | + assertFalse(recordWithHeader.isMutable()); |
| 196 | + } |
| 197 | + |
| 198 | + @Test |
| 199 | + public void testMutable() throws Exception { |
| 200 | + CSVRecord mutable = record.mutable(); |
| 201 | + assertTrue(mutable.isMutable()); |
| 202 | + if (record.isMutable()) { |
| 203 | + assertSame(record, mutable); |
| 204 | + } else { |
| 205 | + assertNotSame(record, mutable); |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + @Test |
| 210 | + public void testImmutable() throws Exception { |
| 211 | + CSVRecord immutable = record.immutable(); |
| 212 | + assertFalse(immutable.isMutable()); |
| 213 | + assertSame(immutable, immutable.immutable()); |
| 214 | + assertNotSame(immutable, immutable.mutable()); |
| 215 | + if (record.isMutable()) { |
| 216 | + assertNotSame(record, immutable); |
| 217 | + } else { |
| 218 | + assertSame(record, immutable); |
| 219 | + } |
| 220 | + } |
| 221 | + |
| 222 | + @Test |
| 223 | + public void testWithValue() throws Exception { |
| 224 | + assertEquals("A", record.get(0)); |
| 225 | + CSVRecord newR = record.withValue(0, "X"); |
| 226 | + assertEquals("X", newR.get(0)); |
| 227 | + if (record.isMutable()) { |
| 228 | + assertSame(record, newR); |
| 229 | + } else { |
| 230 | + // unchanged |
| 231 | + assertEquals("A", record.get(0)); |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + @Test |
| 236 | + public void testWithValueName() throws Exception { |
| 237 | + assertEquals("B", recordWithHeader.get("second")); |
| 238 | + CSVRecord newR = recordWithHeader.withValue("second", "Y"); |
| 239 | + assertEquals("Y", newR.get("second")); |
| 240 | + if (record.isMutable()) { |
| 241 | + assertSame(recordWithHeader, newR); |
| 242 | + } else { |
| 243 | + // unchanged |
| 244 | + assertEquals("B", recordWithHeader.get("second")); |
| 245 | + } |
| 246 | + } |
| 247 | + |
190 | 248 | @Test |
191 | 249 | public void testToMapWithNoHeader() throws Exception { |
192 | 250 | try (final CSVParser parser = CSVParser.parse("a,b", createCommaFormat())) { |
|
0 commit comments