[3/3] commons-csv git commit: CSV-216 test mutators
CSV-216 test mutators Project: http://git-wip-us.apache.org/repos/asf/commons-csv/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-csv/commit/c66ea98c Tree: http://git-wip-us.apache.org/repos/asf/commons-csv/tree/c66ea98c Diff: http://git-wip-us.apache.org/repos/asf/commons-csv/diff/c66ea98c Branch: refs/heads/CSV-216 Commit: c66ea98c0fdc344fc919b228988c695c4b62c442 Parents: 6eebeb0 Author: Stian Soiland-Reyes Authored: Fri Feb 9 16:09:41 2018 + Committer: Stian Soiland-Reyes Committed: Fri Feb 9 16:09:41 2018 + -- .../commons/csv/CSVMutableRecordTest.java | 10 .../org/apache/commons/csv/CSVRecordTest.java | 58 2 files changed, 68 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-csv/blob/c66ea98c/src/test/java/org/apache/commons/csv/CSVMutableRecordTest.java -- diff --git a/src/test/java/org/apache/commons/csv/CSVMutableRecordTest.java b/src/test/java/org/apache/commons/csv/CSVMutableRecordTest.java index 8f97dcd..08770fd 100644 --- a/src/test/java/org/apache/commons/csv/CSVMutableRecordTest.java +++ b/src/test/java/org/apache/commons/csv/CSVMutableRecordTest.java @@ -1,9 +1,19 @@ package org.apache.commons.csv; +import static org.junit.Assert.assertTrue; + import org.junit.Assert; +import org.junit.Test; public class CSVMutableRecordTest extends CSVRecordTest { + @Override +@Test +public void isMutable() { + assertTrue(record.isMutable()); + assertTrue(recordWithHeader.isMutable()); +} + @Override protected CSVFormat createCommaFormat() { return super.createCommaFormat().withMutableRecords(true); http://git-wip-us.apache.org/repos/asf/commons-csv/blob/c66ea98c/src/test/java/org/apache/commons/csv/CSVRecordTest.java -- diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java index cc3f3c6..69f124d 100644 --- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java +++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java @@ -19,7 +19,9 @@ package org.apache.commons.csv; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -188,6 +190,62 @@ public class CSVRecordTest { } @Test +public void isMutable() { + assertFalse(record.isMutable()); + assertFalse(recordWithHeader.isMutable()); +} + +@Test +public void testMutable() throws Exception { + CSVRecord mutable = record.mutable(); + assertTrue(mutable.isMutable()); + if (record.isMutable()) { + assertSame(record, mutable); + } else { + assertNotSame(record, mutable); + } +} + +@Test +public void testImmutable() throws Exception { + CSVRecord immutable = record.immutable(); + assertFalse(immutable.isMutable()); + assertSame(immutable, immutable.immutable()); + assertNotSame(immutable, immutable.mutable()); + if (record.isMutable()) { + assertNotSame(record, immutable); + } else { + assertSame(record, immutable); + } +} + +@Test +public void testWithValue() throws Exception { + assertEquals("A", record.get(0)); + CSVRecord newR = record.withValue(0, "X"); + assertEquals("X", newR.get(0)); + if (record.isMutable()) { + assertSame(record, newR); + } else { + // unchanged + assertEquals("A", record.get(0)); + } +} + +@Test +public void testWithValueName() throws Exception { + assertEquals("B", recordWithHeader.get("second")); + CSVRecord newR = recordWithHeader.withValue("second", "Y"); + assertEquals("Y", newR.get("second")); + if (record.isMutable()) { + assertSame(recordWithHeader, newR); + } else { + // unchanged + assertEquals("B", recordWithHeader.get("second")); + } +} + +@Test public void testToMapWithNoHeader() throws Exception { try (final CSVParser parser = CSVParser.parse("a,b", createCommaFormat())) { final CSVRecord shortRec = parser.iterator().next();
[3/3] commons-csv git commit: CSV-216 test mutators
CSV-216 test mutators Project: http://git-wip-us.apache.org/repos/asf/commons-csv/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-csv/commit/c66ea98c Tree: http://git-wip-us.apache.org/repos/asf/commons-csv/tree/c66ea98c Diff: http://git-wip-us.apache.org/repos/asf/commons-csv/diff/c66ea98c Branch: refs/heads/CSV-216-with Commit: c66ea98c0fdc344fc919b228988c695c4b62c442 Parents: 6eebeb0 Author: Stian Soiland-Reyes Authored: Fri Feb 9 16:09:41 2018 + Committer: Stian Soiland-Reyes Committed: Fri Feb 9 16:09:41 2018 + -- .../commons/csv/CSVMutableRecordTest.java | 10 .../org/apache/commons/csv/CSVRecordTest.java | 58 2 files changed, 68 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-csv/blob/c66ea98c/src/test/java/org/apache/commons/csv/CSVMutableRecordTest.java -- diff --git a/src/test/java/org/apache/commons/csv/CSVMutableRecordTest.java b/src/test/java/org/apache/commons/csv/CSVMutableRecordTest.java index 8f97dcd..08770fd 100644 --- a/src/test/java/org/apache/commons/csv/CSVMutableRecordTest.java +++ b/src/test/java/org/apache/commons/csv/CSVMutableRecordTest.java @@ -1,9 +1,19 @@ package org.apache.commons.csv; +import static org.junit.Assert.assertTrue; + import org.junit.Assert; +import org.junit.Test; public class CSVMutableRecordTest extends CSVRecordTest { + @Override +@Test +public void isMutable() { + assertTrue(record.isMutable()); + assertTrue(recordWithHeader.isMutable()); +} + @Override protected CSVFormat createCommaFormat() { return super.createCommaFormat().withMutableRecords(true); http://git-wip-us.apache.org/repos/asf/commons-csv/blob/c66ea98c/src/test/java/org/apache/commons/csv/CSVRecordTest.java -- diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java index cc3f3c6..69f124d 100644 --- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java +++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java @@ -19,7 +19,9 @@ package org.apache.commons.csv; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -188,6 +190,62 @@ public class CSVRecordTest { } @Test +public void isMutable() { + assertFalse(record.isMutable()); + assertFalse(recordWithHeader.isMutable()); +} + +@Test +public void testMutable() throws Exception { + CSVRecord mutable = record.mutable(); + assertTrue(mutable.isMutable()); + if (record.isMutable()) { + assertSame(record, mutable); + } else { + assertNotSame(record, mutable); + } +} + +@Test +public void testImmutable() throws Exception { + CSVRecord immutable = record.immutable(); + assertFalse(immutable.isMutable()); + assertSame(immutable, immutable.immutable()); + assertNotSame(immutable, immutable.mutable()); + if (record.isMutable()) { + assertNotSame(record, immutable); + } else { + assertSame(record, immutable); + } +} + +@Test +public void testWithValue() throws Exception { + assertEquals("A", record.get(0)); + CSVRecord newR = record.withValue(0, "X"); + assertEquals("X", newR.get(0)); + if (record.isMutable()) { + assertSame(record, newR); + } else { + // unchanged + assertEquals("A", record.get(0)); + } +} + +@Test +public void testWithValueName() throws Exception { + assertEquals("B", recordWithHeader.get("second")); + CSVRecord newR = recordWithHeader.withValue("second", "Y"); + assertEquals("Y", newR.get("second")); + if (record.isMutable()) { + assertSame(recordWithHeader, newR); + } else { + // unchanged + assertEquals("B", recordWithHeader.get("second")); + } +} + +@Test public void testToMapWithNoHeader() throws Exception { try (final CSVParser parser = CSVParser.parse("a,b", createCommaFormat())) { final CSVRecord shortRec = parser.iterator().next();