You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/09/24 06:51:48 UTC

svn commit: r1175102 - in /tapestry/tapestry5/trunk: tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/ tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/util/ tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ tapestr...

Author: hlship
Date: Sat Sep 24 04:51:48 2011
New Revision: 1175102

URL: http://svn.apache.org/viewvc?rev=1175102&view=rev
Log:
TAP5-1664: @InjectResource annotation should be removed, behavior of @Inject on a field should be changed to consider resources first

Removed:
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FailedFieldInjectionStringTransformer.java
Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/UtilMessages.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/util/UtilStrings.properties
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FieldResourceInjectionModule.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
    tapestry/tapestry5/trunk/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/InjectResource.java

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java?rev=1175102&r1=1175101&r2=1175102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java Sat Sep 24 04:51:48 2011
@@ -333,21 +333,17 @@ public class InternalUtils
                             return;
                         }
 
-                        if (ap.getAnnotation(Inject.class) != null)
-                        {
-                            inject(object, f, locator.getObject(fieldType, ap));
-                            return;
-                        }
-
-                        if (ap.getAnnotation(InjectResource.class) != null)
+                        if (ap.getAnnotation(Inject.class) != null || ap.getAnnotation(InjectResource.class) != null)
                         {
                             Object value = resources.findResource(fieldType, f.getGenericType());
 
-                            if (value == null)
-                                throw new RuntimeException(UtilMessages.injectResourceFailure(f.getName(), fieldType));
-
-                            inject(object, f, value);
+                            if (value != null)
+                            {
+                                inject(object, f, value);
+                                return;
+                            }
 
+                            inject(object, f, locator.getObject(fieldType, ap));
                             return;
                         }
 

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/UtilMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/UtilMessages.java?rev=1175102&r1=1175101&r2=1175102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/UtilMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/UtilMessages.java Sat Sep 24 04:51:48 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2008, 2010 The Apache Software Foundation
+// Copyright 2006, 2008, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -15,7 +15,6 @@
 package org.apache.tapestry5.ioc.internal.util;
 
 import org.apache.tapestry5.ioc.Messages;
