1
|
package eu.dnetlib.enabling.resultset;
|
2
|
|
3
|
import static org.junit.Assert.*;
|
4
|
|
5
|
import java.util.ArrayList;
|
6
|
import java.util.Iterator;
|
7
|
import java.util.List;
|
8
|
import org.junit.Before;
|
9
|
import org.junit.Test;
|
10
|
import org.junit.runner.RunWith;
|
11
|
import org.mockito.junit.MockitoJUnitRunner;
|
12
|
|
13
|
@RunWith(MockitoJUnitRunner.class)
|
14
|
public class FetchListTest {
|
15
|
|
16
|
/**
|
17
|
* object to test
|
18
|
*/
|
19
|
private FetchList<String> fetchList;
|
20
|
|
21
|
private List<String> list;
|
22
|
private Iterator<String> iter;
|
23
|
|
24
|
private int FETCH_SIZE = 10;
|
25
|
|
26
|
private int TOTAL_ELEMENTS = 100;
|
27
|
|
28
|
@Before
|
29
|
public void setUp() throws Exception {
|
30
|
list = new ArrayList<String>();
|
31
|
for (int i = 0; i < TOTAL_ELEMENTS; i++) {
|
32
|
list.add("XXX" + i);
|
33
|
}
|
34
|
this.iter = list.iterator();
|
35
|
fetchList = new FetchList<String>(iter, FETCH_SIZE);
|
36
|
|
37
|
}
|
38
|
|
39
|
@Test
|
40
|
public void testFetchList() {
|
41
|
assertNotNull(fetchList);
|
42
|
}
|
43
|
|
44
|
@Test
|
45
|
public void testPoll_consumedElements() {
|
46
|
assertEquals(0, fetchList.getConsumedElements());
|
47
|
fetchList.poll();
|
48
|
assertEquals(1, fetchList.getConsumedElements());
|
49
|
}
|
50
|
|
51
|
@Test
|
52
|
public void testFill_totalElements() {
|
53
|
assertEquals(FETCH_SIZE, fetchList.getTotalElements());
|
54
|
}
|
55
|
|
56
|
@Test
|
57
|
public void testPoll() {
|
58
|
for (int i = 0; i < TOTAL_ELEMENTS; i++) {
|
59
|
assertEquals(i, fetchList.getConsumedElements());
|
60
|
assertEquals(list.get(i), fetchList.poll());
|
61
|
}
|
62
|
assertEquals(TOTAL_ELEMENTS, fetchList.getConsumedElements());
|
63
|
assertEquals(TOTAL_ELEMENTS, fetchList.getTotalElements());
|
64
|
}
|
65
|
|
66
|
@Test
|
67
|
public void testPoll_null() {
|
68
|
for (int i = 0; i < TOTAL_ELEMENTS; i++) {
|
69
|
fetchList.poll();
|
70
|
}
|
71
|
assertNull(fetchList.poll());
|
72
|
assertNull(fetchList.poll());
|
73
|
assertNull(fetchList.poll());
|
74
|
}
|
75
|
}
|