blob: 9338d101d0b7cd67faacb441fca46ae8b9088364 (
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
|
package cgeo.geocaching.utils;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
public class LazyInitializedListTest extends TestCase {
private static final class MockedLazyInitializedList extends LazyInitializedList<String> {
@Override
public List<String> call() {
return new ArrayList<String>();
}
}
public static void testAccess() {
final LazyInitializedList<String> list = new MockedLazyInitializedList();
assertThat(list.isEmpty()).isTrue();
list.add("Test");
assertThat(list.isEmpty()).isFalse();
assertThat(list).hasSize(1);
int iterations = 0;
for (String element : list) {
assertThat(element).isEqualTo("Test");
iterations++;
}
assertThat(iterations).isEqualTo(1);
}
}
|