blob: 427004b8b15906ac9f4528e2758c9aa7ececcba8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package data.io;
import static org.junit.Assert.*;
import java.util.Iterator;
import org.apache.log4j.PropertyConfigurator;
import org.junit.BeforeClass;
import org.junit.Test;
import data.MVDataEntry;
import data.io.stub.StubDataReader;
public class SafeDataReaderTest {
private static final String LOG_PROPERTIES_FILE = "conf/log4j.properties";
@BeforeClass
public static void setup() {
PropertyConfigurator.configure(LOG_PROPERTIES_FILE);
}
@Test
public void testNoErrors() {
MVDataEntry testEntries[] = new MVDataEntry[5];
for (int i=0;i<5;i++) {
testEntries[i] = new MVDataEntry("line"+(i+1));
testEntries[i].put("attr1", "value"+(i+1));
}
StubDataReader src = new StubDataReader("testNoSkipErrors_src", testEntries);
StubDataReader expected = new StubDataReader("testNoSkipErrors_expected", testEntries);
SafeDataReader reader = new SafeDataReader(src, false);
// Test twice to check if asking a new iterator "rewinds" correctly
for (int i=0;i<2;i++) {
//System.out.println("Loop " + (i+1));
Iterator<MVDataEntry> readerIt = reader.iterator();
for ( MVDataEntry e: expected) {
assertTrue(readerIt.hasNext());
MVDataEntry r = readerIt.next();
//System.out.println(e + " / " + r);
assertEquals(e, r);
}
assertFalse(readerIt.hasNext());
}
}
//TODO Real tests with messy input readers (null values, exception, hasNext/next() incoherence)
}
|