-import org.apache.tapestry5.ioc.services.ClassFabUtils;
 
 class UtilMessages
 {
@@ -49,9 +48,4 @@ class UtilMessages
     {
         return MESSAGES.format("bad-marker-annotation", annotationClass.getName());
     }
-
-    static String injectResourceFailure(String fieldName, Class fieldType)
-    {
-        return MESSAGES.format("inject-resource-failure", fieldName, ClassFabUtils.toJavaClassName(fieldType));
-    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/util/UtilStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/util/UtilStrings.properties?rev=1175102&r1=1175101&r2=1175102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/util/UtilStrings.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/util/UtilStrings.properties Sat Sep 24 04:51:48 2011
@@ -1,4 +1,4 @@
-# Copyright 2006, 2008, 2010 The Apache Software Foundation
+# Copyright 2006, 2008, 2010, 2011 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -16,5 +16,4 @@ dependency-cycle=Unable to add '%s' as a
 duplicate-orderer=Could not add object with duplicate id '%s'.  The duplicate object has been ignored.
 constraint-format=Could not parse ordering constraint '%s' (for '%s'). The constraint has been ignored.
 one-shot-lock=Method %s may no longer be invoked.
-bad-marker-annotation=Marker annotation class %s is not valid because it is not visible at runtime. Add a @Retention(RetentionPolicy.RUNTIME) to the class.
-inject-resource-failure=Unable to determine resource value to inject into field '%s' (of type %s).
+bad-marker-annotation=Marker annotation class %s is not valid because it is not visible at runtime. Add a @Retention(RetentionPolicy.RUNTIME) to the class.
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FieldResourceInjectionModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FieldResourceInjectionModule.java?rev=1175102&r1=1175101&r2=1175102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FieldResourceInjectionModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FieldResourceInjectionModule.java Sat Sep 24 04:51:48 2011
@@ -1,4 +1,4 @@
-//  Copyright 2008 The Apache Software Foundation
+//  Copyright 2008, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ public class FieldResourceInjectionModul
     public static void bind(ServiceBinder binder)
     {
         binder.bind(FieldResourceService.class);
-        binder.bind(StringTransformer.class, FailedFieldInjectionStringTransformer.class);
     }
 
     public static void contributeFieldResourceService(Configuration<String> configuration)

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java?rev=1175102&r1=1175101&r2=1175102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java Sat Sep 24 04:51:48 2011
@@ -14,31 +14,20 @@
 
 package org.apache.tapestry5.ioc;
 
-import java.io.File;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.sql.PreparedStatement;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.tapestry5.ioc.internal.*;
-import org.apache.tapestry5.ioc.internal.services.SimpleAnnotation;
 import org.apache.tapestry5.ioc.internal.services.StartupModule2;
-import org.apache.tapestry5.ioc.services.Builtin;
-import org.apache.tapestry5.ioc.services.ServiceActivity;
-import org.apache.tapestry5.ioc.services.ServiceActivityScoreboard;
-import org.apache.tapestry5.ioc.services.Status;
-import org.apache.tapestry5.ioc.services.SymbolSource;
-import org.apache.tapestry5.ioc.services.TypeCoercer;
+import org.apache.tapestry5.ioc.services.*;
 import org.apache.tapestry5.ioc.util.NonmatchingMappedConfigurationOverrideModule;
 import org.easymock.EasyMock;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.PreparedStatement;
+import java.util.*;
+
 /**
  * A few tests that are easiest (or even just possible) by building a Registry and trying out a few
  * things.
@@ -59,8 +48,7 @@ public class IntegrationTest extends IOC
         {
             buildRegistry(FredModule.class, DuplicateFredModule.class);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertTrue(ex.getMessage().startsWith("Service id 'Fred' has already been defined by"));
 
@@ -138,8 +126,7 @@ public class IntegrationTest extends IOC
         {
             service.run();
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex,
                     "Proxy for service Fred is no longer active because the IOC Registry has been shut down.");
@@ -246,8 +233,7 @@ public class IntegrationTest extends IOC
             runnable.run();
 
             unreachable();
-        }
-        catch (Exception ex)
+        } catch (Exception ex)
         {
             assertMessageContains(ex, "Error building service proxy for service 'UnknownScope'",
                     "Unknown service scope 'magic'");
@@ -265,8 +251,7 @@ public class IntegrationTest extends IOC
         {
             r.getService(StringBuilder.class);
             unreachable();
-        }
-        catch (Exception ex)
+        } catch (Exception ex)
         {
             assertMessageContains(ex,
                     "Error building service proxy for service 'ScopeRequiresAProxyAndNoInterfaceIsProvided'",
@@ -358,8 +343,7 @@ public class IntegrationTest extends IOC
             runnable.run();
 
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertTrue(ex.getMessage().contains("has failed due to recursion"));
         }
@@ -418,8 +402,7 @@ public class IntegrationTest extends IOC
         {
             pingable.ping();
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex, "Error invoking constructor", "ExceptionInConstructorServiceImpl()",
                     "for service 'Pingable'", "Yes, we have no tomatoes.");
@@ -464,8 +447,7 @@ public class IntegrationTest extends IOC
         {
             buildRegistry(ConventionModuleImplementationNotFound.class);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex, "No service implements the interface " + StringTransformer.class.getName()
                     + ". Please provide");
@@ -479,8 +461,7 @@ public class IntegrationTest extends IOC
         {
             buildRegistry(ConventionFailureModule.class);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex, "No service implements the interface " + Pingable.class.getName());
         }
@@ -520,7 +501,9 @@ public class IntegrationTest extends IOC
         r.shutdown();
     }
 
-    /** TAP5-967 */
+    /**
+     * TAP5-967
+     */
     @Test
     public void autobuild_with_description_via_registry()
     {
@@ -555,8 +538,7 @@ public class IntegrationTest extends IOC
             pingable.ping();
 
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex,
                     "Class org.apache.tapestry5.ioc.UnbuildablePingable does not contain a public constructor needed to autobuild.");
@@ -579,8 +561,7 @@ public class IntegrationTest extends IOC
             r.autobuild(UnbuildablePingable.class);
 
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex,
                     "Class org.apache.tapestry5.ioc.UnbuildablePingable does not contain a public constructor needed to autobuild.");
@@ -599,8 +580,7 @@ public class IntegrationTest extends IOC
             r.autobuild(FailInConstructorRunnable.class);
 
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex,
                     "Error invoking constructor org.apache.tapestry5.ioc.FailInConstructorRunnable()",
@@ -623,8 +603,7 @@ public class IntegrationTest extends IOC
         {
             r.getService("PeekABoo", Runnable.class);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex, "Service id \'PeekABoo\' is not defined by any module.");
         }
