You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2011/11/10 12:58:03 UTC
svn commit: r1200283 - in /commons/sandbox/csv/trunk/src:
main/java/org/apache/commons/csv/CSVFormat.java
test/java/org/apache/commons/csv/CSVFormatTest.java
Author: ebourg
Date: Thu Nov 10 11:58:02 2011
New Revision: 1200283
URL: http://svn.apache.org/viewvc?rev=1200283&view=rev
Log:
Fixed the immutability of the delimiter in CSVFormat
Modified:
commons/sandbox/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
commons/sandbox/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
Modified: commons/sandbox/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
URL: http://svn.apache.org/viewvc/commons/sandbox/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java?rev=1200283&r1=1200282&r2=1200283&view=diff
==============================================================================
--- commons/sandbox/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java (original)
+++ commons/sandbox/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java Thu Nov 10 11:58:02 2011
@@ -102,7 +102,7 @@ public class CSVFormat implements Clonea
public CSVFormat withDelimiter(char delimiter) {
CSVFormat format = (CSVFormat) clone();
- this.delimiter = delimiter;
+ format.delimiter = delimiter;
return format;
}
Modified: commons/sandbox/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java?rev=1200283&r1=1200282&r2=1200283&view=diff
==============================================================================
--- commons/sandbox/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java (original)
+++ commons/sandbox/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java Thu Nov 10 11:58:02 2011
@@ -22,27 +22,42 @@ import junit.framework.TestCase;
public class CSVFormatTest extends TestCase {
public void testImmutalibity() {
- CSVFormat format1 = new CSVFormat('!', '!', '!', '!', true, true, true, true);
- CSVFormat format2 = format1.withDelimiter('?')
- .withEncapsulator('?')
- .withCommentStart('?')
- .withLineSeparator("?")
- .withEscape('?')
- .withLeadingSpacesIgnored(false)
- .withTrailingSpacesIgnored(false)
- .withEmptyLinesIgnored(false)
- .withUnicodeEscapesInterpreted(false);
-
- assertNotSame(format1.getDelimiter(), format2.getDelimiter());
- assertNotSame(format1.getEncapsulator(), format2.getEncapsulator());
- assertNotSame(format1.getCommentStart(), format2.getCommentStart());
- assertNotSame(format1.getEscape(), format2.getEscape());
- assertNotSame(format1.getLineSeparator(), format2.getLineSeparator());
+ CSVFormat format = new CSVFormat('!', '!', '!', '!', true, true, true, true);
+
+ format.withDelimiter('?');
+ format.withEncapsulator('?');
+ format.withCommentStart('?');
+ format.withLineSeparator("?");
+ format.withEscape('?');
+ format.withLeadingSpacesIgnored(false);
+ format.withTrailingSpacesIgnored(false);
+ format.withEmptyLinesIgnored(false);
+ format.withUnicodeEscapesInterpreted(false);
+
+ assertEquals('!', format.getDelimiter());
+ assertEquals('!', format.getEncapsulator());
+ assertEquals('!', format.getCommentStart());
+ assertEquals("\n", format.getLineSeparator());
+ assertEquals('!', format.getEscape());
- assertNotSame(format1.isTrailingSpacesIgnored(), format2.isTrailingSpacesIgnored());
- assertNotSame(format1.isLeadingSpacesIgnored(), format2.isLeadingSpacesIgnored());
- assertNotSame(format1.isEmptyLinesIgnored(), format2.isEmptyLinesIgnored());
- assertNotSame(format1.isUnicodeEscapesInterpreted(), format2.isUnicodeEscapesInterpreted());
+ assertEquals(true, format.isLeadingSpacesIgnored());
+ assertEquals(true, format.isTrailingSpacesIgnored());
+ assertEquals(true, format.isEmptyLinesIgnored());
+ assertEquals(true, format.isUnicodeEscapesInterpreted());
}
+ public void testMutators() {
+ CSVFormat format = new CSVFormat('!', '!', '!', '!', true, true, true, true);
+
+ assertEquals('?', format.withDelimiter('?').getDelimiter());
+ assertEquals('?', format.withEncapsulator('?').getEncapsulator());
+ assertEquals('?', format.withCommentStart('?').getCommentStart());
+ assertEquals("?", format.withLineSeparator("?").getLineSeparator());
+ assertEquals('?', format.withEscape('?').getEscape());
+
+ assertEquals(false, format.withLeadingSpacesIgnored(false).isLeadingSpacesIgnored());
+ assertEquals(false, format.withTrailingSpacesIgnored(false).isTrailingSpacesIgnored());
+ assertEquals(false, format.withEmptyLinesIgnored(false).isEmptyLinesIgnored());
+ assertEquals(false, format.withUnicodeEscapesInterpreted(false).isUnicodeEscapesInterpreted());
+ }
}