tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r492319 - in /tapestry/tapestry5/tapestry-ioc/trunk/src: main/java/org/apache/tapestry/ioc/ main/java/org/apache/tapestry/ioc/test/ test/java/org/apache/tapestry/ioc/internal/ test/java/org/apache/tapestry/ioc/internal/services/
Date Wed, 03 Jan 2007 21:51:27 GMT
Author: hlship
Date: Wed Jan  3 13:51:27 2007
New Revision: 492319

URL: http://svn.apache.org/viewvc?view=rev&rev=492319
Log:
Move a few common testing factory and trainer methods up to IOCTestCase.

Modified:
    tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/Resource.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/TestBase.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImplTest.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ThreadCleanupHubImplTest.java

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/Resource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/Resource.java?view=diff&rev=492319&r1=492318&r2=492319
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/Resource.java
(original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/Resource.java
Wed Jan  3 13:51:27 2007
@@ -30,7 +30,7 @@
     /** Returns the URL for the resource, or null if it does not exist. */
     URL toURL();
 
-    /** Returns a localized version of the resource. */
+    /** Returns a localized version of the resource. May return null if no such resource
exists. */
     Resource forLocale(Locale locale);
 
     /**
@@ -46,7 +46,7 @@
      * may return null.
      * 
      * @param extension
-     *            to apply to the resource
+     *            to apply to the resource, such as "html" or "properties"
      * @return the new resource
      */
     Resource withExtension(String extension);

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java?view=diff&rev=492319&r1=492318&r2=492319
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
(original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
Wed Jan  3 13:51:27 2007
@@ -15,12 +15,15 @@
 package org.apache.tapestry.ioc.test;
 
 import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.Locale;
 
 import org.apache.commons.logging.Log;
 import org.apache.tapestry.ioc.Configuration;
 import org.apache.tapestry.ioc.Location;
 import org.apache.tapestry.ioc.LogSource;
 import org.apache.tapestry.ioc.MappedConfiguration;
+import org.apache.tapestry.ioc.Messages;
 import org.apache.tapestry.ioc.ObjectCreator;
 import org.apache.tapestry.ioc.ObjectProvider;
 import org.apache.tapestry.ioc.OrderedConfiguration;
@@ -275,5 +278,35 @@
     protected final ThreadLocale newThreadLocale()
     {
         return newMock(ThreadLocale.class);
+    }
+
+    protected final Messages newMessages()
+    {
+        return newMock(Messages.class);
+    }
+
+    protected final void train_toURL(Resource resource, URL url)
+    {
+        expect(resource.toURL()).andReturn(url).atLeastOnce();
+    }
+
+    protected final void train_getPath(Resource r, String path)
+    {
+        expect(r.getPath()).andReturn(path).atLeastOnce();
+    }
+
+    protected final void train_getLocale(ThreadLocale threadLocale, Locale locale)
+    {
+        expect(threadLocale.getLocale()).andReturn(locale);
+    }
+
+    protected final Log newLog()
+    {
+        return newMock(Log.class);
+    }
+
+    protected final void train_isDebugEnabled(Log log, boolean debugEnabled)
+    {
+        expect(log.isDebugEnabled()).andReturn(debugEnabled);
     }
 }

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/TestBase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/TestBase.java?view=diff&rev=492319&r1=492318&r2=492319
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/TestBase.java
(original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/TestBase.java
Wed Jan  3 13:51:27 2007
@@ -14,7 +14,6 @@
 
 package org.apache.tapestry.ioc.test;
 
-import org.apache.commons.logging.Log;
 import org.easymock.EasyMock;
 import org.easymock.IExpectationSetters;
 import org.easymock.IMocksControl;
@@ -124,16 +123,6 @@
     protected final void unreachable()
     {
         fail("This code should not be reachable.");
-    }
-
-    protected final Log newLog()
-    {
-        return newMock(Log.class);
-    }
-
-    protected final void train_isDebugEnabled(Log log, boolean debugEnabled)
-    {
-        expect(log.isDebugEnabled()).andReturn(debugEnabled);
     }
 
     @SuppressWarnings("unchecked")

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImplTest.java?view=diff&rev=492319&r1=492318&r2=492319
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImplTest.java
(original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImplTest.java
Wed Jan  3 13:51:27 2007
@@ -12,347 +12,334 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.ioc.internal;
-
+package org.apache.tapestry.ioc.internal;
+
 import static org.apache.tapestry.ioc.internal.IOCMessages.buildMethodConflict;
-
-import java.lang.reflect.Method;
-import java.math.BigDecimal;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.tapestry.ioc.IOCConstants;
-import org.apache.tapestry.ioc.def.ContributionDef;
-import org.apache.tapestry.ioc.def.DecoratorDef;
-import org.apache.tapestry.ioc.def.ModuleDef;
-import org.apache.tapestry.ioc.def.ServiceDef;
+
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.tapestry.ioc.IOCConstants;
+import org.apache.tapestry.ioc.def.ContributionDef;
+import org.apache.tapestry.ioc.def.DecoratorDef;
+import org.apache.tapestry.ioc.def.ModuleDef;
+import org.apache.tapestry.ioc.def.ServiceDef;
 import org.apache.tapestry.ioc.internal.DefaultModuleDefImpl;
 import org.apache.tapestry.ioc.internal.IOCMessages;
 import org.apache.tapestry.ioc.internal.util.InternalUtils;
+import org.apache.tapestry.ioc.test.IOCTestCase;
 import org.apache.tapestry.ioc.test.TestBase;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-/**
- * 
- */
-public class DefaultModuleDefImplTest extends TestBase
-{
-    @Test
-    public void module_builder_without_id()
-    {
-        Log log = newLog();
-
-        replay();
-
-        // BigDecimal is arbitrary, any class would do.
-
-        ModuleDef md = new DefaultModuleDefImpl(BigDecimal.class, log);
-
-        Assert.assertEquals("java.math", md.getModuleId());
-
-        verify();
-    }
-
-    @Test
-    public void module_builder_with_id()
-    {
-        Log log = newLog();
-
-        replay();
-
-        // BigDecimal is arbitrary, any class would do.
-
-        ModuleDef md = new DefaultModuleDefImpl(ModuleBuilderWithId.class, log);
-
-        Assert.assertEquals("tapestry.ioc", md.getModuleId());
-
-        verify();
-    }
-
-    @Test
-    public void simple_module() throws Exception
-    {
-        String className = SimpleModule.class.getName();
-
-        Log log = newLog();
-
-        replay();
-
-        // BigDecimal is arbitrary, any class would do.
-
-        ModuleDef md = new DefaultModuleDefImpl(SimpleModule.class, log);
-
-        Set<String> ids = md.getServiceIds();
-
-        assertEquals(ids.size(), 3);
-        assertTrue(ids.contains("ioc.Fred"));
-        assertTrue(ids.contains("ioc.Barney"));
-        assertTrue(ids.contains("ioc.Wilma"));
-
-        ServiceDef sd = md.getServiceDef("ioc.Fred");
-
-        assertEquals(sd.getServiceId(), "ioc.Fred");
-
-        assertEquals(sd.getServiceInterface(), FieService.class);
-
-        assertEquals(sd.toString(), className + ".buildFred()");
-        assertEquals(sd.getServiceLifeycle(), IOCConstants.DEFAULT_LIFECYCLE);
-        assertEquals(sd.isPrivate(), false);
-        assertEquals(sd.isEagerLoad(), false);
-
-        sd = md.getServiceDef("ioc.Barney");
-
-        assertEquals(sd.getServiceId(), "ioc.Barney");
-
-        assertEquals(sd.getServiceInterface(), FoeService.class);
-
-        assertEquals(sd.toString(), className + ".buildBarney()");
-        assertEquals(sd.getServiceLifeycle(), "threaded");
-        assertEquals(sd.isPrivate(), true);
-
-        sd = md.getServiceDef("ioc.Wilma");
-        assertEquals(sd.isEagerLoad(), true);
-
-        // Now the decorator method.
-
-        Set<DecoratorDef> defs = md.getDecoratorDefs();
-
-        assertEquals(defs.size(), 1);
-
-        DecoratorDef dd = defs.iterator().next();
-
-        assertEquals(dd.getDecoratorId(), "ioc.Logging");
-        assertEquals(dd.toString(), className + ".decorateLogging(Class, Object)");
-
-        verify();
-
-    }
-
-    /** Two different methods both claim to build the same service. */
-    @Test
-    public void service_id_conflict() throws Exception
-    {
-        Method conflictMethod = ServiceIdConflictMethodModule.class.getMethod("buildFred");
-        String expectedMethod = InternalUtils.asString(ServiceIdConflictMethodModule.class
-                .getMethod("buildFred", Object.class));
-
-        Log log = newLog();
-
-        log.warn(buildMethodConflict(conflictMethod, expectedMethod), null);
-
-        replay();
-
-        // BigDecimal is arbitrary, any class would do.
-
-        ModuleDef md = new DefaultModuleDefImpl(ServiceIdConflictMethodModule.class, log);
-
-        Set<String> ids = md.getServiceIds();
-
-        assertEquals(ids.size(), 1);
-        assertTrue(ids.contains("ioc.Fred"));
-
-        ServiceDef sd = md.getServiceDef("ioc.Fred");
-
-        assertEquals(sd.getServiceId(), "ioc.Fred");
-
-        assertEquals(sd.getServiceInterface(), FieService.class);
-
-        // The methods are considered in ascending order, by name, then descending order,
by
-        // parameter count. So the grinder will latch onto the method that takes a parameter,
-        // and consider the other method (with no parameters) the conflict.
-
-        assertEquals(sd.toString(), expectedMethod.toString());
-
-        verify();
-    }
-
-    @Test
-    public void builder_method_returns_void() throws Exception
-    {
-        Method m = VoidBuilderMethodModule.class.getMethod("buildNull");
-
-        Log log = newLog();
-
-        log.warn(IOCMessages.buildMethodWrongReturnType(m), null);
-
-        replay();
-
-        ModuleDef md = new DefaultModuleDefImpl(VoidBuilderMethodModule.class, log);
-
-        assertTrue(md.getServiceIds().isEmpty());
-
-        verify();
-    }
-
-    @Test
-    public void decorator_method_returns_void() throws Exception
-    {
-        invalidDecoratorMethod(VoidDecoratorMethodModule.class, "decorateVoid");
-    }
-
-    private void invalidDecoratorMethod(Class moduleClass, String methodName)
-            throws NoSuchMethodException
-    {
-        Method m = moduleClass.getMethod(methodName, Object.class);
-
-        Log log = newLog();
-
-        log.warn(IOCMessages.decoratorMethodWrongReturnType(m), null);
-
-        replay();
-
-        ModuleDef md = new DefaultModuleDefImpl(moduleClass, log);
-
-        assertTrue(md.getDecoratorDefs().isEmpty());
-
-        verify();
-    }
-
-    @Test
-    public void decorator_method_returns_primitive() throws Exception
-    {
-        invalidDecoratorMethod(PrimitiveDecoratorMethodModule.class, "decoratePrimitive");
-    }
-
-    @Test
-    public void decorator_method_returns_array() throws Exception
-    {
-        invalidDecoratorMethod(ArrayDecoratorMethodModule.class, "decorateArray");
-    }
-
-    @Test
-    public void decorator_method_does_not_include_delegate_parameter() throws Exception
-    {
-        Class moduleClass = NoDelegateDecoratorMethodModule.class;
-        Method m = moduleClass.getMethod("decorateNoDelegate");
-
-        Log log = newLog();
-
-        log.warn(IOCMessages.decoratorMethodNeedsDelegateParameter(m), null);
-
-        replay();
-
-        ModuleDef md = new DefaultModuleDefImpl(moduleClass, log);
-
-        assertTrue(md.getDecoratorDefs().isEmpty());
-
-        verify();
-    }
-
-    @Test
-    public void contribution_without_annotation()
-    {
-        attemptConfigurationMethod(
-                SimpleModule.class,
-                "ioc.Barney",
-                "contributeBarney(Configuration)");
-    }
-
-    @Test
-    public void contribution_with_annotation()
-    {
-        attemptConfigurationMethod(
-                ConfigurationWithContributeAnnotationModule.class,
-                "ioc.test.Fred",
-                "contributeSomething(Configuration)");
-
-    }
-
-    @Test
-    public void contribution_with_annotation_to_other_module()
-    {
-        attemptConfigurationMethod(
-                ConfigurationWithAnnotationOtherModule.class,
-                "some.module.Wilma",
-                "contributeOtherModule(Configuration)");
-    }
-
-    @Test
-    public void ordered_contribution_method()
-    {
-        attemptConfigurationMethod(
-                OrderedConfigurationModule.class,
-                "ioc.test.Ordered",
-                "contributeOrdered(OrderedConfiguration)");
-    }
-
-    @Test
-    public void mapped_contribution_method()
-    {
-        attemptConfigurationMethod(
-                MappedConfigurationModule.class,
-                "ioc.test.Mapped",
-                "contributeMapped(MappedConfiguration)");
-    }
-
-    private void attemptConfigurationMethod(Class moduleClass, String expectedServiceId,
-            String expectedMethodSignature)
-    {
-        Log log = newLog();
-
-        replay();
-
-        ModuleDef md = new DefaultModuleDefImpl(moduleClass, log);
-
-        Set<ContributionDef> defs = md.getContributionDefs();
-
-        assertEquals(defs.size(), 1);
-
-        ContributionDef cd = defs.iterator().next();
-
-        // The target service id is derived from the method name
-
-        assertEquals(cd.getServiceId(), expectedServiceId);
-        assertEquals(cd.toString(), moduleClass.getName() + "." + expectedMethodSignature);
-
-        verify();
-    }
-
-    @Test
-    public void contribution_with_too_many_parameters() throws Exception
-    {
-        Class moduleClass = TooManyContributionParametersModule.class;
-        Method m = findMethod(moduleClass, "contributeTooMany");
-
-        Log log = newLog();
-        log.warn(IOCMessages.tooManyContributionParameters(m));
-
-        replay();
-
-        ModuleDef md = new DefaultModuleDefImpl(moduleClass, log);
-
-        assertTrue(md.getContributionDefs().isEmpty());
-
-        verify();
-    }
-
-    @Test
-    public void contribution_with_no_contribution_parameter() throws Exception
-    {
-        Class moduleClass = NoUsableContributionParameterModule.class;
-        Method m = findMethod(moduleClass, "contributeNoParameter");
-
-        Log log = newLog();
-        log.warn(IOCMessages.noContributionParameter(m));
-
-        replay();
-
-        ModuleDef md = new DefaultModuleDefImpl(moduleClass, log);
-
-        assertTrue(md.getContributionDefs().isEmpty());
-
-        verify();
-    }
-
-    private Method findMethod(Class containingClass, String methodName)
-    {
-        for (Method method : containingClass.getMethods())
-        {
-            if (method.getName().equals(methodName))
-                return method;
-        }
-
-        throw new IllegalArgumentException(methodName);
-    }
-}
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class DefaultModuleDefImplTest extends IOCTestCase
+{
+    @Test
+    public void module_builder_without_id()
+    {
+        Log log = newLog();
+
+        replay();
+
+        // BigDecimal is arbitrary, any class would do.
+
+        ModuleDef md = new DefaultModuleDefImpl(BigDecimal.class, log);
+
+        Assert.assertEquals("java.math", md.getModuleId());
+
+        verify();
+    }
+
+    @Test
+    public void module_builder_with_id()
+    {
+        Log log = newLog();
+
+        replay();
+
+        // BigDecimal is arbitrary, any class would do.
+
+        ModuleDef md = new DefaultModuleDefImpl(ModuleBuilderWithId.class, log);
+
+        Assert.assertEquals("tapestry.ioc", md.getModuleId());
+
+        verify();
+    }
+
+    @Test
+    public void simple_module() throws Exception
+    {
+        String className = SimpleModule.class.getName();
+
+        Log log = newLog();
+
+        replay();
+
+        // BigDecimal is arbitrary, any class would do.
+
+        ModuleDef md = new DefaultModuleDefImpl(SimpleModule.class, log);
+
+        Set<String> ids = md.getServiceIds();
+
+        assertEquals(ids.size(), 3);
+        assertTrue(ids.contains("ioc.Fred"));
+        assertTrue(ids.contains("ioc.Barney"));
+        assertTrue(ids.contains("ioc.Wilma"));
+
+        ServiceDef sd = md.getServiceDef("ioc.Fred");
+
+        assertEquals(sd.getServiceId(), "ioc.Fred");
+
+        assertEquals(sd.getServiceInterface(), FieService.class);
+
+        assertEquals(sd.toString(), className + ".buildFred()");
+        assertEquals(sd.getServiceLifeycle(), IOCConstants.DEFAULT_LIFECYCLE);
+        assertEquals(sd.isPrivate(), false);
+        assertEquals(sd.isEagerLoad(), false);
+
+        sd = md.getServiceDef("ioc.Barney");
+
+        assertEquals(sd.getServiceId(), "ioc.Barney");
+
+        assertEquals(sd.getServiceInterface(), FoeService.class);
+
+        assertEquals(sd.toString(), className + ".buildBarney()");
+        assertEquals(sd.getServiceLifeycle(), "threaded");
+        assertEquals(sd.isPrivate(), true);
+
+        sd = md.getServiceDef("ioc.Wilma");
+        assertEquals(sd.isEagerLoad(), true);
+
+        // Now the decorator method.
+
+        Set<DecoratorDef> defs = md.getDecoratorDefs();
+
+        assertEquals(defs.size(), 1);
+
+        DecoratorDef dd = defs.iterator().next();
+
+        assertEquals(dd.getDecoratorId(), "ioc.Logging");
+        assertEquals(dd.toString(), className + ".decorateLogging(Class, Object)");
+
+        verify();
+
+    }
+
+    /** Two different methods both claim to build the same service. */
+    @Test
+    public void service_id_conflict() throws Exception
+    {
+        Method conflictMethod = ServiceIdConflictMethodModule.class.getMethod("buildFred");
+        String expectedMethod = InternalUtils.asString(ServiceIdConflictMethodModule.class
+                .getMethod("buildFred", Object.class));
+
+        Log log = newLog();
+
+        log.warn(buildMethodConflict(conflictMethod, expectedMethod), null);
+
+        replay();
+
+        // BigDecimal is arbitrary, any class would do.
+
+        ModuleDef md = new DefaultModuleDefImpl(ServiceIdConflictMethodModule.class, log);
+
+        Set<String> ids = md.getServiceIds();
+
+        assertEquals(ids.size(), 1);
+        assertTrue(ids.contains("ioc.Fred"));
+
+        ServiceDef sd = md.getServiceDef("ioc.Fred");
+
+        assertEquals(sd.getServiceId(), "ioc.Fred");
+
+        assertEquals(sd.getServiceInterface(), FieService.class);
+
+        // The methods are considered in ascending order, by name, then descending order,
by
+        // parameter count. So the grinder will latch onto the method that takes a parameter,
+        // and consider the other method (with no parameters) the conflict.
+
+        assertEquals(sd.toString(), expectedMethod.toString());
+
+        verify();
+    }
+
+    @Test
+    public void builder_method_returns_void() throws Exception
+    {
+        Method m = VoidBuilderMethodModule.class.getMethod("buildNull");
+
+        Log log = newLog();
+
+        log.warn(IOCMessages.buildMethodWrongReturnType(m), null);
+
+        replay();
+
+        ModuleDef md = new DefaultModuleDefImpl(VoidBuilderMethodModule.class, log);
+
+        assertTrue(md.getServiceIds().isEmpty());
+
+        verify();
+    }
+
+    @Test
+    public void decorator_method_returns_void() throws Exception
+    {
+        invalidDecoratorMethod(VoidDecoratorMethodModule.class, "decorateVoid");
+    }
+
+    private void invalidDecoratorMethod(Class moduleClass, String methodName)
+            throws NoSuchMethodException
+    {
+        Method m = moduleClass.getMethod(methodName, Object.class);
+
+        Log log = newLog();
+
+        log.warn(IOCMessages.decoratorMethodWrongReturnType(m), null);
+
+        replay();
+
+        ModuleDef md = new DefaultModuleDefImpl(moduleClass, log);
+
+        assertTrue(md.getDecoratorDefs().isEmpty());
+
+        verify();
+    }
+
+    @Test
+    public void decorator_method_returns_primitive() throws Exception
+    {
+        invalidDecoratorMethod(PrimitiveDecoratorMethodModule.class, "decoratePrimitive");
+    }
+
+    @Test
+    public void decorator_method_returns_array() throws Exception
+    {
+        invalidDecoratorMethod(ArrayDecoratorMethodModule.class, "decorateArray");
+    }
+
+    @Test
+    public void decorator_method_does_not_include_delegate_parameter() throws Exception
+    {
+        Class moduleClass = NoDelegateDecoratorMethodModule.class;
+        Method m = moduleClass.getMethod("decorateNoDelegate");
+
+        Log log = newLog();
+
+        log.warn(IOCMessages.decoratorMethodNeedsDelegateParameter(m), null);
+
+        replay();
+
+        ModuleDef md = new DefaultModuleDefImpl(moduleClass, log);
+
+        assertTrue(md.getDecoratorDefs().isEmpty());
+
+        verify();
+    }
+
+    @Test
+    public void contribution_without_annotation()
+    {
+        attemptConfigurationMethod(
+                SimpleModule.class,
+                "ioc.Barney",
+                "contributeBarney(Configuration)");
+    }
+
+    @Test
+    public void contribution_with_annotation()
+    {
+        attemptConfigurationMethod(
+                ConfigurationWithContributeAnnotationModule.class,
+                "ioc.test.Fred",
+                "contributeSomething(Configuration)");
+
+    }
+
+    @Test
+    public void contribution_with_annotation_to_other_module()
+    {
+        attemptConfigurationMethod(
+                ConfigurationWithAnnotationOtherModule.class,
+                "some.module.Wilma",
+                "contributeOtherModule(Configuration)");
+    }
+
+    @Test
+    public void ordered_contribution_method()
+    {
+        attemptConfigurationMethod(
+                OrderedConfigurationModule.class,
+                "ioc.test.Ordered",
+                "contributeOrdered(OrderedConfiguration)");
+    }
+
+    @Test
+    public void mapped_contribution_method()
+    {
+        attemptConfigurationMethod(
+                MappedConfigurationModule.class,
+                "ioc.test.Mapped",
+                "contributeMapped(MappedConfiguration)");
+    }
+
+    private void attemptConfigurationMethod(Class moduleClass, String expectedServiceId,
+            String expectedMethodSignature)
+    {
+        Log log = newLog();
+
+        replay();
+
+        ModuleDef md = new DefaultModuleDefImpl(moduleClass, log);
+
+        Set<ContributionDef> defs = md.getContributionDefs();
+
+        assertEquals(defs.size(), 1);
+
+        ContributionDef cd = defs.iterator().next();
+
+        // The target service id is derived from the method name
+
+        assertEquals(cd.getServiceId(), expectedServiceId);
+        assertEquals(cd.toString(), moduleClass.getName() + "." + expectedMethodSignature);
+
+        verify();
+    }
+
+    @Test
+    public void contribution_with_too_many_parameters() throws Exception
+    {
+        Class moduleClass = TooManyContributionParametersModule.class;
+        Method m = findMethod(moduleClass, "contributeTooMany");
+
+        Log log = newLog();
+        log.warn(IOCMessages.tooManyContributionParameters(m));
+
+        replay();
+
+        ModuleDef md = new DefaultModuleDefImpl(moduleClass, log);
+
+        assertTrue(md.getContributionDefs().isEmpty());
+
+        verify();
+    }
+
+    @Test
+    public void contribution_with_no_contribution_parameter() throws Exception
+    {
+        Class moduleClass = NoUsableContributionParameterModule.class;
+        Method m = findMethod(moduleClass, "contributeNoParameter");
+
+        Log log = newLog();
+        log.warn(IOCMessages.noContributionParameter(m));
+
+        replay();
+
+        ModuleDef md = new DefaultModuleDefImpl(moduleClass, log);
+
+        assertTrue(md.getContributionDefs().isEmpty());
+
+        verify();
+    }
+}

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ThreadCleanupHubImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ThreadCleanupHubImplTest.java?view=diff&rev=492319&r1=492318&r2=492319
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ThreadCleanupHubImplTest.java
(original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ThreadCleanupHubImplTest.java
Wed Jan  3 13:51:27 2007
@@ -16,10 +16,10 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.tapestry.ioc.services.ThreadCleanupListener;
-import org.apache.tapestry.ioc.test.TestBase;
+import org.apache.tapestry.ioc.test.IOCTestCase;
 import org.testng.annotations.Test;
 
-public class ThreadCleanupHubImplTest extends TestBase
+public class ThreadCleanupHubImplTest extends IOCTestCase
 {
     @Test
     public void no_listeners()



Mime
View raw message