1 5 package org.easymock.classextension.tests; 6 7 import org.easymock.MockControl; 8 import org.easymock.classextension.MockClassControl; 9 10 import junit.framework.TestCase; 11 12 public class ConstructorTest extends TestCase { 13 14 public static class FooClass { 15 public void foo() { 16 fail(); 18 } 19 } 20 21 public static class EmptyConstructorClass extends FooClass { 22 } 23 24 public static class ConstructorCallingPublicMethodClass extends FooClass { 25 26 public ConstructorCallingPublicMethodClass() { 27 foo(); 28 } 29 } 30 31 private void testConstructor(Class mockedClass) { 32 MockControl ctrl = MockClassControl.createControl(mockedClass); 33 FooClass mock = (FooClass) ctrl.getMock(); 34 assertTrue(mockedClass.isAssignableFrom(mock.getClass())); 35 mock.foo(); 36 ctrl.setVoidCallable(); 37 ctrl.replay(); 38 mock.foo(); 39 ctrl.verify(); 40 } 41 42 45 public void testEmptyConstructor() { 46 testConstructor(EmptyConstructorClass.class); 47 } 48 49 54 public void testConstructorCallingPublicMethod() { 55 testConstructor(ConstructorCallingPublicMethodClass.class); 56 } 57 } 58 | Popular Tags |