1 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 23 public class DefaultCloneHandlerTest 24 extends JGAPTestCase { 25 26 private static final String CVS_REVISION = "$Revision: 1.6 $"; 27 28 public static Test suite() { 29 TestSuite suite = new TestSuite(DefaultCloneHandlerTest.class); 30 return suite; 31 } 32 33 40 public void testIsHandlerFor_0() 41 throws Exception { 42 IHandler handler = new DefaultCloneHandler(); 43 assertFalse(handler.isHandlerFor(null, MyCloneHandlerForTest.class)); 44 } 45 46 53 public void testIsHandlerFor_1() 54 throws Exception { 55 IHandler handler = new DefaultCloneHandler(); 56 assertFalse(handler.isHandlerFor(null, MyClassForTest.class)); 57 } 58 59 65 public void testIsHandlerFor_2() 66 throws Exception { 67 IHandler handler = new DefaultCloneHandler(); 68 Object app = new MyAppDataForTest(); 69 assertTrue(handler.isHandlerFor(app, app.getClass())); 70 } 71 72 78 public void testIsHandlerFor_3() 79 throws Exception { 80 IHandler handler = new DefaultCloneHandler(); 81 assertTrue(handler.isHandlerFor(null, ICloneable.class)); 82 } 83 84 90 public void testPerform_1() 91 throws Exception { 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 105 public void testPerform_2() 106 throws Exception { 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 120 public void testPerform_3() 121 throws Exception { 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 134 public void testPerform_4() 135 throws Exception { 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 148 public void testPerform_5() 149 throws Exception { 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 162 public void testPerform_6() 163 throws Exception { 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 nex) { 170 ; } 172 } 173 174 class MyAppDataForTest 175 implements Cloneable { 176 public int compareTo(Object o) { 177 return 0; 178 } 179 180 public Object clone() 181 throws CloneNotSupportedException { 182 throw new CloneNotSupportedException (); 183 } 184 } 185 class MyCloneHandlerForTest 186 implements Cloneable { 187 } 188 class MyClassForTest { 189 } 190 } 191 | Popular Tags |