KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > test > TestMockClass


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.test;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.easymock.MockControl;
21
22 /**
23  * Tests {@link org.apache.hivemind.test.HiveMindTestCase}'s ability to generate a mock for a class
24  * as well as an interface.
25  *
26  * @author Howard M. Lewis Ship
27  * @since 1.1
28  */

29 public class TestMockClass extends HiveMindTestCase
30 {
31     public void testMockForClass()
32     {
33         // Skip the test under a Gump build; there's no way to reconcile the different versions
34
// of ASM needed by Groovy and easymockclassextension.
35

36         try
37         {
38             MockControl c = newControl(ArrayList JavaDoc.class);
39             List JavaDoc l = (List JavaDoc) c.getMock();
40
41             l.size();
42             c.setReturnValue(5);
43
44             replayControls();
45
46             // We're not actually testing the List, we're testing the ability to create a mock
47
// for ArrayList
48

49             assertEquals(5, l.size());
50
51             verifyControls();
52         }
53         catch (Error JavaDoc err)
54         {
55             System.err
56                     .println("TestMockClass.testMockForClass() failed --- this is due to a conflict in versions of ASM between easymock and groovy.");
57             err.printStackTrace();
58         }
59     }
60
61     /**
62      * Test the placeholder, which is used when the easymockclassextension is not available.
63      */

64
65     public void testPlaceholder()
66     {
67         MockControlFactory f = new PlaceholderClassMockControlFactory();
68
69         try
70         {
71             f.newControl(ArrayList JavaDoc.class);
72             unreachable();
73         }
74         catch (RuntimeException JavaDoc ex)
75         {
76             assertEquals(
77                     "Unable to instantiate EasyMock control for class java.util.ArrayList; ensure that easymockclassextension-1.1.jar and cglib-full-2.0.1.jar are on the classpath.",
78                     ex.getMessage());
79         }
80     }
81 }
Popular Tags