Skip to content

Commit 186e9f9

Browse files
committed
Update to JUnit 4.10 from 3.8.1.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1300977 13f79535-47bb-0310-9956-ffa450edef68
1 parent 38670db commit 186e9f9

6 files changed

Lines changed: 278 additions & 223 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>junit</groupId>
1818
<artifactId>junit</artifactId>
19-
<version>3.8.1</version>
19+
<version>4.10</version>
2020
<scope>test</scope>
2121
</dependency>
2222
</dependencies>

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import java.io.ObjectInputStream;
2323
import java.io.ObjectOutputStream;
2424

25-
import junit.framework.TestCase;
25+
import org.junit.Assert;
26+
import org.junit.Test;
2627

27-
public class CSVFormatTest extends TestCase {
28+
public class CSVFormatTest {
2829

30+
@Test
2931
public void testImmutalibity() {
3032
CSVFormat format = new CSVFormat('!', '!', '!', '!', true, true, true, true, "\r\n");
3133

@@ -39,91 +41,94 @@ public void testImmutalibity() {
3941
format.withEmptyLinesIgnored(false);
4042
format.withUnicodeEscapesInterpreted(false);
4143

42-
assertEquals('!', format.getDelimiter());
43-
assertEquals('!', format.getEncapsulator());
44-
assertEquals('!', format.getCommentStart());
45-
assertEquals('!', format.getEscape());
46-
assertEquals("\r\n", format.getLineSeparator());
44+
Assert.assertEquals('!', format.getDelimiter());
45+
Assert.assertEquals('!', format.getEncapsulator());
46+
Assert.assertEquals('!', format.getCommentStart());
47+
Assert.assertEquals('!', format.getEscape());
48+
Assert.assertEquals("\r\n", format.getLineSeparator());
4749

48-
assertEquals(true, format.isLeadingSpacesIgnored());
49-
assertEquals(true, format.isTrailingSpacesIgnored());
50-
assertEquals(true, format.isEmptyLinesIgnored());
51-
assertEquals(true, format.isUnicodeEscapesInterpreted());
50+
Assert.assertEquals(true, format.isLeadingSpacesIgnored());
51+
Assert.assertEquals(true, format.isTrailingSpacesIgnored());
52+
Assert.assertEquals(true, format.isEmptyLinesIgnored());
53+
Assert.assertEquals(true, format.isUnicodeEscapesInterpreted());
5254
}
5355

56+
@Test
5457
public void testMutators() {
5558
CSVFormat format = new CSVFormat('!', '!', '!', '!', true, true, true, true, "\r\n");
5659

57-
assertEquals('?', format.withDelimiter('?').getDelimiter());
58-
assertEquals('?', format.withEncapsulator('?').getEncapsulator());
59-
assertEquals('?', format.withCommentStart('?').getCommentStart());
60-
assertEquals("?", format.withLineSeparator("?").getLineSeparator());
61-
assertEquals('?', format.withEscape('?').getEscape());
62-
63-
assertEquals(false, format.withLeadingSpacesIgnored(false).isLeadingSpacesIgnored());
64-
assertEquals(false, format.withTrailingSpacesIgnored(false).isTrailingSpacesIgnored());
65-
assertEquals(false, format.withSurroundingSpacesIgnored(false).isLeadingSpacesIgnored());
66-
assertEquals(false, format.withSurroundingSpacesIgnored(false).isTrailingSpacesIgnored());
67-
assertEquals(false, format.withEmptyLinesIgnored(false).isEmptyLinesIgnored());
68-
assertEquals(false, format.withUnicodeEscapesInterpreted(false).isUnicodeEscapesInterpreted());
60+
Assert.assertEquals('?', format.withDelimiter('?').getDelimiter());
61+
Assert.assertEquals('?', format.withEncapsulator('?').getEncapsulator());
62+
Assert.assertEquals('?', format.withCommentStart('?').getCommentStart());
63+
Assert.assertEquals("?", format.withLineSeparator("?").getLineSeparator());
64+
Assert.assertEquals('?', format.withEscape('?').getEscape());
65+
66+
Assert.assertEquals(false, format.withLeadingSpacesIgnored(false).isLeadingSpacesIgnored());
67+
Assert.assertEquals(false, format.withTrailingSpacesIgnored(false).isTrailingSpacesIgnored());
68+
Assert.assertEquals(false, format.withSurroundingSpacesIgnored(false).isLeadingSpacesIgnored());
69+
Assert.assertEquals(false, format.withSurroundingSpacesIgnored(false).isTrailingSpacesIgnored());
70+
Assert.assertEquals(false, format.withEmptyLinesIgnored(false).isEmptyLinesIgnored());
71+
Assert.assertEquals(false, format.withUnicodeEscapesInterpreted(false).isUnicodeEscapesInterpreted());
6972
}
7073

74+
@Test
7175
public void testFormat() {
7276
CSVFormat format = CSVFormat.DEFAULT;
7377

74-
assertEquals("", format.format());
75-
assertEquals("a,b,c", format.format("a", "b", "c"));
76-
assertEquals("\"x,y\",z", format.format("x,y", "z"));
78+
Assert.assertEquals("", format.format());
79+
Assert.assertEquals("a,b,c", format.format("a", "b", "c"));
80+
Assert.assertEquals("\"x,y\",z", format.format("x,y", "z"));
7781
}
7882

83+
@Test
7984
public void testValidation() {
8085
CSVFormat format = CSVFormat.DEFAULT;
8186

8287
try {
8388
format.withDelimiter('\n');
84-
fail();
89+
Assert.fail();
8590
} catch (IllegalArgumentException e) {
8691
// expected
8792
}
8893

8994
try {
9095
format.withEscape('\r');
91-
fail();
96+
Assert.fail();
9297
} catch (IllegalArgumentException e) {
9398
// expected
9499
}
95100

96101
try {
97102
format.withEncapsulator('\n');
98-
fail();
103+
Assert.fail();
99104
} catch (IllegalArgumentException e) {
100105
// expected
101106
}
102107

103108
try {
104109
format.withCommentStart('\r');
105-
fail();
110+
Assert.fail();
106111
} catch (IllegalArgumentException e) {
107112
// expected
108113
}
109114

110115
try {
111116
format.withDelimiter('!').withEscape('!').validate();
112-
fail();
117+
Assert.fail();
113118
} catch (IllegalArgumentException e) {
114119
// expected
115120
}
116121

117122
try {
118123
format.withDelimiter('!').withCommentStart('!').validate();
119-
fail();
124+
Assert.fail();
120125
} catch (IllegalArgumentException e) {
121126
// expected
122127
}
123128

124129
try {
125130
format.withEncapsulator('!').withCommentStart('!').validate();
126-
fail();
131+
Assert.fail();
127132
} catch (IllegalArgumentException e) {
128133
// expected
129134
}
@@ -132,7 +137,7 @@ public void testValidation() {
132137

133138
try {
134139
format.withEscape('!').withCommentStart('!').validate();
135-
fail();
140+
Assert.fail();
136141
} catch (IllegalArgumentException e) {
137142
// expected
138143
}
@@ -142,12 +147,13 @@ public void testValidation() {
142147

143148
try {
144149
format.withEncapsulator('!').withDelimiter('!').validate();
145-
fail();
150+
Assert.fail();
146151
} catch (IllegalArgumentException e) {
147152
// expected
148153
}
149154
}
150155

156+
@Test
151157
public void testSerialization() throws Exception {
152158
ByteArrayOutputStream out = new ByteArrayOutputStream();
153159

@@ -159,15 +165,15 @@ public void testSerialization() throws Exception {
159165
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
160166
CSVFormat format = (CSVFormat) in.readObject();
161167

162-
assertNotNull(format);
163-
assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
164-
assertEquals("encapsulator", CSVFormat.DEFAULT.getEncapsulator(), format.getEncapsulator());
165-
assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
166-
assertEquals("line separator", CSVFormat.DEFAULT.getLineSeparator(), format.getLineSeparator());
167-
assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());
168-
assertEquals("unicode escape", CSVFormat.DEFAULT.isUnicodeEscapesInterpreted(), format.isUnicodeEscapesInterpreted());
169-
assertEquals("trim left", CSVFormat.DEFAULT.isLeadingSpacesIgnored(), format.isLeadingSpacesIgnored());
170-
assertEquals("trim right", CSVFormat.DEFAULT.isTrailingSpacesIgnored(), format.isTrailingSpacesIgnored());
171-
assertEquals("empty lines", CSVFormat.DEFAULT.isEmptyLinesIgnored(), format.isEmptyLinesIgnored());
168+
Assert.assertNotNull(format);
169+
Assert.assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
170+
Assert.assertEquals("encapsulator", CSVFormat.DEFAULT.getEncapsulator(), format.getEncapsulator());
171+
Assert.assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
172+
Assert.assertEquals("line separator", CSVFormat.DEFAULT.getLineSeparator(), format.getLineSeparator());
173+
Assert.assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());
174+
Assert.assertEquals("unicode escape", CSVFormat.DEFAULT.isUnicodeEscapesInterpreted(), format.isUnicodeEscapesInterpreted());
175+
Assert.assertEquals("trim left", CSVFormat.DEFAULT.isLeadingSpacesIgnored(), format.isLeadingSpacesIgnored());
176+
Assert.assertEquals("trim right", CSVFormat.DEFAULT.isTrailingSpacesIgnored(), format.isTrailingSpacesIgnored());
177+
Assert.assertEquals("empty lines", CSVFormat.DEFAULT.isEmptyLinesIgnored(), format.isEmptyLinesIgnored());
172178
}
173179
}

src/test/java/org/apache/commons/csv/CSVLexerTest.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,30 @@
1717

1818
package org.apache.commons.csv;
1919

20+
import static org.apache.commons.csv.CSVLexer.Token.Type.EOF;
21+
import static org.apache.commons.csv.CSVLexer.Token.Type.EORECORD;
22+
import static org.apache.commons.csv.CSVLexer.Token.Type.TOKEN;
23+
2024
import java.io.IOException;
2125
import java.io.StringReader;
2226

23-
import junit.framework.TestCase;
2427
import org.apache.commons.csv.CSVLexer.Token;
28+
import org.junit.Assert;
29+
import org.junit.Test;
2530

26-
import static org.apache.commons.csv.CSVLexer.Token.Type.*;
27-
28-
public class CSVLexerTest extends TestCase {
31+
public class CSVLexerTest {
2932

3033
private CSVLexer getLexer(String input, CSVFormat format) {
3134
return new CSVLexer(format, new ExtendedBufferedReader(new StringReader(input)));
3235
}
3336

3437
private void assertTokenEquals(Token.Type expectedType, String expectedContent, Token token) {
35-
assertEquals("Token type", expectedType, token.type);
36-
assertEquals("Token content", expectedContent, token.content.toString());
38+
Assert.assertEquals("Token type", expectedType, token.type);
39+
Assert.assertEquals("Token content", expectedContent, token.content.toString());
3740
}
3841

3942
// Single line (without comment)
43+
@Test
4044
public void testNextToken1() throws IOException {
4145
String code = "abc,def, hijk, lmnop, qrst,uv ,wxy ,z , ,";
4246
CSVLexer parser = getLexer(code, CSVFormat.DEFAULT);
@@ -53,6 +57,7 @@ public void testNextToken1() throws IOException {
5357
}
5458

5559
// multiline including comments (and empty lines)
60+
@Test
5661
public void testNextToken2() throws IOException {
5762
/* file: 1,2,3,
5863
* a,b x,c
@@ -84,6 +89,7 @@ public void testNextToken2() throws IOException {
8489
}
8590

8691
// simple token with escaping
92+
@Test
8793
public void testNextToken3() throws IOException {
8894
/* file: a,\,,b
8995
* \,,
@@ -104,6 +110,7 @@ public void testNextToken3() throws IOException {
104110
}
105111

106112
// encapsulator tokenizer (sinle line)
113+
@Test
107114
public void testNextToken4() throws IOException {
108115
/* file: a,"foo",b
109116
* a, " foo",b
@@ -128,6 +135,7 @@ public void testNextToken4() throws IOException {
128135
}
129136

130137
// encapsulator tokenizer (multi line, delimiter in string)
138+
@Test
131139
public void testNextToken5() throws IOException {
132140
String code = "a,\"foo\n\",b\n\"foo\n baar ,,,\"\n\"\n\t \n\"";
133141
CSVLexer parser = getLexer(code, CSVFormat.DEFAULT);
@@ -140,6 +148,7 @@ public void testNextToken5() throws IOException {
140148
}
141149

142150
// change delimiters, comment, encapsulater
151+
@Test
143152
public void testNextToken6() throws IOException {
144153
/* file: a;'b and \' more
145154
* '
@@ -154,6 +163,7 @@ public void testNextToken6() throws IOException {
154163
}
155164

156165
// From CSV-1
166+
@Test
157167
public void testDelimiterIsWhitespace() throws IOException {
158168
String code = "one\ttwo\t\tfour \t five\t six";
159169
CSVLexer parser = getLexer(code, CSVFormat.TDF);

0 commit comments

Comments
 (0)