|
0 |
/*
|
|
1 |
* Java CSV is a stream based library for reading and writing
|
|
2 |
* CSV and other delimited data.
|
|
3 |
*
|
|
4 |
* Copyright (C) Bruce Dunwiddie bruce@csvreader.com
|
|
5 |
*
|
|
6 |
* This library is free software; you can redistribute it and/or
|
|
7 |
* modify it under the terms of the GNU Lesser General Public
|
|
8 |
* License as published by the Free Software Foundation; either
|
|
9 |
* version 2.1 of the License, or (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This library is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 |
* Lesser General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU Lesser General Public
|
|
17 |
* License along with this library; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
19 |
*/
|
0 | 20 |
import java.io.BufferedReader;
|
1 | 21 |
import java.io.ByteArrayInputStream;
|
2 | 22 |
import java.io.ByteArrayOutputStream;
|
|
27 | 47 |
|
28 | 48 |
public class AllTests {
|
29 | 49 |
public static void main(String[] args) throws Exception {
|
30 | |
Class testClass = AllTests.class;
|
|
50 |
Class<AllTests> testClass = AllTests.class;
|
31 | 51 |
ArrayList<Method> setups = new ArrayList<Method>();
|
32 | 52 |
ArrayList<Method> tearDowns = new ArrayList<Method>();
|
33 | 53 |
|
|
62 | 82 |
setup.invoke(instance, (Object[]) null);
|
63 | 83 |
}
|
64 | 84 |
|
65 | |
Class expectedException = testAnnotation.expected();
|
|
85 |
Class<?> expectedException = testAnnotation.expected();
|
66 | 86 |
|
67 | 87 |
// can't for the life of me get eclipse to be able to
|
68 | 88 |
// resolve Test.None directly
|
|
651 | 671 |
new OutputStreamWriter(new FileOutputStream("temp.csv"),
|
652 | 672 |
Charset.forName("UTF-8"))), ',');
|
653 | 673 |
// writer will trim all whitespace and put this in quotes to preserve
|
654 | |
// it's existance
|
|
674 |
// it's existence
|
655 | 675 |
writer.write(" \t \t");
|
656 | 676 |
writer.close();
|
657 | 677 |
|
|
1423 | 1443 |
@Test
|
1424 | 1444 |
public void test76() throws Exception {
|
1425 | 1445 |
CsvReader reader = CsvReader.parse("user_id,name\r\n1,Bruce");
|
1426 | |
Assert.assertEquals(null, reader.getHeaders());
|
|
1446 |
Assert.assertNull(reader.getHeaders());
|
1427 | 1447 |
Assert.assertEquals(-1, reader.getIndex("user_id"));
|
1428 | 1448 |
Assert.assertEquals("", reader.getHeader(0));
|
1429 | 1449 |
Assert.assertTrue(reader.readHeaders());
|
|
1434 | 1454 |
Assert.assertEquals("user_id", headers[0]);
|
1435 | 1455 |
Assert.assertEquals("name", headers[1]);
|
1436 | 1456 |
reader.setHeaders(null);
|
1437 | |
Assert.assertEquals(null, reader.getHeaders());
|
|
1457 |
Assert.assertNull(reader.getHeaders());
|
1438 | 1458 |
Assert.assertEquals(-1, reader.getIndex("user_id"));
|
1439 | 1459 |
Assert.assertEquals("", reader.getHeader(0));
|
1440 | 1460 |
reader.close();
|
|
1575 | 1595 |
@Test
|
1576 | 1596 |
public void test88() throws Exception {
|
1577 | 1597 |
try {
|
1578 | |
CsvReader reader = new CsvReader((String) null, ',', Charset
|
|
1598 |
new CsvReader((String) null, ',', Charset
|
1579 | 1599 |
.forName("ISO-8859-1"));
|
1580 | 1600 |
} catch (Exception ex) {
|
1581 | 1601 |
assertException(new IllegalArgumentException(
|
|
1586 | 1606 |
@Test
|
1587 | 1607 |
public void test89() throws Exception {
|
1588 | 1608 |
try {
|
1589 | |
CsvReader reader = new CsvReader("temp.csv", ',', null);
|
|
1609 |
new CsvReader("temp.csv", ',', null);
|
1590 | 1610 |
} catch (Exception ex) {
|
1591 | 1611 |
assertException(new IllegalArgumentException(
|
1592 | 1612 |
"Parameter charset can not be null."), ex);
|
|
1596 | 1616 |
@Test
|
1597 | 1617 |
public void test90() throws Exception {
|
1598 | 1618 |
try {
|
1599 | |
CsvReader reader = new CsvReader((Reader) null, ',');
|
|
1619 |
new CsvReader((Reader) null, ',');
|
1600 | 1620 |
} catch (Exception ex) {
|
1601 | 1621 |
assertException(new IllegalArgumentException(
|
1602 | 1622 |
"Parameter inputStream can not be null."), ex);
|
|
1648 | 1668 |
@Test
|
1649 | 1669 |
public void test112() throws Exception {
|
1650 | 1670 |
try {
|
1651 | |
CsvWriter writer = new CsvWriter((String) null, ',', Charset
|
|
1671 |
new CsvWriter((String) null, ',', Charset
|
1652 | 1672 |
.forName("ISO-8859-1"));
|
1653 | 1673 |
} catch (Exception ex) {
|
1654 | 1674 |
assertException(new IllegalArgumentException("Parameter fileName can not be null."), ex);
|
|
1658 | 1678 |
@Test
|
1659 | 1679 |
public void test113() throws Exception {
|
1660 | 1680 |
try {
|
1661 | |
CsvWriter writer = new CsvWriter("test.csv", ',', (Charset) null);
|
|
1681 |
new CsvWriter("test.csv", ',', (Charset) null);
|
1662 | 1682 |
} catch (Exception ex) {
|
1663 | 1683 |
assertException(new IllegalArgumentException("Parameter charset can not be null."), ex);
|
1664 | 1684 |
}
|
|
1667 | 1687 |
@Test
|
1668 | 1688 |
public void test114() throws Exception {
|
1669 | 1689 |
try {
|
1670 | |
CsvWriter writer = new CsvWriter((Writer) null, ',');
|
|
1690 |
new CsvWriter((Writer) null, ',');
|
1671 | 1691 |
} catch (Exception ex) {
|
1672 | 1692 |
assertException(new IllegalArgumentException("Parameter outputStream can not be null."), ex);
|
1673 | 1693 |
}
|
|
2158 | 2178 |
public void test149() throws Exception {
|
2159 | 2179 |
try
|
2160 | 2180 |
{
|
2161 | |
CsvReader reader = new CsvReader("C:\\somefilethatdoesntexist.csv");
|
|
2181 |
new CsvReader("C:\\somefilethatdoesntexist.csv");
|
2162 | 2182 |
}
|
2163 | 2183 |
catch (Exception ex)
|
2164 | 2184 |
{
|
|
2179 | 2199 |
reader.readRecord();
|
2180 | 2200 |
} catch (IOException ex) {
|
2181 | 2201 |
// make sure stream that caused exception
|
2182 | |
// has been sent a dipose call
|
|
2202 |
// has been sent a dispose call
|
2183 | 2203 |
Assert.assertTrue(fail.DisposeCalled);
|
2184 | 2204 |
exceptionThrown = true;
|
2185 | 2205 |
Assert.assertEquals("Read failed.", ex.getMessage());
|
|
2216 | 2236 |
DisposeCalled = true;
|
2217 | 2237 |
}
|
2218 | 2238 |
}
|
|
2239 |
|
|
2240 |
@Test
|
|
2241 |
public void Test174() throws IOException {
|
|
2242 |
// verifies that data is eventually automatically flushed
|
|
2243 |
CsvWriter writer = new CsvWriter("temp.csv");
|
|
2244 |
|
|
2245 |
for (int i = 0; i < 10000; i++)
|
|
2246 |
{
|
|
2247 |
writer.write("stuff");
|
|
2248 |
writer.endRecord();
|
|
2249 |
}
|
|
2250 |
|
|
2251 |
CsvReader reader = new CsvReader("temp.csv");
|
|
2252 |
|
|
2253 |
Assert.assertTrue(reader.readRecord());
|
|
2254 |
|
|
2255 |
Assert.assertEquals("stuff", reader.get(0));
|
|
2256 |
|
|
2257 |
writer.close();
|
|
2258 |
reader.close();
|
|
2259 |
|
|
2260 |
new File("temp.csv").delete();
|
|
2261 |
}
|
2219 | 2262 |
}
|