Static imports in the unit tests
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1301084 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
186e9f9804
commit
3362f9c9d8
|
@ -22,9 +22,10 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CSVFormatTest {
|
||||
|
||||
@Test
|
||||
|
@ -41,43 +42,43 @@ public class CSVFormatTest {
|
|||
format.withEmptyLinesIgnored(false);
|
||||
format.withUnicodeEscapesInterpreted(false);
|
||||
|
||||
Assert.assertEquals('!', format.getDelimiter());
|
||||
Assert.assertEquals('!', format.getEncapsulator());
|
||||
Assert.assertEquals('!', format.getCommentStart());
|
||||
Assert.assertEquals('!', format.getEscape());
|
||||
Assert.assertEquals("\r\n", format.getLineSeparator());
|
||||
assertEquals('!', format.getDelimiter());
|
||||
assertEquals('!', format.getEncapsulator());
|
||||
assertEquals('!', format.getCommentStart());
|
||||
assertEquals('!', format.getEscape());
|
||||
assertEquals("\r\n", format.getLineSeparator());
|
||||
|
||||
Assert.assertEquals(true, format.isLeadingSpacesIgnored());
|
||||
Assert.assertEquals(true, format.isTrailingSpacesIgnored());
|
||||
Assert.assertEquals(true, format.isEmptyLinesIgnored());
|
||||
Assert.assertEquals(true, format.isUnicodeEscapesInterpreted());
|
||||
assertEquals(true, format.isLeadingSpacesIgnored());
|
||||
assertEquals(true, format.isTrailingSpacesIgnored());
|
||||
assertEquals(true, format.isEmptyLinesIgnored());
|
||||
assertEquals(true, format.isUnicodeEscapesInterpreted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMutators() {
|
||||
CSVFormat format = new CSVFormat('!', '!', '!', '!', true, true, true, true, "\r\n");
|
||||
|
||||
Assert.assertEquals('?', format.withDelimiter('?').getDelimiter());
|
||||
Assert.assertEquals('?', format.withEncapsulator('?').getEncapsulator());
|
||||
Assert.assertEquals('?', format.withCommentStart('?').getCommentStart());
|
||||
Assert.assertEquals("?", format.withLineSeparator("?").getLineSeparator());
|
||||
Assert.assertEquals('?', format.withEscape('?').getEscape());
|
||||
assertEquals('?', format.withDelimiter('?').getDelimiter());
|
||||
assertEquals('?', format.withEncapsulator('?').getEncapsulator());
|
||||
assertEquals('?', format.withCommentStart('?').getCommentStart());
|
||||
assertEquals("?", format.withLineSeparator("?").getLineSeparator());
|
||||
assertEquals('?', format.withEscape('?').getEscape());
|
||||
|
||||
Assert.assertEquals(false, format.withLeadingSpacesIgnored(false).isLeadingSpacesIgnored());
|
||||
Assert.assertEquals(false, format.withTrailingSpacesIgnored(false).isTrailingSpacesIgnored());
|
||||
Assert.assertEquals(false, format.withSurroundingSpacesIgnored(false).isLeadingSpacesIgnored());
|
||||
Assert.assertEquals(false, format.withSurroundingSpacesIgnored(false).isTrailingSpacesIgnored());
|
||||
Assert.assertEquals(false, format.withEmptyLinesIgnored(false).isEmptyLinesIgnored());
|
||||
Assert.assertEquals(false, format.withUnicodeEscapesInterpreted(false).isUnicodeEscapesInterpreted());
|
||||
assertEquals(false, format.withLeadingSpacesIgnored(false).isLeadingSpacesIgnored());
|
||||
assertEquals(false, format.withTrailingSpacesIgnored(false).isTrailingSpacesIgnored());
|
||||
assertEquals(false, format.withSurroundingSpacesIgnored(false).isLeadingSpacesIgnored());
|
||||
assertEquals(false, format.withSurroundingSpacesIgnored(false).isTrailingSpacesIgnored());
|
||||
assertEquals(false, format.withEmptyLinesIgnored(false).isEmptyLinesIgnored());
|
||||
assertEquals(false, format.withUnicodeEscapesInterpreted(false).isUnicodeEscapesInterpreted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormat() {
|
||||
CSVFormat format = CSVFormat.DEFAULT;
|
||||
|
||||
Assert.assertEquals("", format.format());
|
||||
Assert.assertEquals("a,b,c", format.format("a", "b", "c"));
|
||||
Assert.assertEquals("\"x,y\",z", format.format("x,y", "z"));
|
||||
assertEquals("", format.format());
|
||||
assertEquals("a,b,c", format.format("a", "b", "c"));
|
||||
assertEquals("\"x,y\",z", format.format("x,y", "z"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -86,49 +87,49 @@ public class CSVFormatTest {
|
|||
|
||||
try {
|
||||
format.withDelimiter('\n');
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
format.withEscape('\r');
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
format.withEncapsulator('\n');
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
format.withCommentStart('\r');
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
format.withDelimiter('!').withEscape('!').validate();
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
format.withDelimiter('!').withCommentStart('!').validate();
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
format.withEncapsulator('!').withCommentStart('!').validate();
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
@ -137,7 +138,7 @@ public class CSVFormatTest {
|
|||
|
||||
try {
|
||||
format.withEscape('!').withCommentStart('!').validate();
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
@ -147,7 +148,7 @@ public class CSVFormatTest {
|
|||
|
||||
try {
|
||||
format.withEncapsulator('!').withDelimiter('!').validate();
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
@ -165,15 +166,15 @@ public class CSVFormatTest {
|
|||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
|
||||
CSVFormat format = (CSVFormat) in.readObject();
|
||||
|
||||
Assert.assertNotNull(format);
|
||||
Assert.assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
|
||||
Assert.assertEquals("encapsulator", CSVFormat.DEFAULT.getEncapsulator(), format.getEncapsulator());
|
||||
Assert.assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
|
||||
Assert.assertEquals("line separator", CSVFormat.DEFAULT.getLineSeparator(), format.getLineSeparator());
|
||||
Assert.assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());
|
||||
Assert.assertEquals("unicode escape", CSVFormat.DEFAULT.isUnicodeEscapesInterpreted(), format.isUnicodeEscapesInterpreted());
|
||||
Assert.assertEquals("trim left", CSVFormat.DEFAULT.isLeadingSpacesIgnored(), format.isLeadingSpacesIgnored());
|
||||
Assert.assertEquals("trim right", CSVFormat.DEFAULT.isTrailingSpacesIgnored(), format.isTrailingSpacesIgnored());
|
||||
Assert.assertEquals("empty lines", CSVFormat.DEFAULT.isEmptyLinesIgnored(), format.isEmptyLinesIgnored());
|
||||
assertNotNull(format);
|
||||
assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
|
||||
assertEquals("encapsulator", CSVFormat.DEFAULT.getEncapsulator(), format.getEncapsulator());
|
||||
assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
|
||||
assertEquals("line separator", CSVFormat.DEFAULT.getLineSeparator(), format.getLineSeparator());
|
||||
assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());
|
||||
assertEquals("unicode escape", CSVFormat.DEFAULT.isUnicodeEscapesInterpreted(), format.isUnicodeEscapesInterpreted());
|
||||
assertEquals("trim left", CSVFormat.DEFAULT.isLeadingSpacesIgnored(), format.isLeadingSpacesIgnored());
|
||||
assertEquals("trim right", CSVFormat.DEFAULT.isTrailingSpacesIgnored(), format.isTrailingSpacesIgnored());
|
||||
assertEquals("empty lines", CSVFormat.DEFAULT.isEmptyLinesIgnored(), format.isEmptyLinesIgnored());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,17 +17,15 @@
|
|||
|
||||
package org.apache.commons.csv;
|
||||
|
||||
import static org.apache.commons.csv.CSVLexer.Token.Type.EOF;
|
||||
import static org.apache.commons.csv.CSVLexer.Token.Type.EORECORD;
|
||||
import static org.apache.commons.csv.CSVLexer.Token.Type.TOKEN;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.apache.commons.csv.CSVLexer.Token;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.apache.commons.csv.CSVLexer.Token.Type.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CSVLexerTest {
|
||||
|
||||
private CSVLexer getLexer(String input, CSVFormat format) {
|
||||
|
@ -35,8 +33,8 @@ public class CSVLexerTest {
|
|||
}
|
||||
|
||||
private void assertTokenEquals(Token.Type expectedType, String expectedContent, Token token) {
|
||||
Assert.assertEquals("Token type", expectedType, token.type);
|
||||
Assert.assertEquals("Token content", expectedContent, token.content.toString());
|
||||
assertEquals("Token type", expectedType, token.type);
|
||||
assertEquals("Token content", expectedContent, token.content.toString());
|
||||
}
|
||||
|
||||
// Single line (without comment)
|
||||
|
|
|
@ -26,10 +26,11 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* CSVParserTest
|
||||
*
|
||||
|
@ -57,20 +58,20 @@ public class CSVParserTest {
|
|||
public void testGetLine() throws IOException {
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
for (String[] re : res) {
|
||||
Assert.assertTrue(Arrays.equals(re, parser.getRecord()));
|
||||
assertTrue(Arrays.equals(re, parser.getRecord()));
|
||||
}
|
||||
|
||||
Assert.assertTrue(parser.getRecord() == null);
|
||||
assertTrue(parser.getRecord() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRecords() throws IOException {
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertEquals(res.length, tmp.length);
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
Assert.assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,10 +89,10 @@ public class CSVParserTest {
|
|||
};
|
||||
CSVParser parser = new CSVParser(code, CSVFormat.EXCEL);
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertEquals(res.length, tmp.length);
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
Assert.assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,10 +108,10 @@ public class CSVParserTest {
|
|||
};
|
||||
CSVParser parser = new CSVParser(code, CSVFormat.EXCEL);
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertEquals(res.length, tmp.length);
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
Assert.assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,10 +136,10 @@ public class CSVParserTest {
|
|||
for (String code : codes) {
|
||||
CSVParser parser = new CSVParser(code, CSVFormat.EXCEL);
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertEquals(res.length, tmp.length);
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
Assert.assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -162,10 +163,10 @@ public class CSVParserTest {
|
|||
for (String code : codes) {
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertEquals(res.length, tmp.length);
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
Assert.assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -186,10 +187,10 @@ public class CSVParserTest {
|
|||
for (String code : codes) {
|
||||
CSVParser parser = new CSVParser(code, CSVFormat.EXCEL);
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertEquals(res.length, tmp.length);
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
Assert.assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -208,10 +209,10 @@ public class CSVParserTest {
|
|||
for (String code : codes) {
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertEquals(res.length, tmp.length);
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
Assert.assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -242,10 +243,10 @@ public class CSVParserTest {
|
|||
};
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertEquals(res.length, tmp.length);
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
Assert.assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,9 +287,9 @@ public class CSVParserTest {
|
|||
|
||||
CSVParser parser = new CSVParser(code, format);
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
Assert.assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,10 +316,10 @@ public class CSVParserTest {
|
|||
|
||||
CSVParser parser = new CSVParser(code, format);
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertTrue(tmp.length > 0);
|
||||
|
||||
if (!CSVPrinterTest.equals(res, tmp)) {
|
||||
Assert.assertTrue(false);
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,14 +338,14 @@ public class CSVParserTest {
|
|||
};
|
||||
|
||||
CSVFormat format = CSVFormat.DEFAULT;
|
||||
Assert.assertEquals(CSVFormat.DISABLED, format.getCommentStart());
|
||||
assertEquals(CSVFormat.DISABLED, format.getCommentStart());
|
||||
|
||||
CSVParser parser = new CSVParser(code, format);
|
||||
String[][] tmp = parser.getRecords();
|
||||
Assert.assertTrue(tmp.length > 0);
|
||||
assertTrue(tmp.length > 0);
|
||||
|
||||
if (!CSVPrinterTest.equals(res, tmp)) {
|
||||
Assert.assertTrue(false);
|
||||
assertTrue(false);
|
||||
}
|
||||
|
||||
String[][] res_comments = {
|
||||
|
@ -358,7 +359,7 @@ public class CSVParserTest {
|
|||
tmp = parser.getRecords();
|
||||
|
||||
if (!CSVPrinterTest.equals(res_comments, tmp)) {
|
||||
Assert.assertTrue(false);
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -368,10 +369,10 @@ public class CSVParserTest {
|
|||
CSVParser parser = new CSVParser(code, CSVFormat.DEFAULT.withUnicodeEscapesInterpreted(true));
|
||||
final Iterator<String[]> iterator = parser.iterator();
|
||||
String[] data = iterator.next();
|
||||
Assert.assertEquals(2, data.length);
|
||||
Assert.assertEquals("abc", data[0]);
|
||||
Assert.assertEquals("public", data[1]);
|
||||
Assert.assertFalse("Should not have any more records", iterator.hasNext());
|
||||
assertEquals(2, data.length);
|
||||
assertEquals("abc", data[0]);
|
||||
assertEquals("public", data[1]);
|
||||
assertFalse("Should not have any more records", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -380,10 +381,10 @@ public class CSVParserTest {
|
|||
CSVParser parser = new CSVParser(code, CSVFormat.MYSQL.withUnicodeEscapesInterpreted(true));
|
||||
final Iterator<String[]> iterator = parser.iterator();
|
||||
String[] data = iterator.next();
|
||||
Assert.assertEquals(2, data.length);
|
||||
Assert.assertEquals("abc", data[0]);
|
||||
Assert.assertEquals("public", data[1]);
|
||||
Assert.assertFalse("Should not have any more records", iterator.hasNext());
|
||||
assertEquals(2, data.length);
|
||||
assertEquals("abc", data[0]);
|
||||
assertEquals("public", data[1]);
|
||||
assertFalse("Should not have any more records", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -391,7 +392,7 @@ public class CSVParserTest {
|
|||
String code = "foo\r\nbaar,\r\nhello,world\r\n,kanu";
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] data = parser.getRecords();
|
||||
Assert.assertEquals(4, data.length);
|
||||
assertEquals(4, data.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -399,7 +400,7 @@ public class CSVParserTest {
|
|||
String code = "foo\rbaar,\rhello,world\r,kanu";
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] data = parser.getRecords();
|
||||
Assert.assertEquals(4, data.length);
|
||||
assertEquals(4, data.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -407,7 +408,7 @@ public class CSVParserTest {
|
|||
String code = "foo\nbaar,\nhello,world\n,kanu";
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] data = parser.getRecords();
|
||||
Assert.assertEquals(4, data.length);
|
||||
assertEquals(4, data.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -417,7 +418,7 @@ public class CSVParserTest {
|
|||
//String code = "foo;baar\r\n\r\nhello;\r\n\r\nworld;\r\n";
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] data = parser.getRecords();
|
||||
Assert.assertEquals(3, data.length);
|
||||
assertEquals(3, data.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -430,10 +431,10 @@ public class CSVParserTest {
|
|||
records.add(record);
|
||||
}
|
||||
|
||||
Assert.assertEquals(3, records.size());
|
||||
Assert.assertTrue(Arrays.equals(new String[]{"a", "b", "c"}, records.get(0)));
|
||||
Assert.assertTrue(Arrays.equals(new String[]{"1", "2", "3"}, records.get(1)));
|
||||
Assert.assertTrue(Arrays.equals(new String[]{"x", "y", "z"}, records.get(2)));
|
||||
assertEquals(3, records.size());
|
||||
assertTrue(Arrays.equals(new String[]{"a", "b", "c"}, records.get(0)));
|
||||
assertTrue(Arrays.equals(new String[]{"1", "2", "3"}, records.get(1)));
|
||||
assertTrue(Arrays.equals(new String[]{"x", "y", "z"}, records.get(2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -442,23 +443,23 @@ public class CSVParserTest {
|
|||
|
||||
Iterator<String[]> iterator = CSVFormat.DEFAULT.parse(in).iterator();
|
||||
|
||||
Assert.assertTrue(iterator.hasNext());
|
||||
assertTrue(iterator.hasNext());
|
||||
try {
|
||||
iterator.remove();
|
||||
Assert.fail("expected UnsupportedOperationException");
|
||||
fail("expected UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
}
|
||||
Assert.assertTrue(Arrays.equals(new String[]{"a", "b", "c"}, iterator.next()));
|
||||
Assert.assertTrue(Arrays.equals(new String[]{"1", "2", "3"}, iterator.next()));
|
||||
Assert.assertTrue(iterator.hasNext());
|
||||
Assert.assertTrue(iterator.hasNext());
|
||||
Assert.assertTrue(iterator.hasNext());
|
||||
Assert.assertTrue(Arrays.equals(new String[]{"x", "y", "z"}, iterator.next()));
|
||||
Assert.assertFalse(iterator.hasNext());
|
||||
assertTrue(Arrays.equals(new String[]{"a", "b", "c"}, iterator.next()));
|
||||
assertTrue(Arrays.equals(new String[]{"1", "2", "3"}, iterator.next()));
|
||||
assertTrue(iterator.hasNext());
|
||||
assertTrue(iterator.hasNext());
|
||||
assertTrue(iterator.hasNext());
|
||||
assertTrue(Arrays.equals(new String[]{"x", "y", "z"}, iterator.next()));
|
||||
assertFalse(iterator.hasNext());
|
||||
|
||||
try {
|
||||
iterator.next();
|
||||
Assert.fail("NoSuchElementException expected");
|
||||
fail("NoSuchElementException expected");
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
|
|
|
@ -14,18 +14,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.csv;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* CSVPrinterTest
|
||||
*/
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CSVPrinterTest {
|
||||
|
||||
String lineSeparator = CSVFormat.DEFAULT.getLineSeparator();
|
||||
|
@ -35,7 +34,7 @@ public class CSVPrinterTest {
|
|||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
|
||||
printer.println("a", "b");
|
||||
Assert.assertEquals("a,b" + lineSeparator, sw.toString());
|
||||
assertEquals("a,b" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -43,7 +42,7 @@ public class CSVPrinterTest {
|
|||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
|
||||
printer.println("a,b", "b");
|
||||
Assert.assertEquals("\"a,b\",b" + lineSeparator, sw.toString());
|
||||
assertEquals("\"a,b\",b" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -51,7 +50,7 @@ public class CSVPrinterTest {
|
|||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
|
||||
printer.println("a, b", "b ");
|
||||
Assert.assertEquals("\"a, b\",\"b \"" + lineSeparator, sw.toString());
|
||||
assertEquals("\"a, b\",\"b \"" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -59,7 +58,7 @@ public class CSVPrinterTest {
|
|||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
|
||||
printer.println("a", "b\"c");
|
||||
Assert.assertEquals("a,\"b\"\"c\"" + lineSeparator, sw.toString());
|
||||
assertEquals("a,\"b\"\"c\"" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -67,7 +66,7 @@ public class CSVPrinterTest {
|
|||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
|
||||
printer.println("a", "b\nc");
|
||||
Assert.assertEquals("a,\"b\nc\"" + lineSeparator, sw.toString());
|
||||
assertEquals("a,\"b\nc\"" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -75,7 +74,7 @@ public class CSVPrinterTest {
|
|||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
|
||||
printer.println("a", "b\r\nc");
|
||||
Assert.assertEquals("a,\"b\r\nc\"" + lineSeparator, sw.toString());
|
||||
assertEquals("a,\"b\r\nc\"" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -83,7 +82,7 @@ public class CSVPrinterTest {
|
|||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
|
||||
printer.println("a", "b\\c");
|
||||
Assert.assertEquals("a,b\\c" + lineSeparator, sw.toString());
|
||||
assertEquals("a,b\\c" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -91,7 +90,7 @@ public class CSVPrinterTest {
|
|||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL);
|
||||
printer.println("a", "b");
|
||||
Assert.assertEquals("a,b" + lineSeparator, sw.toString());
|
||||
assertEquals("a,b" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -99,7 +98,7 @@ public class CSVPrinterTest {
|
|||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL);
|
||||
printer.println("a,b", "b");
|
||||
Assert.assertEquals("\"a,b\",b" + lineSeparator, sw.toString());
|
||||
assertEquals("\"a,b\",b" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -107,7 +106,7 @@ public class CSVPrinterTest {
|
|||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
|
||||
printer.println("a", null, "b");
|
||||
Assert.assertEquals("a,,b" + lineSeparator, sw.toString());
|
||||
assertEquals("a,,b" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -116,7 +115,7 @@ public class CSVPrinterTest {
|
|||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
|
||||
printer.printComment("This is a comment");
|
||||
|
||||
Assert.assertEquals("", sw.toString());
|
||||
assertEquals("", sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -125,7 +124,7 @@ public class CSVPrinterTest {
|
|||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentStart('#'));
|
||||
printer.printComment("This is a comment");
|
||||
|
||||
Assert.assertEquals("# This is a comment" + lineSeparator, sw.toString());
|
||||
assertEquals("# This is a comment" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -134,7 +133,7 @@ public class CSVPrinterTest {
|
|||
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentStart('#'));
|
||||
printer.printComment("This is a comment\non multiple lines");
|
||||
|
||||
Assert.assertEquals("# This is a comment" + lineSeparator + "# on multiple lines" + lineSeparator, sw.toString());
|
||||
assertEquals("# This is a comment" + lineSeparator + "# on multiple lines" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -183,7 +182,7 @@ public class CSVPrinterTest {
|
|||
|
||||
if (!equals(lines, parseResult)) {
|
||||
System.out.println("Printer output :" + printable(result));
|
||||
Assert.assertTrue(false);
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,69 +20,70 @@ package org.apache.commons.csv;
|
|||
import java.io.StringReader;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ExtendedBufferedReaderTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyInput() throws Exception {
|
||||
ExtendedBufferedReader br = getBufferedReader("");
|
||||
Assert.assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.read());
|
||||
Assert.assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.lookAhead());
|
||||
Assert.assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.readAgain());
|
||||
Assert.assertNull(br.readLine());
|
||||
Assert.assertEquals(0, br.read(new char[10], 0, 0));
|
||||
assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.read());
|
||||
assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.lookAhead());
|
||||
assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.readAgain());
|
||||
assertNull(br.readLine());
|
||||
assertEquals(0, br.read(new char[10], 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadLookahead1() throws Exception {
|
||||
ExtendedBufferedReader br = getBufferedReader("1\n2\r3\n");
|
||||
Assert.assertEquals('1', br.lookAhead());
|
||||
Assert.assertEquals(ExtendedBufferedReader.UNDEFINED, br.readAgain());
|
||||
Assert.assertEquals('1', br.read());
|
||||
Assert.assertEquals('1', br.readAgain());
|
||||
assertEquals('1', br.lookAhead());
|
||||
assertEquals(ExtendedBufferedReader.UNDEFINED, br.readAgain());
|
||||
assertEquals('1', br.read());
|
||||
assertEquals('1', br.readAgain());
|
||||
|
||||
Assert.assertEquals(0, br.getLineNumber());
|
||||
Assert.assertEquals('\n', br.lookAhead());
|
||||
Assert.assertEquals(0, br.getLineNumber());
|
||||
Assert.assertEquals('1', br.readAgain());
|
||||
Assert.assertEquals('\n', br.read());
|
||||
Assert.assertEquals(1, br.getLineNumber());
|
||||
Assert.assertEquals('\n', br.readAgain());
|
||||
Assert.assertEquals(1, br.getLineNumber());
|
||||
assertEquals(0, br.getLineNumber());
|
||||
assertEquals('\n', br.lookAhead());
|
||||
assertEquals(0, br.getLineNumber());
|
||||
assertEquals('1', br.readAgain());
|
||||
assertEquals('\n', br.read());
|
||||
assertEquals(1, br.getLineNumber());
|
||||
assertEquals('\n', br.readAgain());
|
||||
assertEquals(1, br.getLineNumber());
|
||||
|
||||
Assert.assertEquals('2', br.lookAhead());
|
||||
Assert.assertEquals(1, br.getLineNumber());
|
||||
Assert.assertEquals('\n', br.readAgain());
|
||||
Assert.assertEquals(1, br.getLineNumber());
|
||||
Assert.assertEquals('2', br.read());
|
||||
Assert.assertEquals('2', br.readAgain());
|
||||
assertEquals('2', br.lookAhead());
|
||||
assertEquals(1, br.getLineNumber());
|
||||
assertEquals('\n', br.readAgain());
|
||||
assertEquals(1, br.getLineNumber());
|
||||
assertEquals('2', br.read());
|
||||
assertEquals('2', br.readAgain());
|
||||
|
||||
Assert.assertEquals('\r', br.lookAhead());
|
||||
Assert.assertEquals('2', br.readAgain());
|
||||
Assert.assertEquals('\r', br.read());
|
||||
Assert.assertEquals('\r', br.readAgain());
|
||||
assertEquals('\r', br.lookAhead());
|
||||
assertEquals('2', br.readAgain());
|
||||
assertEquals('\r', br.read());
|
||||
assertEquals('\r', br.readAgain());
|
||||
|
||||
Assert.assertEquals('3', br.lookAhead());
|
||||
Assert.assertEquals('\r', br.readAgain());
|
||||
Assert.assertEquals('3', br.read());
|
||||
Assert.assertEquals('3', br.readAgain());
|
||||
assertEquals('3', br.lookAhead());
|
||||
assertEquals('\r', br.readAgain());
|
||||
assertEquals('3', br.read());
|
||||
assertEquals('3', br.readAgain());
|
||||
|
||||
Assert.assertEquals('\n', br.lookAhead());
|
||||
Assert.assertEquals(1, br.getLineNumber());
|
||||
Assert.assertEquals('3', br.readAgain());
|
||||
Assert.assertEquals('\n', br.read());
|
||||
Assert.assertEquals(2, br.getLineNumber());
|
||||
Assert.assertEquals('\n', br.readAgain());
|
||||
Assert.assertEquals(2, br.getLineNumber());
|
||||
assertEquals('\n', br.lookAhead());
|
||||
assertEquals(1, br.getLineNumber());
|
||||
assertEquals('3', br.readAgain());
|
||||
assertEquals('\n', br.read());
|
||||
assertEquals(2, br.getLineNumber());
|
||||
assertEquals('\n', br.readAgain());
|
||||
assertEquals(2, br.getLineNumber());
|
||||
|
||||
Assert.assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.lookAhead());
|
||||
Assert.assertEquals('\n', br.readAgain());
|
||||
Assert.assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.read());
|
||||
Assert.assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.readAgain());
|
||||
Assert.assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.read());
|
||||
Assert.assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.lookAhead());
|
||||
assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.lookAhead());
|
||||
assertEquals('\n', br.readAgain());
|
||||
assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.read());
|
||||
assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.readAgain());
|
||||
assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.read());
|
||||
assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.lookAhead());
|
||||
|
||||
}
|
||||
|
||||
|
@ -95,58 +96,58 @@ public class ExtendedBufferedReaderTest {
|
|||
ref[0] = 'a';
|
||||
ref[1] = 'b';
|
||||
ref[2] = 'c';
|
||||
Assert.assertEquals(3, br.read(res, 0, 3));
|
||||
Assert.assertTrue(Arrays.equals(res, ref));
|
||||
Assert.assertEquals('c', br.readAgain());
|
||||
assertEquals(3, br.read(res, 0, 3));
|
||||
assertTrue(Arrays.equals(res, ref));
|
||||
assertEquals('c', br.readAgain());
|
||||
|
||||
Assert.assertEquals('d', br.lookAhead());
|
||||
assertEquals('d', br.lookAhead());
|
||||
ref[4] = 'd';
|
||||
Assert.assertEquals(1, br.read(res, 4, 1));
|
||||
Assert.assertTrue(Arrays.equals(res, ref));
|
||||
Assert.assertEquals('d', br.readAgain());
|
||||
assertEquals(1, br.read(res, 4, 1));
|
||||
assertTrue(Arrays.equals(res, ref));
|
||||
assertEquals('d', br.readAgain());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadLine() throws Exception {
|
||||
ExtendedBufferedReader br = getBufferedReader("");
|
||||
Assert.assertTrue(br.readLine() == null);
|
||||
assertTrue(br.readLine() == null);
|
||||
|
||||
br = getBufferedReader("\n");
|
||||
Assert.assertTrue(br.readLine().equals(""));
|
||||
Assert.assertTrue(br.readLine() == null);
|
||||
assertTrue(br.readLine().equals(""));
|
||||
assertTrue(br.readLine() == null);
|
||||
|
||||
br = getBufferedReader("foo\n\nhello");
|
||||
Assert.assertEquals(0, br.getLineNumber());
|
||||
Assert.assertTrue(br.readLine().equals("foo"));
|
||||
Assert.assertEquals(1, br.getLineNumber());
|
||||
Assert.assertTrue(br.readLine().equals(""));
|
||||
Assert.assertEquals(2, br.getLineNumber());
|
||||
Assert.assertTrue(br.readLine().equals("hello"));
|
||||
Assert.assertEquals(3, br.getLineNumber());
|
||||
Assert.assertTrue(br.readLine() == null);
|
||||
Assert.assertEquals(3, br.getLineNumber());
|
||||
assertEquals(0, br.getLineNumber());
|
||||
assertTrue(br.readLine().equals("foo"));
|
||||
assertEquals(1, br.getLineNumber());
|
||||
assertTrue(br.readLine().equals(""));
|
||||
assertEquals(2, br.getLineNumber());
|
||||
assertTrue(br.readLine().equals("hello"));
|
||||
assertEquals(3, br.getLineNumber());
|
||||
assertTrue(br.readLine() == null);
|
||||
assertEquals(3, br.getLineNumber());
|
||||
|
||||
br = getBufferedReader("foo\n\nhello");
|
||||
Assert.assertEquals('f', br.read());
|
||||
Assert.assertEquals('o', br.lookAhead());
|
||||
Assert.assertTrue(br.readLine().equals("oo"));
|
||||
Assert.assertEquals(1, br.getLineNumber());
|
||||
Assert.assertEquals('\n', br.lookAhead());
|
||||
Assert.assertTrue(br.readLine().equals(""));
|
||||
Assert.assertEquals(2, br.getLineNumber());
|
||||
Assert.assertEquals('h', br.lookAhead());
|
||||
Assert.assertTrue(br.readLine().equals("hello"));
|
||||
Assert.assertTrue(br.readLine() == null);
|
||||
Assert.assertEquals(3, br.getLineNumber());
|
||||
assertEquals('f', br.read());
|
||||
assertEquals('o', br.lookAhead());
|
||||
assertTrue(br.readLine().equals("oo"));
|
||||
assertEquals(1, br.getLineNumber());
|
||||
assertEquals('\n', br.lookAhead());
|
||||
assertTrue(br.readLine().equals(""));
|
||||
assertEquals(2, br.getLineNumber());
|
||||
assertEquals('h', br.lookAhead());
|
||||
assertTrue(br.readLine().equals("hello"));
|
||||
assertTrue(br.readLine() == null);
|
||||
assertEquals(3, br.getLineNumber());
|
||||
|
||||
|
||||
br = getBufferedReader("foo\rbaar\r\nfoo");
|
||||
Assert.assertTrue(br.readLine().equals("foo"));
|
||||
Assert.assertEquals('b', br.lookAhead());
|
||||
Assert.assertTrue(br.readLine().equals("baar"));
|
||||
Assert.assertEquals('f', br.lookAhead());
|
||||
Assert.assertTrue(br.readLine().equals("foo"));
|
||||
Assert.assertTrue(br.readLine() == null);
|
||||
assertTrue(br.readLine().equals("foo"));
|
||||
assertEquals('b', br.lookAhead());
|
||||
assertTrue(br.readLine().equals("baar"));
|
||||
assertEquals('f', br.lookAhead());
|
||||
assertTrue(br.readLine().equals("foo"));
|
||||
assertTrue(br.readLine() == null);
|
||||
}
|
||||
|
||||
private ExtendedBufferedReader getBufferedReader(String s) {
|
||||
|
|
Loading…
Reference in New Issue