1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.functor.generator;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.fail;
23
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.List;
27
28 import org.apache.commons.functor.BaseFunctorTest;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32
33
34
35
36
37 @SuppressWarnings("unchecked")
38 public class TestIteratorToGeneratorAdapter extends BaseFunctorTest {
39
40 public Object makeFunctor() {
41 List list = new ArrayList();
42 list.add("1");
43 return new IteratorToGeneratorAdapter(list.iterator());
44 }
45
46
47
48
49 private List list = null;
50
51 @Before
52 public void setUp() throws Exception {
53 list = new ArrayList();
54 list.add("1");
55 list.add("two");
56 list.add("c");
57 }
58
59 @After
60 public void tearDown() throws Exception {
61 list = null;
62 }
63
64
65
66
67 @Test
68 public void testAdaptNull() {
69 assertNull(IteratorToGeneratorAdapter.adapt(null));
70 }
71
72 @Test
73 public void testAdaptNonNull() {
74 assertNotNull(IteratorToGeneratorAdapter.adapt(list.iterator()));
75 }
76
77 @Test
78 public void testGenerate() {
79 Iterator iter = list.iterator();
80 Generator gen = new IteratorToGeneratorAdapter(iter);
81 List list2 = new ArrayList();
82 list2.addAll(gen.toCollection());
83 assertEquals(list,list2);
84 }
85
86 @Test
87 public void testConstructNull() {
88 try {
89 new IteratorToGeneratorAdapter(null);
90 fail("Expected NullPointerException");
91 } catch(IllegalArgumentException e) {
92
93 }
94 }
95
96 @Test
97 public void testEquals() {
98 Iterator iter = list.iterator();
99 Generator gen = new IteratorToGeneratorAdapter(iter);
100 assertObjectsAreEqual(gen,gen);
101 assertObjectsAreEqual(gen,new IteratorToGeneratorAdapter(iter));
102 }
103 }