KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > easymock > classextension > tests > LimitationsTest


1 /*
2  * Copyright (c) 2003-2004 OFFIS. This program is made available under the terms of
3  * the MIT License.
4  */

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 /**
13  * Test the limitations of class mocking
14  */

15 public class LimitationsTest extends TestCase {
16
17     public static class MyClass {
18         public final int foo() {
19             throw new RuntimeException JavaDoc();
20         }
21     }
22
23     public static class PrivateClass {
24         private PrivateClass() {
25         }
26     }
27
28     public void testFinalClass() {
29         try {
30             MockClassControl.createControl(String JavaDoc.class);
31             fail("Magic, we can mock a final class");
32         } catch (Exception JavaDoc e) {
33         }
34     }
35
36     public void testAbstractClass() {
37         MockControl ctrl = MockClassControl.createControl(TestCase.class);
38         assertTrue(ctrl.getMock() instanceof TestCase);
39     }
40
41     public void testMockFinalMethod() {
42         MockControl ctrl = MockClassControl.createControl(MyClass.class);
43         MyClass c = (MyClass) ctrl.getMock();
44
45         try {
46             c.foo();
47             fail("Final method shouldn't be mocked");
48         } catch (Exception JavaDoc e) {
49         }
50     }
51
52     public void testPrivateConstructor() {
53         MockClassControl.createControl(PrivateClass.class);
54     }
55 }
56
Popular Tags