Iterator<Record2> it2 = r2.iterator();
assertNotNull(it2);
assertTrue(it2.hasNext());
int c2 = 0;
while (it2.hasNext()) {
Record2 rec = it2.next();
assertNotNull(rec);
if (c2 == 0) {
assertEquals("48882467972", rec.getCustomer());
} else if (c2 == 3) {
assertEquals("agdvr\"g;;;r", rec.getCustomer());
}
c2++;
}
assertTrue(c2 >= 4);
r2.closeResources();
// CsvTestRecord reader from string
CsvReader<CsvTestRecord2> r3 = new CsvReader<CsvTestRecord2>(new StringReader("1;2;3;31.12.2008\n3;4\n5;6"), CsvTestRecord2.class);
assertNotNull(r3);
Iterator<CsvTestRecord2> it3 = r3.iterator();
assertNotNull(it3);
assertTrue(it3.hasNext());
int c3 = 0;
while (it3.hasNext()) {
CsvTestRecord rec = it3.next();
assertNotNull(rec);
if (c3 == 0) {
assertEquals("1", rec.getField1());
assertEquals(2, rec.getField2());
} else if (c3 == 1) {
assertEquals("3", rec.getField1());
assertEquals(4, rec.getField2());
} else if (c3 == 2) {
assertEquals("5", rec.getField1());
assertEquals(6, rec.getField2());
assertFalse(it3.hasNext());
} else {
fail();
}
c3++;
}
assertEquals(3, c3);
r3.closeResources();
// CsvTestRecord reader with array parsing
CsvReader<CsvTestRecord3> r4 = new CsvReader<CsvTestRecord3>(
new StringReader("1;2;3;31.12.2008;" + TestEnum.CCC.name() + ";a1;a2;a3;a4\n3;4;;;" + TestEnum.BBB.name() + ";b1;b2;b3\n5;6"),
CsvTestRecord3.class);
assertNotNull(r4);
Iterator<CsvTestRecord3> it4 = r4.iterator();
assertNotNull(it4);
assertTrue(it4.hasNext());
int c4 = 0;
while (it4.hasNext()) {
CsvTestRecord3 rec = it4.next();
assertNotNull(rec);
if (c4 == 0) {
assertEquals("1", rec.getField1());
assertEquals(2, rec.getField2());
assertEquals(TestEnum.CCC, rec.getField5());
assertEquals(4, rec.getField6().size());
assertTrue(rec.getField6().get(0).equals("a1"));
assertTrue(rec.getField6().get(1).equals("a2"));
assertTrue(rec.getField6().get(2).equals("a3"));
assertTrue(rec.getField6().get(3).equals("a4"));
} else if (c4 == 1) {
assertEquals("3", rec.getField1());
assertEquals(4, rec.getField2());
assertEquals(TestEnum.BBB, rec.getField5());
assertEquals(3, rec.getField6().size());
assertTrue(rec.getField6().get(0).equals("b1"));
assertTrue(rec.getField6().get(1).equals("b2"));
assertTrue(rec.getField6().get(2).equals("b3"));
} else if (c4 == 2) {
assertEquals("5", rec.getField1());
assertEquals(6, rec.getField2());
assertFalse(it4.hasNext());
assertNull(rec.getField5());
} else {
fail();
}
c4++;
}