KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > coerce > TestIteratorConverters


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.coerce;
16
17 import java.util.Collections JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.hivemind.test.HiveMindTestCase;
22
23 /**
24  * @author Howard M. Lewis Ship
25  * @since 4.0
26  */

27 public class TestIteratorConverters extends HiveMindTestCase
28 {
29     public void testObjectToIterator()
30     {
31         Object JavaDoc o = new Object JavaDoc();
32         TypeConverter c = new ObjectToIteratorConverter();
33
34         Iterator JavaDoc i = (Iterator JavaDoc) c.convertValue(o);
35
36         assertTrue(i.hasNext());
37         assertSame(o, i.next());
38         assertFalse(i.hasNext());
39     }
40
41     public void testNullToIterator()
42     {
43         TypeConverter c = new NullToIteratorConverter();
44
45         Iterator JavaDoc i = (Iterator JavaDoc) c.convertValue("will be null");
46
47         assertFalse(i.hasNext());
48     }
49
50     public void testCollectionToIterator()
51     {
52         Object JavaDoc o = new Object JavaDoc();
53         List JavaDoc l = Collections.singletonList(o);
54         TypeConverter c = new CollectionToIteratorConverter();
55
56         Iterator JavaDoc i = (Iterator JavaDoc) c.convertValue(l);
57
58         assertTrue(i.hasNext());
59         assertSame(o, i.next());
60         assertFalse(i.hasNext());
61     }
62
63     public void testObjectArrayToIterator()
64     {
65         Object JavaDoc o = new Object JavaDoc();
66         Object JavaDoc[] a = new Object JavaDoc[]
67         { o };
68
69         TypeConverter c = new ObjectArrayToIteratorConverter();
70
71         Iterator JavaDoc i = (Iterator JavaDoc) c.convertValue(a);
72
73         assertTrue(i.hasNext());
74         assertSame(o, i.next());
75         assertFalse(i.hasNext());
76     }
77 }
Popular Tags