Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 74ebd00

Browse files
author
sconway
committed
Update JUnit and tests to JUnit4.7
1 parent b2292b9 commit 74ebd00

10 files changed

+96
-62
lines changed

.classpath

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<classpath>
3-
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5-
<classpathentry kind="src" path="test"/>
6-
<classpathentry kind="lib" path="lib/junit.jar"/>
7-
<classpathentry kind="src" path="examples"/>
8-
<classpathentry kind="output" path="build/classes"/>
9-
</classpath>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="src" path="test"/>
6+
<classpathentry kind="src" path="examples"/>
7+
<classpathentry kind="var" path="M2_REPO/junit/junit/4.7/junit-4.7.jar"/>
8+
<classpathentry kind="output" path="build/classes"/>
9+
</classpath>

lib/junit-4.7.jar

227 KB
Binary file not shown.

lib/junit.jar

-118 KB
Binary file not shown.

test/au/com/bytecode/opencsv/CSVReaderTest.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import java.io.IOException;
2020
import java.io.StringReader;
2121

22+
import org.junit.Before;
23+
import org.junit.Test;
24+
2225
import junit.framework.TestCase;
2326

2427
public class CSVReaderTest extends TestCase {
@@ -29,6 +32,7 @@ public class CSVReaderTest extends TestCase {
2932
/**
3033
* Setup the test.
3134
*/
35+
@Before
3236
protected void setUp() throws Exception {
3337
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
3438
sb.append("a,b,c").append("\n"); // standard case
@@ -48,6 +52,7 @@ protected void setUp() throws Exception {
4852
* @throws IOException
4953
* if the reader fails.
5054
*/
55+
@Test
5156
public void testParseLine() throws IOException {
5257

5358
// test normal case
@@ -92,6 +97,7 @@ public void testParseLine() throws IOException {
9297
* @throws IOException
9398
* if the reader fails.
9499
*/
100+
@Test
95101
public void testParseAll() throws IOException {
96102
assertEquals(7, csvr.readAll().size());
97103
}
@@ -101,6 +107,7 @@ public void testParseAll() throws IOException {
101107
*
102108
* @throws IOException if the reader fails.
103109
*/
110+
@Test
104111
public void testOptionalConstructors() throws IOException {
105112

106113
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -122,6 +129,7 @@ public void testOptionalConstructors() throws IOException {
122129
*
123130
* @throws IOException if bad things happen
124131
*/
132+
@Test
125133
public void testSkippingLines() throws IOException {
126134

127135
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -141,6 +149,7 @@ public void testSkippingLines() throws IOException {
141149
*
142150
* @throws IOException if bad things happen
143151
*/
152+
@Test
144153
public void testParsedLineWithInternalQuota() throws IOException {
145154

146155
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -160,6 +169,7 @@ public void testParsedLineWithInternalQuota() throws IOException {
160169
* Test a normal non quoted line with three elements
161170
* @throws IOException
162171
*/
172+
@Test
163173
public void testNormalParsedLine() throws IOException {
164174

165175
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -181,6 +191,7 @@ public void testNormalParsedLine() throws IOException {
181191
* Test a line where one of the elements is a single Double quote "
182192
* @throws IOException
183193
*/
194+
@Test
184195
public void testADoubleQuoteAsDataElement() throws IOException {
185196

186197
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -203,6 +214,7 @@ public void testADoubleQuoteAsDataElement() throws IOException {
203214
* Test a line where one of the elements is a single Double quote "
204215
* @throws IOException
205216
*/
217+
@Test
206218
public void testEscapedDoubleQuoteAsDataElement() throws IOException {
207219

208220
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -226,6 +238,7 @@ public void testEscapedDoubleQuoteAsDataElement() throws IOException {
226238
* single quote.
227239
* @throws IOException
228240
*/
241+
@Test
229242
public void testASingleQuoteAsDataElement() throws IOException {
230243

231244
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -249,6 +262,7 @@ public void testASingleQuoteAsDataElement() throws IOException {
249262
* single quote. Also the middle field is empty.
250263
* @throws IOException
251264
*/
265+
@Test
252266
public void testASingleQuoteAsDataElementWithEmptyField() throws IOException {
253267

254268
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -274,6 +288,7 @@ public void testASingleQuoteAsDataElementWithEmptyField() throws IOException {
274288
* @throws IOException
275289
*
276290
*/
291+
@Test
277292
public void testIssue2263439() throws IOException {
278293

279294
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -294,6 +309,7 @@ public void testIssue2263439() throws IOException {
294309

295310
}
296311

312+
@Test
297313
public void testEscapedQuote() throws IOException {
298314

299315
StringBuffer sb = new StringBuffer();
@@ -309,6 +325,7 @@ public void testEscapedQuote() throws IOException {
309325

310326
}
311327

328+
@Test
312329
public void testEscapedEscape() throws IOException {
313330

314331
StringBuffer sb = new StringBuffer();
@@ -331,6 +348,7 @@ public void testEscapedEscape() throws IOException {
331348
* single quotes.
332349
* @throws IOException
333350
*/
351+
@Test
334352
public void testSingleQuoteWhenDoubleQuoteIsQuoteChar() throws IOException {
335353

336354
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -353,6 +371,7 @@ public void testSingleQuoteWhenDoubleQuoteIsQuoteChar() throws IOException {
353371
* Test a normal line with three elements and all elements are quoted
354372
* @throws IOException
355373
*/
374+
@Test
356375
public void testQuotedParsedLine() throws IOException {
357376

358377
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);
@@ -380,7 +399,7 @@ public void testQuotedParsedLine() throws IOException {
380399
* "804503689","London",""London""shop","address","116.453182","39.918884"
381400
* "453074125","NewYork","brief","address"","121.514683","31.228511"
382401
*/
383-
402+
@Test
384403
public void testIssue2726363()throws IOException {
385404

386405
StringBuilder sb = new StringBuilder(CSVReader.INITIAL_READ_SIZE);

test/au/com/bytecode/opencsv/CSVWriterTest.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.ArrayList;
2626
import java.util.List;
2727

28+
import org.junit.Test;
29+
2830
import junit.framework.TestCase;
2931

3032
public class CSVWriterTest extends TestCase {
@@ -53,6 +55,7 @@ private String invokeWriter(String[] args) throws IOException {
5355
* @throws IOException
5456
* if the reader fails.
5557
*/
58+
@Test
5659
public void testParseLine() throws IOException {
5760

5861
// test normal case
@@ -83,6 +86,7 @@ public void testParseLine() throws IOException {
8386
* @throws IOException
8487
* if the reader fails.
8588
*/
89+
@Test
8690
public void testParseAll() throws IOException {
8791

8892
List<String[]> allElements = new ArrayList<String[]>();
@@ -109,6 +113,7 @@ public void testParseAll() throws IOException {
109113
*
110114
* @throws IOException if bad things happen
111115
*/
116+
@Test
112117
public void testNoQuoteChars() throws IOException {
113118

114119
String[] line = {"Foo","Bar","Baz"};
@@ -125,7 +130,7 @@ public void testNoQuoteChars() throws IOException {
125130
*
126131
* @throws IOException if bad things happen
127132
*/
128-
133+
@Test
129134
public void testNullValues() throws IOException {
130135

131136
String[] line = {"Foo",null,"Bar","baz"};
@@ -137,7 +142,8 @@ public void testNullValues() throws IOException {
137142
assertEquals("\"Foo\",,\"Bar\",\"baz\"\n",result);
138143

139144
}
140-
145+
146+
@Test
141147
public void testStreamFlushing() throws IOException {
142148

143149
String WRITE_FILE = "myfile.csv";
@@ -153,15 +159,17 @@ public void testStreamFlushing() throws IOException {
153159
writer.close();
154160

155161
}
156-
162+
163+
@Test
157164
public void testAlternateEscapeChar() {
158165
String[] line = {"Foo","bar's"};
159166
StringWriter sw = new StringWriter();
160167
CSVWriter csvw = new CSVWriter(sw,CSVWriter.DEFAULT_SEPARATOR,CSVWriter.DEFAULT_QUOTE_CHARACTER,'\'');
161168
csvw.writeNext(line);
162169
assertEquals("\"Foo\",\"bar''s\"\n",sw.toString());
163170
}
164-
171+
172+
@Test
165173
public void testNoQuotingNoEscaping() {
166174
String[] line = {"\"Foo\",\"Bar\""};
167175
StringWriter sw = new StringWriter();
@@ -170,7 +178,7 @@ public void testNoQuotingNoEscaping() {
170178
assertEquals("\"Foo\",\"Bar\"\n",sw.toString());
171179
}
172180

173-
181+
@Test
174182
public void testNestedQuotes(){
175183
String[] data = new String[]{"\"\"", "test"};
176184
String oracle = new String("\"\"\"\"\"\",\"test\"\n");
@@ -227,7 +235,7 @@ public void testNestedQuotes(){
227235
assertTrue(oracle.equals(fileContents.toString()));
228236
}
229237

230-
238+
@Test
231239
public void testAlternateLineFeeds() {
232240
String[] line = {"Foo","Bar","baz"};
233241
StringWriter sw = new StringWriter();

test/au/com/bytecode/opencsv/OpencsvTest.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,33 @@
1616
limitations under the License.
1717
*/
1818

19+
import static org.junit.Assert.assertTrue;
20+
1921
import java.io.File;
2022
import java.io.FileReader;
2123
import java.io.FileWriter;
2224
import java.io.IOException;
2325

24-
import junit.framework.TestCase;
26+
import org.junit.Before;
27+
import org.junit.Test;
2528

26-
public class OpencsvTest extends TestCase {
29+
public class OpencsvTest {
2730

2831
private File tempFile = null;
2932
private CSVWriter writer = null;
3033
private CSVReader reader = null;
3134

32-
protected void setUp() throws Exception {
33-
super.setUp();
34-
35-
try {
36-
tempFile = File.createTempFile("csvWriterTest", ".csv");
37-
tempFile.deleteOnExit();
38-
// System.out.println("filename: "+tempFile.getAbsolutePath());
39-
} catch (IOException e) {
40-
fail();
41-
}
35+
@Before
36+
public void setUp() throws IOException {
37+
tempFile = File.createTempFile("csvWriterTest", ".csv");
38+
tempFile.deleteOnExit();
4239
}
4340

4441
/**
4542
* Test the full cycle of write-read
4643
*
4744
*/
45+
@Test
4846
public void testWriteRead() throws IOException {
4947
final String[][] data = new String[][]{{"hello, a test", "one nested \" test"}, {"\"\"", "test", null, "8"}};
5048

test/au/com/bytecode/opencsv/bean/ColumnPositionMappingStrategyTest.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,33 @@
1717
*/
1818

1919

20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertTrue;
23+
2024
import java.io.StringReader;
2125
import java.util.List;
2226

23-
import au.com.bytecode.opencsv.bean.ColumnPositionMappingStrategy;
24-
import au.com.bytecode.opencsv.bean.CsvToBean;
25-
26-
import junit.framework.TestCase;
27+
import org.junit.Test;
2728

2829

29-
public class ColumnPositionMappingStrategyTest extends TestCase {
30+
public class ColumnPositionMappingStrategyTest {
3031

32+
@Test
3133
public void testParse() {
3234
String s = "" +
3335
"kyle,123456,emp123\n" +
3436
"jimmy,abcnum,cust09878";
35-
ColumnPositionMappingStrategy<TestBean> strat = new ColumnPositionMappingStrategy<TestBean>();
36-
strat.setType(TestBean.class);
37+
ColumnPositionMappingStrategy<MockBean> strat = new ColumnPositionMappingStrategy<MockBean>();
38+
strat.setType(MockBean.class);
3739
String[] columns = new String[] {"name", "orderNumber", "id"};
3840
strat.setColumnMapping(columns);
3941

40-
CsvToBean<TestBean> csv = new CsvToBean<TestBean>();
41-
List<TestBean> list = csv.parse(strat, new StringReader(s));
42+
CsvToBean<MockBean> csv = new CsvToBean<MockBean>();
43+
List<MockBean> list = csv.parse(strat, new StringReader(s));
4244
assertNotNull(list);
4345
assertTrue(list.size() == 2);
44-
TestBean bean = list.get(0);
46+
MockBean bean = list.get(0);
4547
assertEquals("kyle", bean.getName());
4648
assertEquals("123456", bean.getOrderNumber());
4749
assertEquals("emp123", bean.getId());

0 commit comments

Comments
 (0)