KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > impl > DefaultCloneHandlerTest


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.impl;
11
12 import java.util.*;
13 import org.jgap.*;
14 import org.jgap.util.*;
15 import junit.framework.*;
16
17 /**
18  * Tests the DefaultCloneHandler class.
19  *
20  * @author Klaus Meffert
21  * @since 2.6
22  */

23 public class DefaultCloneHandlerTest
24     extends JGAPTestCase {
25   /** String containing the CVS revision. Read out via reflection!*/
26   private static final String JavaDoc CVS_REVISION = "$Revision: 1.6 $";
27
28   public static Test suite() {
29     TestSuite suite = new TestSuite(DefaultCloneHandlerTest.class);
30     return suite;
31   }
32
33   /**
34    * Handler implementing Cloneable without clone() method.
35    * @throws Exception
36    *
37    * @author Klaus Meffert
38    * @since 2.6
39    */

40   public void testIsHandlerFor_0()
41       throws Exception JavaDoc {
42     IHandler handler = new DefaultCloneHandler();
43     assertFalse(handler.isHandlerFor(null, MyCloneHandlerForTest.class));
44   }
45
46   /**
47    * Handler not implementing Cloneable.
48    * @throws Exception
49    *
50    * @author Klaus Meffert
51    * @since 2.6
52    */

53   public void testIsHandlerFor_1()
54       throws Exception JavaDoc {
55     IHandler handler = new DefaultCloneHandler();
56     assertFalse(handler.isHandlerFor(null, MyClassForTest.class));
57   }
58
59   /**
60    * @throws Exception
61    *
62    * @author Klaus Meffert
63    * @since 2.6
64    */

65   public void testIsHandlerFor_2()
66       throws Exception JavaDoc {
67     IHandler handler = new DefaultCloneHandler();
68     Object JavaDoc app = new MyAppDataForTest();
69     assertTrue(handler.isHandlerFor(app, app.getClass()));
70   }
71
72   /**
73    * @throws Exception
74    *
75    * @author Klaus Meffert
76    * @since 3.2
77    */

78   public void testIsHandlerFor_3()
79       throws Exception JavaDoc {
80     IHandler handler = new DefaultCloneHandler();
81     assertTrue(handler.isHandlerFor(null, ICloneable.class));
82   }
83
84   /**
85    * @throws Exception
86    *
87    * @author Klaus Meffert
88    * @since 2.6
89    */

90   public void testPerform_1()
91       throws Exception JavaDoc {
92     IHandler handler = new DefaultCloneHandler();
93     FixedBinaryGene orig = new FixedBinaryGene(conf, 3);
94     FixedBinaryGene clone = (FixedBinaryGene) handler.perform(orig,
95         FixedBinaryGene.class, null);
96     assertEquals(orig, clone);
97   }
98
99   /**
100    * @throws Exception
101    *
102    * @author Klaus Meffert
103    * @since 3.2
104    */

105   public void testPerform_2()
106       throws Exception JavaDoc {
107     IHandler handler = new DefaultCloneHandler();
108     FixedBinaryGene orig = new FixedBinaryGene(conf, 3);
109     FixedBinaryGene clone = (FixedBinaryGene) handler.perform(orig,
110         null, null);
111     assertEquals(orig, clone);
112   }
113
114   /**
115    * @throws Exception
116    *
117    * @author Klaus Meffert
118    * @since 3.2
119    */

120   public void testPerform_3()
121       throws Exception JavaDoc {
122     IHandler handler = new DefaultCloneHandler();
123     Chromosome orig = new Chromosome(conf);
124     Chromosome clone = (Chromosome) handler.perform(orig, Chromosome.class, null);
125     assertEquals(orig, clone);
126   }
127
128   /**
129    * @throws Exception
130    *
131    * @author Klaus Meffert
132    * @since 3.2
133    */

134   public void testPerform_4()
135       throws Exception JavaDoc {
136     IHandler handler = new DefaultCloneHandler();
137     Chromosome orig = new Chromosome(conf);
138     Chromosome clone = (Chromosome) handler.perform(orig, null, null);
139     assertEquals(orig, clone);
140   }
141
142   /**
143    * @throws Exception
144    *
145    * @author Klaus Meffert
146    * @since 3.2
147    */

148   public void testPerform_5()
149       throws Exception JavaDoc {
150     IHandler handler = new DefaultCloneHandler();
151     Chromosome orig = new Chromosome(conf);
152     Chromosome clone = (Chromosome) handler.perform(orig, null, new Vector());
153     assertEquals(orig, clone);
154   }
155
156   /**
157    * @throws Exception
158    *
159    * @author Klaus Meffert
160    * @since 3.2
161    */

162   public void testPerform_6()
163       throws Exception JavaDoc {
164     IHandler handler = new DefaultCloneHandler();
165     Chromosome orig = new Chromosome(conf);
166     try {
167       Chromosome clone = (Chromosome) handler.perform(null, Chromosome.class, null);
168       fail();
169     } catch (NullPointerException JavaDoc nex) {
170       ; //this is OK
171
}
172   }
173
174   class MyAppDataForTest
175       implements Cloneable JavaDoc {
176     public int compareTo(Object JavaDoc o) {
177       return 0;
178     }
179
180     public Object JavaDoc clone()
181         throws CloneNotSupportedException JavaDoc {
182       throw new CloneNotSupportedException JavaDoc();
183     }
184   }
185   class MyCloneHandlerForTest
186       implements Cloneable JavaDoc {
187   }
188   class MyClassForTest {
189   }
190 }
191
Popular Tags