1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.list;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertNotNull;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.time.LocalDateTime;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28
29 import org.apache.commons.collections4.AbstractObjectTest;
30 import org.apache.commons.collections4.Factory;
31 import org.apache.commons.collections4.Transformer;
32 import org.junit.jupiter.api.Test;
33
34 public class LazyListTest extends AbstractObjectTest {
35
36 public LazyListTest() {
37 super(LazyListTest.class.getSimpleName());
38 }
39
40 @Override
41 public Object makeObject() {
42 final Factory<LocalDateTime> dateFactory = LocalDateTime::now;
43 return new LazyList<>(new ArrayList<>(), dateFactory);
44 }
45
46 @Test
47 @Override
48 public void testCanonicalEmptyCollectionExists() {
49
50 }
51
52 @Test
53 @Override
54 public void testCanonicalFullCollectionExists() {
55
56 }
57
58 @Test
59 public void testCreateNullGapsWithFactory() {
60 final Factory<LocalDateTime> dateFactory = LocalDateTime::now;
61 final List<LocalDateTime> list = new LazyList<>(new ArrayList<>(), dateFactory);
62
63 final LocalDateTime fourthElement = list.get(3);
64 assertFalse(list.isEmpty());
65 assertNotNull(fourthElement);
66 }
67
68 @Test
69 public void testCreateNullGapsWithTransformer() {
70 final List<Integer> hours = Arrays.asList(7, 5, 8, 2);
71 final Transformer<Integer, LocalDateTime> dateFactory = input -> LocalDateTime.now().withHour(hours.get(input));
72 final List<LocalDateTime> list = new LazyList<>(new ArrayList<>(), dateFactory);
73
74 final LocalDateTime fourthElement = list.get(3);
75 assertFalse(list.isEmpty());
76 assertNotNull(fourthElement);
77 }
78
79 @Test
80 public void testElementCreationWithFactory() {
81 final Factory<LocalDateTime> dateFactory = LocalDateTime::now;
82 final List<LocalDateTime> list = new LazyList<>(new ArrayList<>(), dateFactory);
83
84 assertTrue(list.isEmpty());
85
86 final LocalDateTime firstElement = list.get(0);
87 assertNotNull(firstElement);
88 assertFalse(list.isEmpty());
89 }
90
91 @Test
92 public void testElementCreationWithTransformer() {
93 final Factory<LocalDateTime> dateFactory = LocalDateTime::now;
94 final List<LocalDateTime> list = new LazyList<>(new ArrayList<>(), dateFactory);
95
96 assertTrue(list.isEmpty());
97
98 final LocalDateTime firstElement = list.get(0);
99 assertNotNull(firstElement);
100 assertFalse(list.isEmpty());
101 }
102
103 @Test
104 public void testGetWithNull() {
105 final List<Integer> hours = Arrays.asList(7, 5, 8, 2);
106 final Transformer<Integer, LocalDateTime> transformer = input -> LocalDateTime.now().withHour(hours.get(input));
107 final List<LocalDateTime> list = new LazyList<>(new ArrayList<>(), transformer);
108 LocalDateTime fourthElement = list.get(3);
109 assertFalse(list.isEmpty());
110 assertNotNull(fourthElement);
111 list.remove(3);
112 list.add(3, null);
113 fourthElement = list.get(3);
114 assertNotNull(fourthElement);
115 }
116
117 @Test
118 @Override
119 public void testSerializeDeserializeThenCompare() {
120
121 }
122
123 @Test
124 @Override
125 public void testSimpleSerialization() {
126
127 }
128
129 private void testSubList(final List<LocalDateTime> list) {
130 List<LocalDateTime> subList = list.subList(1, 3);
131 assertFalse(subList.isEmpty());
132 assertNotNull(subList);
133 assertEquals(2, subList.size());
134
135 subList = list.subList(0, 1);
136 assertFalse(subList.isEmpty());
137 assertEquals(1, subList.size());
138
139 subList = list.subList(1, 1);
140 assertTrue(subList.isEmpty());
141
142 subList = list.subList(0, list.size());
143 assertFalse(subList.isEmpty());
144 assertEquals(list.size(), subList.size());
145 }
146
147 @Test
148 public void testSubListWitheFactory() {
149 final Factory<LocalDateTime> dateFactory = LocalDateTime::now;
150 final List<LocalDateTime> list = new LazyList<>(new ArrayList<>(), dateFactory);
151 final LocalDateTime fourthElement = list.get(3);
152 assertFalse(list.isEmpty());
153 assertNotNull(fourthElement);
154 testSubList(list);
155 }
156
157 @Test
158 public void testSubListWithTransformer() {
159 final List<Integer> hours = Arrays.asList(7, 5, 8, 2);
160 final Transformer<Integer, LocalDateTime> transformer = input -> LocalDateTime.now().withHour(hours.get(input));
161 final List<LocalDateTime> list = new LazyList<>(new ArrayList<>(), transformer);
162 final LocalDateTime fourthElement = list.get(3);
163 assertFalse(list.isEmpty());
164 assertNotNull(fourthElement);
165 testSubList(list);
166 }
167
168 }