Return-Path: Delivered-To: apmail-jakarta-hivemind-cvs-archive@www.apache.org Received: (qmail 75326 invoked from network); 5 Dec 2004 16:43:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 5 Dec 2004 16:43:21 -0000 Received: (qmail 89875 invoked by uid 500); 5 Dec 2004 16:43:21 -0000 Delivered-To: apmail-jakarta-hivemind-cvs-archive@jakarta.apache.org Received: (qmail 89858 invoked by uid 500); 5 Dec 2004 16:43:21 -0000 Mailing-List: contact hivemind-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: hivemind-dev@jakarta.apache.org Delivered-To: mailing list hivemind-cvs@jakarta.apache.org Received: (qmail 89844 invoked by uid 99); 5 Dec 2004 16:43:21 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 05 Dec 2004 08:43:20 -0800 Received: (qmail 75299 invoked by uid 1616); 5 Dec 2004 16:43:19 -0000 Date: 5 Dec 2004 16:43:19 -0000 Message-ID: <20041205164319.75298.qmail@minotaur.apache.org> From: hlship@apache.org To: jakarta-hivemind-cvs@apache.org Subject: cvs commit: jakarta-hivemind/framework/src/test/org/apache/hivemind/test TestMockClass.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N hlship 2004/12/05 08:43:19 Modified: . .classpath status.xml framework/src/java/org/apache/hivemind/test HiveMindTestCase.java framework build.xml Added: framework/src/test/org/apache/hivemind/test TestMockClass.java Log: Optionally support the EasyMock class extension (if present on the classpath). Revision Changes Path 1.43 +2 -0 jakarta-hivemind/.classpath Index: .classpath =================================================================== RCS file: /home/cvs/jakarta-hivemind/.classpath,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- .classpath 11 Nov 2004 14:13:44 -0000 1.42 +++ .classpath 5 Dec 2004 16:43:19 -0000 1.43 @@ -24,5 +24,7 @@ + + 1.83 +4 -0 jakarta-hivemind/status.xml Index: status.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/status.xml,v retrieving revision 1.82 retrieving revision 1.83 diff -u -r1.82 -r1.83 --- status.xml 11 Nov 2004 14:13:44 -0000 1.82 +++ status.xml 5 Dec 2004 16:43:19 -0000 1.83 @@ -108,6 +108,10 @@ Added Groovy support. Module descriptors can now be defined using Groovy scripts. Although it requires some additional work in building the Registry. + + Support the EasyMock Class Extension, if present on the classpath, to allow classes (not just + interfaces) to be mocked. + 1.19 +64 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/test/HiveMindTestCase.java Index: HiveMindTestCase.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/test/HiveMindTestCase.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- HiveMindTestCase.java 10 Nov 2004 13:26:21 -0000 1.18 +++ HiveMindTestCase.java 5 Dec 2004 16:43:19 -0000 1.19 @@ -33,6 +33,7 @@ import org.apache.hivemind.impl.LocationImpl; import org.apache.hivemind.impl.RegistryBuilder; import org.apache.hivemind.impl.XmlModuleDescriptorProvider; +import org.apache.hivemind.service.ClassFabUtils; import org.apache.hivemind.util.ClasspathResource; import org.apache.hivemind.util.PropertyUtils; import org.apache.hivemind.util.URLResource; @@ -44,6 +45,7 @@ import org.apache.oro.text.regex.Perl5Compiler; import org.apache.oro.text.regex.Perl5Matcher; import org.easymock.MockControl; +import org.easymock.classextension.MockClassControl; /** * Contains some support for creating HiveMind tests; this is useful enough that has been moved into @@ -67,6 +69,60 @@ private List _controls = new ArrayList(); + /** @since 1.1 */ + interface MockControlFactory + { + public MockControl newControl(Class mockClass); + } + + /** @since 1.1 */ + private static class InterfaceMockControlFactory implements MockControlFactory + { + public MockControl newControl(Class mockClass) + { + return MockControl.createStrictControl(mockClass); + } + } + + /** @since 1.1 */ + private static class ClassMockControlFactory implements MockControlFactory + { + public MockControl newControl(Class mockClass) + { + return MockClassControl.createStrictControl(mockClass); + } + } + + /** @since 1.1 */ + static class PlaceholderClassMockControlFactory implements MockControlFactory + { + public MockControl newControl(Class mockClass) + { + throw new RuntimeException( + "Unable to instantiate EasyMock control for " + + mockClass + + "; ensure that easymockclassextension-1.1.jar and cglib-full-2.0.1.jar are on the classpath."); + } + } + + /** @since 1.1 */ + private static final MockControlFactory _interfaceMockControlFactory = new InterfaceMockControlFactory(); + + /** @since 1.1 */ + private static MockControlFactory _classMockControlFactory; + + static + { + try + { + _classMockControlFactory = new ClassMockControlFactory(); + } + catch (NoClassDefFoundError ex) + { + _classMockControlFactory = new PlaceholderClassMockControlFactory(); + } + } + /** * Returns the given file as a {@link Resource}from the classpath. Typically, this is to find * files in the same folder as the invoking class. @@ -400,10 +456,17 @@ * Creates a managed control via * {@link MockControl#createStrictControl(java.lang.Class)}. The created control is remembered, * and will be invoked by {@link #replayControls()},{@link #verifyControls()}, etc.. + *

+ * The class to mock may be either an interface or a class. The EasyMock class extension + * (easymockclassextension-1.1.jar) and CGLIB (cglib-full-2.01.jar) must be present in the + * latter case (new since 1.1). */ protected MockControl newControl(Class mockClass) { - MockControl result = MockControl.createStrictControl(mockClass); + MockControlFactory factory = mockClass.isInterface() ? _interfaceMockControlFactory + : _classMockControlFactory; + + MockControl result = factory.newControl(mockClass); addControl(result); 1.16 +12 -11 jakarta-hivemind/framework/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/build.xml,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- build.xml 16 Nov 2004 18:51:43 -0000 1.15 +++ build.xml 5 Dec 2004 16:43:19 -0000 1.16 @@ -26,17 +26,18 @@ - - - - - - - - - - - + + + + + + + + + + + +