KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > mx > mxbean > test > CompositeDataCollectionUnitTestCase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.mx.mxbean.test;
23
24 import java.lang.reflect.Type JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.LinkedHashSet JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Set JavaDoc;
30
31 import org.jboss.test.mx.mxbean.support.TestParameterizedType;
32
33 import junit.framework.Test;
34 import junit.framework.TestSuite;
35
36 /**
37  * CompositeDataCollectionUnitTestCase.
38  *
39  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
40  * @version $Revision: 1.1 $
41  */

42 public class CompositeDataCollectionUnitTestCase extends CompositeDataTest
43 {
44    private static final TestParameterizedType COLLECTION_OF_STRINGS = new TestParameterizedType(Collection JavaDoc.class, new Type JavaDoc[] { String JavaDoc.class });
45    private static final TestParameterizedType LIST_OF_STRINGS = new TestParameterizedType(List JavaDoc.class, new Type JavaDoc[] { String JavaDoc.class });
46    private static final TestParameterizedType SET_OF_STRINGS = new TestParameterizedType(Set JavaDoc.class, new Type JavaDoc[] { String JavaDoc.class });
47    
48    public static Test suite()
49    {
50       return new TestSuite(CompositeDataCollectionUnitTestCase.class);
51    }
52    
53    public CompositeDataCollectionUnitTestCase(String JavaDoc name)
54    {
55       super(name);
56    }
57    
58    public void testCollection() throws Exception JavaDoc
59    {
60       Collection JavaDoc<String JavaDoc> c = new ArrayList JavaDoc<String JavaDoc>();
61       c.add("one");
62       c.add("two");
63       c.add("three");
64       String JavaDoc[] openData = { "one", "two", "three" };
65       constructReconstructTest(c, COLLECTION_OF_STRINGS, openData);
66    }
67    
68    public void testCollectionNull() throws Exception JavaDoc
69    {
70       constructReconstructTest(null, COLLECTION_OF_STRINGS);
71    }
72    
73    public void testCollectionContainsNull() throws Exception JavaDoc
74    {
75       Collection JavaDoc<String JavaDoc> c = new ArrayList JavaDoc<String JavaDoc>();
76       c.add("one");
77       c.add(null);
78       c.add("three");
79       String JavaDoc[] openData = { "one", null, "three" };
80       constructReconstructTest(c, COLLECTION_OF_STRINGS, openData);
81    }
82    
83    public void testList() throws Exception JavaDoc
84    {
85       ArrayList JavaDoc<String JavaDoc> c = new ArrayList JavaDoc<String JavaDoc>();
86       c.add("one");
87       c.add("two");
88       c.add("three");
89       String JavaDoc[] openData = { "one", "two", "three" };
90       constructReconstructTest(c, LIST_OF_STRINGS, openData);
91    }
92    
93    public void testListNull() throws Exception JavaDoc
94    {
95       constructReconstructTest(null, LIST_OF_STRINGS);
96    }
97    
98    public void testListContainsNull() throws Exception JavaDoc
99    {
100       ArrayList JavaDoc<String JavaDoc> c = new ArrayList JavaDoc<String JavaDoc>();
101       c.add("one");
102       c.add(null);
103       c.add("three");
104       String JavaDoc[] openData = { "one", null, "three" };
105       constructReconstructTest(c, LIST_OF_STRINGS, openData);
106    }
107    
108    public void testSet() throws Exception JavaDoc
109    {
110       LinkedHashSet JavaDoc<String JavaDoc> c = new LinkedHashSet JavaDoc<String JavaDoc>();
111       c.add("one");
112       c.add("two");
113       c.add("three");
114       String JavaDoc[] openData = { "one", "two", "three" };
115       constructReconstructTest(c, SET_OF_STRINGS, openData);
116    }
117    
118    public void testSetNull() throws Exception JavaDoc
119    {
120       constructReconstructTest(null, SET_OF_STRINGS);
121    }
122    
123    public void testSetContainsNull() throws Exception JavaDoc
124    {
125       LinkedHashSet JavaDoc<String JavaDoc> c = new LinkedHashSet JavaDoc<String JavaDoc>();
126       c.add("one");
127       c.add(null);
128       c.add("three");
129       String JavaDoc[] openData = { "one", null, "three" };
130       constructReconstructTest(c, SET_OF_STRINGS, openData);
131    }
132
133    protected void checkOpenDataEquals(Object JavaDoc expected, Object JavaDoc actual)
134    {
135       checkArrayEquals(expected, actual);
136    }
137 }
138
Popular Tags