KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.jgap.*;
13 import junit.framework.*;
14
15 /**
16  * Tests the DefaultInitializer class.
17  *
18  * @author Klaus Meffert
19  * @since 2.6
20  */

21 public class DefaultInitializerTest
22     extends JGAPTestCase {
23   /** String containing the CVS revision. Read out via reflection!*/
24   private static final String JavaDoc CVS_REVISION = "$Revision: 1.2 $";
25
26   public static Test suite() {
27     TestSuite suite = new TestSuite(DefaultInitializerTest.class);
28     return suite;
29   }
30
31   /**
32    * @throws Exception
33    *
34    * @author Klaus Meffert
35    * @since 2.6
36    */

37   public void testIsHandlerFor_0()
38       throws Exception JavaDoc {
39     IHandler handler = new DefaultInitializer();
40     assertFalse(handler.isHandlerFor(null, Object JavaDoc.class));
41     assertTrue(handler.isHandlerFor(null, Chromosome.class));
42     assertFalse(handler.isHandlerFor(null,DefaultInitializer.class));
43     assertFalse(handler.isHandlerFor(new DefaultInitializer(),
44                                      DefaultInitializer.class));
45     assertTrue(handler.isHandlerFor(new MyInitializerForTest(),
46                                     MyInitializerForTest.class));
47   }
48
49   /**
50    * @throws Exception
51    *
52    * @author Klaus meffert
53    * @since 2.6
54    */

55   public void testPerform_0()
56       throws Exception JavaDoc {
57     IHandler handler = new DefaultInitializer();
58     Chromosome orig = new Chromosome(conf);
59     try {
60       handler.perform(orig, Chromosome.class, null);
61       fail();
62     }
63     catch (InvalidConfigurationException iex) {
64       ; //this is OK (Configuration is null)
65
}
66   }
67
68   /**
69    * @throws Exception
70    *
71    * @author Klaus meffert
72    * @since 2.6
73    */

74   public void testPerform_1()
75       throws Exception JavaDoc {
76     IHandler handler = new DefaultCloneHandler();
77     FixedBinaryGene orig = new FixedBinaryGene(conf, 3);
78     FixedBinaryGene clone = (FixedBinaryGene) handler.perform(orig,
79         FixedBinaryGene.class, null);
80     assertEquals(orig, clone);
81   }
82
83   public class MyInitializerForTest
84       implements IInitializer {
85     public boolean isHandlerFor(final Object JavaDoc a_obj, final Class JavaDoc a_class) {
86       return true;
87     }
88
89     public Object JavaDoc perform(final Object JavaDoc a_obj, final Class JavaDoc a_class,
90                           final Object JavaDoc a_params)
91         throws Exception JavaDoc {
92       return null;
93     }
94   }
95 }
96
Popular Tags