@@ -642,8 +621,7 @@ public class IntegrationTest extends IOC
         {
             r.getService(PreparedStatement.class);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertEquals(ex.getMessage(), "No service implements the interface java.sql.PreparedStatement.");
         }
@@ -660,8 +638,7 @@ public class IntegrationTest extends IOC
         {
             r.getService(Pingable.class);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertEquals(
                     ex.getMessage(),
@@ -738,8 +715,7 @@ public class IntegrationTest extends IOC
         {
             g.getGreeting();
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(
                     ex,
@@ -763,8 +739,7 @@ public class IntegrationTest extends IOC
         {
             g.getGreeting();
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(
                     ex,
@@ -970,8 +945,7 @@ public class IntegrationTest extends IOC
         {
             g.getGreeting();
             unreachable();
-        }
-        catch (Exception ex)
+        } catch (Exception ex)
         {
             assertEquals(ex.getMessage(),
                     "Exception constructing service 'BrokenGreeter': Failure inside ServiceBuilder callback.");
@@ -990,7 +964,7 @@ public class IntegrationTest extends IOC
         URL url = fakejar.toURL();
 
         URLClassLoader loader = new URLClassLoader(new URL[]
-        { url }, Thread.currentThread().getContextClassLoader());
+                {url}, Thread.currentThread().getContextClassLoader());
 
         RegistryBuilder builder = new RegistryBuilder(loader);
 
@@ -998,8 +972,7 @@ public class IntegrationTest extends IOC
         {
             IOCUtilities.addDefaultModules(builder);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex, "Exception loading module(s) from manifest",
                     "Failure loading Tapestry IoC module class does.not.exist.Module");
@@ -1044,8 +1017,7 @@ public class IntegrationTest extends IOC
         {
             trigger.run();
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex, "Construction of service 'TypeCoercer' has failed due to recursion");
         }
@@ -1063,8 +1035,7 @@ public class IntegrationTest extends IOC
             r.getService("Trigger", Runnable.class).run();
 
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex,
                     "Module class org.apache.tapestry5.ioc.internal.PrivateConstructorModule does not contain any public constructors.");
@@ -1151,28 +1122,6 @@ public class IntegrationTest extends IOC
     }
 
     /**
-     * TAP5-292
-     */
-    @Test
-    public void failed_field_resource_injection()
-    {
-        Registry r = buildRegistry(FieldResourceInjectionModule.class);
-
-        StringTransformer s = r.getService(StringTransformer.class);
-
-        try
-        {
-            s.transform("hello");
-            unreachable();
-        }
-        catch (RuntimeException ex)
-        {
-            assertMessageContains(ex,
-                    "Unable to determine resource value to inject into field 'unknownRunnable' (of type java.lang.Runnable).");
-        }
-    }
-
-    /**
      * TAP5-291
      */
     @Test
@@ -1195,8 +1144,7 @@ public class IntegrationTest extends IOC
         {
             buildRegistry(InvalidContributeDefModule.class);
             unreachable();
-        }
-        catch (IllegalArgumentException ex)
+        } catch (IllegalArgumentException ex)
         {
             assertMessageContains(
                     ex,
@@ -1215,8 +1163,7 @@ public class IntegrationTest extends IOC
         {
             buildRegistry(ExtraMethodsModule.class);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex,
                     "Module class org.apache.tapestry5.ioc.ExtraMethodsModule contains unrecognized public methods: ",
@@ -1298,8 +1245,7 @@ public class IntegrationTest extends IOC
         {
             service.getNames();
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(
                     ex,
@@ -1323,8 +1269,7 @@ public class IntegrationTest extends IOC
         {
             service.getNames();
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             // Can't get too specific since we don't know which module will get processed first
             assertMessageContains(ex, "Error invoking service contribution method ",
@@ -1364,8 +1309,7 @@ public class IntegrationTest extends IOC
         {
             sl.keys();
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(
                     ex,
@@ -1391,8 +1335,7 @@ public class IntegrationTest extends IOC
         {
             sl.keys();
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex, "Error invoking service contribution method",
                     "Contribution key fred has already been overridden");
@@ -1422,8 +1365,7 @@ public class IntegrationTest extends IOC
         {
             buildRegistry(NonVoidAdvisorMethodModule.class);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(
                     ex,
@@ -1442,8 +1384,7 @@ public class IntegrationTest extends IOC
         {
             buildRegistry(AdviceMethodMissingAdvisorParameterModule.class);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertMessageContains(ex,
                     "Advise method org.apache.tapestry5.ioc.AdviceMethodMissingAdvisorParameterModule.adviseBar()",
@@ -1496,8 +1437,7 @@ public class IntegrationTest extends IOC
         {
             buildRegistry(InvalidContributeDefModule2.class);
             unreachable();
-        }
-        catch (Exception e)
+        } catch (Exception e)
         {
             assertMessageContains(
                     e,
@@ -1515,8 +1455,7 @@ public class IntegrationTest extends IOC
         {
             buildRegistry(InvalidContributeDefModule3.class);
             unreachable();
-        }
-        catch (Exception e)
+        } catch (Exception e)
         {
             assertMessageContains(
                     e,

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java?rev=1175102&r1=1175101&r2=1175102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java Sat Sep 24 04:51:48 2011
@@ -14,35 +14,9 @@
 
 package org.apache.tapestry5.ioc.internal.util;
 
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newMap;
-import static org.apache.tapestry5.ioc.internal.util.InternalUtils.toList;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.isA;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.tapestry5.func.F;
 import org.apache.tapestry5.func.Predicate;
-import org.apache.tapestry5.ioc.AnnotationProvider;
-import org.apache.tapestry5.ioc.Locatable;
-import org.apache.tapestry5.ioc.Location;
-import org.apache.tapestry5.ioc.ObjectCreator;
-import org.apache.tapestry5.ioc.ObjectLocator;
-import org.apache.tapestry5.ioc.OperationTracker;
-import org.apache.tapestry5.ioc.ScopeConstants;
-import org.apache.tapestry5.ioc.ServiceBuilderResources;
+import org.apache.tapestry5.ioc.*;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.def.ServiceDef;
 import org.apache.tapestry5.ioc.def.ServiceDef2;
@@ -56,6 +30,17 @@ import org.easymock.IAnswer;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
+import java.io.Closeable;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.*;
+
+import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newMap;
+import static org.apache.tapestry5.ioc.internal.util.InternalUtils.toList;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.isA;
+
 public class InternalUtilsTest extends IOCTestCase
 {
     private final OperationTracker tracker = new QuietOperationTracker();
@@ -127,7 +112,7 @@ public class InternalUtilsTest extends I
     public void array_size_when_non_null()
     {
         Object[] array =
-        { 1, 2, 3 };
+                {1, 2, 3};
 
         assertEquals(InternalUtils.size(array), 3);
     }
@@ -142,15 +127,15 @@ public class InternalUtilsTest extends I
     public Object[][] memberNameData()
     {
         return new Object[][]
-        {
-        { "simple", "simple" },
-        { "_name", "name" },
-        { "$name", "name" },
-        { "ruby_style", "ruby_style" },
-        { "__$ruby_style_", "ruby_style" },
-        { "$_$__$__$_$___$_$_$_$$name$", "name" },
-        { "foo_", "foo" },
-        { "_foo_", "foo" } };
+                {
+                        {"simple", "simple"},
+                        {"_name", "name"},
+                        {"$name", "name"},
+                        {"ruby_style", "ruby_style"},
+                        {"__$ruby_style_", "ruby_style"},
+                        {"$_$__$__$_$___$_$_$_$$name$", "name"},
+                        {"foo_", "foo"},
+                        {"_foo_", "foo"}};
     }
 
     @Test
@@ -160,8 +145,7 @@ public class InternalUtilsTest extends I
         {
             InternalUtils.stripMemberName("!foo");
             unreachable();
-        }
-        catch (IllegalArgumentException ex)
+        } catch (IllegalArgumentException ex)
         {
             assertEquals(ex.getMessage(), "Input '!foo' is not a valid Java identifier.");
         }
@@ -239,12 +223,12 @@ public class InternalUtilsTest extends I
     public Object[][] capitalize_inputs()
     {
         return new Object[][]
-        {
-        { "hello", "Hello" },
-        { "Goodbye", "Goodbye" },
-        { "", "" },
-        { "a", "A" },
-        { "A", "A" } };
+                {
+                        {"hello", "Hello"},
+                        {"Goodbye", "Goodbye"},
+                        {"", ""},
+                        {"a", "A"},
+                        {"A", "A"}};
     }
 
     @Test
@@ -346,8 +330,7 @@ public class InternalUtilsTest extends I
         {
             i.remove();
             unreachable();
-        }
-        catch (UnsupportedOperationException ex)
+        } catch (UnsupportedOperationException ex)
         {
 
         }
@@ -389,10 +372,9 @@ public class InternalUtilsTest extends I
         try
         {
             InternalUtils.validateMarkerAnnotations(new Class[]
-            { Inject.class, NotRetainedRuntime.class });
+                    {Inject.class, NotRetainedRuntime.class});
             unreachable();
-        }
-        catch (IllegalArgumentException ex)
+        } catch (IllegalArgumentException ex)
         {
             assertEquals(
                     ex.getMessage(),
@@ -455,7 +437,7 @@ public class InternalUtilsTest extends I
         assertEquals(c.getParameterTypes().length, 1);
         assertEquals(c.getParameterTypes()[0], String.class);
     }
-    
+
     @Test
     public void constructor_with_javax_inject_annotation()
     {
@@ -464,15 +446,14 @@ public class InternalUtilsTest extends I
         assertEquals(c.getParameterTypes().length, 1);
         assertEquals(c.getParameterTypes()[0], String.class);
     }
-    
+
     @Test
     public void too_many_autobuild_constructors()
     {
-    	try
-    	{
-    		InternalUtils.findAutobuildConstructor(TooManyAutobuildConstructorsBean.class);
-    	}
-        catch (IllegalArgumentException ex)
+        try
+        {
+            InternalUtils.findAutobuildConstructor(TooManyAutobuildConstructorsBean.class);
+        } catch (IllegalArgumentException ex)
         {
             assertEquals(
                     ex.getMessage(),
@@ -490,8 +471,7 @@ public class InternalUtilsTest extends I
         {
             InternalUtils.validateConstructorForAutobuild(cons);
             unreachable();
-        }
-        catch (IllegalArgumentException ex)
+        } catch (IllegalArgumentException ex)
         {
             assertEquals(
                     ex.getMessage(),
@@ -509,8 +489,7 @@ public class InternalUtilsTest extends I
         {
             InternalUtils.validateConstructorForAutobuild(cons);
             unreachable();
-        }
-        catch (IllegalArgumentException ex)
+        } catch (IllegalArgumentException ex)
         {
             assertMessageContains(
                     ex,
@@ -535,7 +514,7 @@ public class InternalUtilsTest extends I
 
         verify();
     }
-    
+
     @Test
     public void javax_inject_named_annotation_on_field()
     {
@@ -553,15 +532,15 @@ public class InternalUtilsTest extends I
 
         verify();
     }
-    
 
-    
+
     @Test
     public void javax_inject_annotation_on_field()
     {
         ObjectLocator ol = mockObjectLocator();
         FieldInjectionViaInject target = new FieldInjectionViaInject();
         final SymbolSource ss = mockSymbolSource();
+        InjectionResources ir = newMock(InjectionResources.class);
 
         IAnswer answer = new IAnswer()
         {
@@ -579,11 +558,13 @@ public class InternalUtilsTest extends I
             }
         };
 
+        expect(ir.findResource(SymbolSource.class, SymbolSource.class)).andReturn(null);
+
         expect(ol.getObject(eq(SymbolSource.class), isA(AnnotationProvider.class))).andAnswer(answer);
 
         replay();
 
-        InternalUtils.injectIntoFields(target, ol, null, tracker);
+        InternalUtils.injectIntoFields(target, ol, ir, tracker);
 
         assertSame(target.getSymbolSource(), ss);
 
@@ -596,6 +577,7 @@ public class InternalUtilsTest extends I
         ObjectLocator ol = mockObjectLocator();
         FieldInjectionViaInject target = new FieldInjectionViaInject();
         final SymbolSource ss = mockSymbolSource();
+        InjectionResources ir = newMock(InjectionResources.class);
 
         IAnswer answer = new IAnswer()
         {
@@ -613,11 +595,13 @@ public class InternalUtilsTest extends I
             }
         };
 
+        expect(ir.findResource(SymbolSource.class, SymbolSource.class)).andReturn(null);
+
         expect(ol.getObject(eq(SymbolSource.class), isA(AnnotationProvider.class))).andAnswer(answer);
 
         replay();
 
-        InternalUtils.injectIntoFields(target, ol, null, tracker);
+        InternalUtils.injectIntoFields(target, ol, ir, tracker);
 
         assertSame(target.getSymbolSource(), ss);
 
@@ -643,8 +627,7 @@ public class InternalUtilsTest extends I
             InternalUtils.injectIntoFields(target, ol, null, tracker);
 
             unreachable();
-        }
-        catch (Exception ex)
+        } catch (Exception ex)
         {
             assertMessageContains(ex,
                     "Unable to set field 'fred' of <FieldInjectionViaInjectService> to NotTheRightType");

Modified: tapestry/tapestry5/trunk/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/InjectResource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/InjectResource.java?rev=1175102&r1=1175101&r2=1175102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/InjectResource.java (original)
+++ tapestry/tapestry5/trunk/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/InjectResource.java Sat Sep 24 04:51:48 2011
@@ -20,6 +20,10 @@ import java.lang.annotation.*;
 /**
  * Annotation used with field injection when the desired injection value is a resource (such as a service id, service
  * configuration, or logger) and not an object obtained from the {@link org.apache.tapestry5.ioc.services.MasterObjectProvider}.
+ * <p/>
+ * In Tapestry 5.3, the logic for this was changed so that it is treated the same as {@link @Inject}. This reflects what people usually want.
+ *
+ * @deprecated Deprecated in Tapestry 5.3, to be removed in a later release. Use {@link Inject} instead.
  */
 @Target(ElementType.FIELD)
 @Retention(RetentionPolicy.RUNTIME)