You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2014/10/30 00:34:39 UTC

svn commit: r1635342 - in /sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src: main/java/org/apache/sling/models/impl/ main/java/org/apache/sling/models/impl/injectors/ main/java/org/apache/sling/models/impl/model/ test/java/org/apache/sling/m...

Author: sseifert
Date: Wed Oct 29 23:34:39 2014
New Revision: 1635342

URL: http://svn.apache.org/r1635342
Log:
SLING-4112 refactor to cache most of reflection inspection tasks

Added:
    sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java   (with props)
Modified:
    sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
    sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java
    sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java
    sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableElement.java
    sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableField.java
    sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableMethod.java
    sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java

Modified: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java?rev=1635342&r1=1635341&r2=1635342&view=diff
==============================================================================
--- sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java (original)
+++ sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java Wed Oct 29 23:34:39 2014
@@ -43,7 +43,6 @@ import java.util.concurrent.ConcurrentHa
 import java.util.concurrent.ConcurrentMap;
 
 import javax.annotation.PostConstruct;
-import javax.inject.Named;
 
 import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.lang.ArrayUtils;
@@ -283,7 +282,7 @@ public class ModelAdapterFactory impleme
          * @param result
          * @return true if injection was successful otherwise false
          */
-        public boolean inject(AnnotatedElement element, Object value, Result<?> result);
+        public boolean inject(InjectableElement element, Object value, Result<?> result);
     }
 
     private class SetFieldCallback implements InjectCallback {
@@ -295,8 +294,8 @@ public class ModelAdapterFactory impleme
         }
 
         @Override
-        public boolean inject(AnnotatedElement element, Object value, Result<?> result) {
-            return setField((Field) element, object, value, result);
+        public boolean inject(InjectableElement element, Object value, Result<?> result) {
+            return setField((Field) element.getAnnotatedElement(), object, value, result);
         }
     }
 
@@ -309,8 +308,8 @@ public class ModelAdapterFactory impleme
         }
 
         @Override
-        public boolean inject(AnnotatedElement element, Object value, Result<?> result) {
-            return setMethod((Method) element, methods, value, result);
+        public boolean inject(InjectableElement element, Object value, Result<?> result) {
+            return setMethod((Method) element.getAnnotatedElement(), methods, value, result);
         }
     }
 
@@ -323,7 +322,7 @@ public class ModelAdapterFactory impleme
         }
 
         @Override
-        public boolean inject(AnnotatedElement element, Object value, Result<?> result) {
+        public boolean inject(InjectableElement element, Object value, Result<?> result) {
             return setConstructorParameter((ConstructorParameter)element, parameterValues, value, result);
         }
     }
@@ -344,7 +343,7 @@ public class ModelAdapterFactory impleme
             }
         }
 
-        String name = getName(element.getAnnotatedElement(), annotationProcessor);
+        String name = getName(element, annotationProcessor);
         Object injectionAdaptable = getAdaptable(adaptable, element.getAnnotatedElement(), annotationProcessor);
 
         if (injectionAdaptable != null) {
@@ -353,7 +352,7 @@ public class ModelAdapterFactory impleme
                 if (source == null || source.equals(injector.getName())) {
                     if (name != null || injector instanceof AcceptsNullName) {
                         Object value = injector.getValue(injectionAdaptable, name, element.getType(), element.getAnnotatedElement(), registry);
-                        if (callback.inject(element.getAnnotatedElement(), value, result)) {
+                        if (callback.inject(element, value, result)) {
                             wasInjectionSuccessful = true;
                             break;
                         }
@@ -363,14 +362,14 @@ public class ModelAdapterFactory impleme
         }
         // if injection failed, use default
         if (!wasInjectionSuccessful) {
-            wasInjectionSuccessful = injectDefaultValue(element.getAnnotatedElement(), element.getType(), annotationProcessor, callback, result);
+            wasInjectionSuccessful = injectDefaultValue(element, annotationProcessor, callback, result);
         }
 
         // if default is not set, check if mandatory
         if (!wasInjectionSuccessful) {
             if (isOptional(element.getAnnotatedElement(), modelAnnotation, annotationProcessor)) {
                 if (element.isPrimitive()) {
-                    injectPrimitiveInitialValue(element.getAnnotatedElement(), element.getType(), callback, result);
+                    injectPrimitiveInitialValue(element, callback, result);
                 }
             } else {
                 return false;
@@ -520,13 +519,13 @@ public class ModelAdapterFactory impleme
             throws InstantiationException, InvocationTargetException, IllegalAccessException {
         ConstructorParameter[] parameters = constructor.getConstructorParameters();
 
-        Set<ConstructorParameter> requiredParameters = new HashSet<ConstructorParameter>();
+        Set<AnnotatedElement> requiredParameters = new HashSet<AnnotatedElement>();
         List<Object> paramValues = new ArrayList<Object>(Arrays.asList(new Object[parameters.length]));
         InjectCallback callback = new SetConstructorParameterCallback(paramValues);
 
         for (int i = 0; i < parameters.length; i++) {
             if (!injectElement(parameters[i], adaptable, modelClass.getModelAnnotation(), registry, callback, result)) {
-                requiredParameters.add(parameters[i]);
+                requiredParameters.add(parameters[i].getAnnotatedElement());
             }
         }
         if (!requiredParameters.isEmpty()) {
@@ -551,7 +550,7 @@ public class ModelAdapterFactory impleme
         
     }
 
-    private boolean injectDefaultValue(AnnotatedElement point, Type type, InjectAnnotationProcessor processor,
+    private boolean injectDefaultValue(InjectableElement point, InjectAnnotationProcessor processor,
             InjectCallback callback, Result<?> result) {
 
         if (processor != null) {
@@ -559,16 +558,15 @@ public class ModelAdapterFactory impleme
                 return callback.inject(point, processor.getDefault(), result);
             }
         }
-        Default defaultAnnotation = point.getAnnotation(Default.class);
+        Default defaultAnnotation = point.getAnnotatedElement().getAnnotation(Default.class);
         if (defaultAnnotation == null) {
             return false;
         }
 
-        type = ReflectionUtil.mapPrimitiveClasses(type);
         Object value = null;
 
-        if (type instanceof Class) {
-            Class<?> injectedClass = (Class<?>) type;
+        if (point.getType() instanceof Class) {
+            Class<?> injectedClass = (Class<?>) point.getType();
             if (injectedClass.isArray()) {
                 Class<?> componentType = injectedClass.getComponentType();
                 if (componentType == String.class) {
@@ -622,7 +620,7 @@ public class ModelAdapterFactory impleme
                 }
             }
         } else {
-            log.warn("Cannot provide default for {}", type);
+            log.warn("Cannot provide default for {}", point.getType());
             return false;
         }
         return callback.inject(point, value, result);
@@ -637,8 +635,8 @@ public class ModelAdapterFactory impleme
      * @param callback Inject callback
      * @param result
      */
-    private void injectPrimitiveInitialValue(AnnotatedElement point, Type wrapperType, InjectCallback callback, Result<?> result) {
-        Type primitiveType = ReflectionUtil.mapWrapperClasses(wrapperType);
+    private void injectPrimitiveInitialValue(InjectableElement point, InjectCallback callback, Result<?> result) {
+        Type primitiveType = ReflectionUtil.mapWrapperClasses(point.getType());
         Object value = null;
         if (primitiveType == int.class) {
             value = Integer.valueOf(0);
@@ -682,7 +680,7 @@ public class ModelAdapterFactory impleme
         }
     }
 
-    private String getName(AnnotatedElement element, InjectAnnotationProcessor processor) {
+    private String getName(InjectableElement element, InjectAnnotationProcessor processor) {
         // try to get the name from injector-specific annotation
         if (processor != null) {
             String name = processor.getName();
@@ -690,38 +688,10 @@ public class ModelAdapterFactory impleme
                 return name;
             }
         }
-        // alternative for name attribute
-        Named named = element.getAnnotation(Named.class);
-        if (named != null) {
-            return named.value();
-        }
-        if (element instanceof Method) {
-            return getNameFromMethod((Method) element);
-        } else if (element instanceof Field) {
-            return getNameFromField((Field) element);
-        } else if (element instanceof ConstructorParameter) {
-            // implicit name not supported for constructor parameters - but do not throw exception because class-based injection is still possible
-            return null;
-        } else {
-            throw new IllegalArgumentException("The given element must be either method or field but is " + element);
-        }
-    }
-
-    private String getNameFromField(Field field) {
-        return field.getName();
+        // get name from @Named annotation or element name
+        return element.getName();
     }
 
-    private String getNameFromMethod(Method method) {
-        String methodName = method.getName();
-        if (methodName.startsWith("get")) {
-            return methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
-        } else if (methodName.startsWith("is")) {
-            return methodName.substring(2, 3).toLowerCase() + methodName.substring(3);
-        } else {
-            return methodName;
-        }
-    }
-    
     private boolean addMethodIfNotOverriden(List<Method> methods, Method newMethod) {
         for (Method method : methods) {
             if (method.getName().equals(newMethod.getName())) {

Modified: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java?rev=1635342&r1=1635341&r2=1635342&view=diff
==============================================================================
--- sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java (original)
+++ sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java Wed Oct 29 23:34:39 2014
@@ -53,8 +53,8 @@ public class SelfInjector implements Inj
         } else {
             // special handling for the first constructor parameter
             // apply class-based injection only if class matches or is a superclass
-            if (element instanceof ConstructorParameter &&
-                    ((ConstructorParameter)element).getParameterIndex() == 0 &&
+            if (element instanceof ConstructorParameter.FakeAnnotatedElement &&
+                    ((ConstructorParameter.FakeAnnotatedElement)element).getParameterIndex() == 0 &&
                     type instanceof Class<?> &&
                     ((Class<?>)type).isAssignableFrom(adaptable.getClass())) {
                 return adaptable;

Added: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java?rev=1635342&view=auto
==============================================================================
--- sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java (added)
+++ sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java Wed Oct 29 23:34:39 2014
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.models.impl.model;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.inject.Named;
+
+abstract class AbstractInjectableElement implements InjectableElement {
+    
+    private final AnnotatedElement element;
+    private final Named namedAnnotation;
+    
+    public AbstractInjectableElement(AnnotatedElement element) {
+        this.element = element;
+        this.namedAnnotation = element.getAnnotation(Named.class);
+    }
+
+    @Override
+    public final AnnotatedElement getAnnotatedElement() {
+        return this.element;
+    }
+
+    @Override
+    public final String getName() {
+        if (this.namedAnnotation != null) {
+            return this.namedAnnotation.value();
+        }
+        return getElementName();
+    }
+    
+    protected abstract String getElementName();
+    
+}

Propchange: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Wed Oct 29 23:34:39 2014
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java?rev=1635342&r1=1635341&r2=1635342&view=diff
==============================================================================
--- sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java (original)
+++ sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java Wed Oct 29 23:34:39 2014
@@ -27,48 +27,21 @@ import java.lang.reflect.Type;
  * AnnotatedElement. This class acts as a facade to ease
  * compatibility with field and method injection.
  */
-public class ConstructorParameter implements AnnotatedElement, InjectableElement {
+public class ConstructorParameter extends AbstractInjectableElement {
 
-    private final Annotation[] annotations;
     private final Type parameterType;
     private final Type genericType;
     private final boolean isPrimitive;
     private final int parameterIndex;
 
     public ConstructorParameter(Annotation[] annotations, Type parameterType, Type genericType, boolean isPrimitive, int parameterIndex) {
-        this.annotations = annotations;
+        super(new FakeAnnotatedElement(annotations, parameterIndex));
         this.parameterType = parameterType;
         this.genericType = genericType;
         this.isPrimitive = isPrimitive;
         this.parameterIndex = parameterIndex;
     }
 
-    @Override
-    public boolean isAnnotationPresent(Class<? extends Annotation> paramClass) {
-        return getAnnotation(paramClass) != null;
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public <T extends Annotation> T getAnnotation(Class<T> paramClass) {
-        for (Annotation annotation : this.annotations) {
-            if (paramClass.isInstance(annotation)) {
-                return (T)annotation;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public Annotation[] getAnnotations() {
-        return annotations;
-    }
-
-    @Override
-    public Annotation[] getDeclaredAnnotations() {
-        return annotations;
-    }
-
     public Type getGenericType() {
         return this.genericType;
     }
@@ -91,7 +64,6 @@ public class ConstructorParameter implem
         return isPrimitive;
     }
     
-
     public int getParameterIndex() {
         return this.parameterIndex;
     }
@@ -102,8 +74,51 @@ public class ConstructorParameter implem
     }
 
     @Override
-    public AnnotatedElement getAnnotatedElement() {
-        return this;
+    public String getElementName() {
+        // implicit name not supported for constructor parameters - but do not throw exception because class-based injection is still possible
+        return null;
+    }
+    
+    public static class FakeAnnotatedElement implements AnnotatedElement {
+        
+        private final Annotation[] annotations;
+        private final int parameterIndex;
+        
+        public FakeAnnotatedElement(Annotation[] annotations, int parameterIndex) {
+            this.annotations = annotations;
+            this.parameterIndex = parameterIndex;
+        }
+
+        @Override
+        public boolean isAnnotationPresent(Class<? extends Annotation> paramClass) {
+            return getAnnotation(paramClass) != null;
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public <T extends Annotation> T getAnnotation(Class<T> paramClass) {
+            for (Annotation annotation : this.annotations) {
+                if (paramClass.isInstance(annotation)) {
+                    return (T)annotation;
+                }
+            }
+            return null;
+        }
+
+        @Override
+        public Annotation[] getAnnotations() {
+            return annotations;
+        }
+
+        @Override
+        public Annotation[] getDeclaredAnnotations() {
+            return annotations;
+        }
+        
+        public int getParameterIndex() {
+            return this.parameterIndex;
+        }
+
     }
    
 }

Modified: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableElement.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableElement.java?rev=1635342&r1=1635341&r2=1635342&view=diff
==============================================================================
--- sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableElement.java (original)
+++ sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableElement.java Wed Oct 29 23:34:39 2014
@@ -34,5 +34,10 @@ public interface InjectableElement {
      * @return true if original type of injectable is a primitive type
      */
     boolean isPrimitive();
+    
+    /**
+     * @return Name for injection
+     */
+    String getName();
 
 }

Modified: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableField.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableField.java?rev=1635342&r1=1635341&r2=1635342&view=diff
==============================================================================
--- sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableField.java (original)
+++ sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableField.java Wed Oct 29 23:34:39 2014
@@ -18,18 +18,18 @@
  */
 package org.apache.sling.models.impl.model;
 
-import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Field;
 import java.lang.reflect.Type;
 
 import org.apache.sling.models.impl.ReflectionUtil;
 
-public class InjectableField implements InjectableElement {
+public class InjectableField extends AbstractInjectableElement {
     
     private final Field field;
     private final Type genericType;
     
     public InjectableField(Field field) {
+        super(field);
         this.field = field;
         this.genericType = ReflectionUtil.mapPrimitiveClasses(field.getGenericType());
     }
@@ -38,11 +38,6 @@ public class InjectableField implements 
         return field;
     }
 
-    @Override
-    public AnnotatedElement getAnnotatedElement() {
-        return field;
-    }
-
     /**
      * @return Type of injectable mapped to wrapper class
      */
@@ -57,4 +52,9 @@ public class InjectableField implements 
         return false;
     }
 
+    @Override
+    public String getElementName() {
+        return field.getName();
+    }
+
 }

Modified: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableMethod.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableMethod.java?rev=1635342&r1=1635341&r2=1635342&view=diff
==============================================================================
--- sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableMethod.java (original)
+++ sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/main/java/org/apache/sling/models/impl/model/InjectableMethod.java Wed Oct 29 23:34:39 2014
@@ -18,19 +18,19 @@
  */
 package org.apache.sling.models.impl.model;
 
-import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 
 import org.apache.sling.models.impl.ReflectionUtil;
 
-public class InjectableMethod implements InjectableElement {
+public class InjectableMethod extends AbstractInjectableElement {
     
     private final Method method;
     private final Type genericReturnType;
     private final Type returnType;
 
     public InjectableMethod(Method method) {
+        super(method);
         this.method = method;
         this.genericReturnType = method.getGenericReturnType();
         this.returnType = ReflectionUtil.mapPrimitiveClasses(this.genericReturnType);
@@ -40,11 +40,6 @@ public class InjectableMethod implements
         return method;
     }
 
-    @Override
-    public AnnotatedElement getAnnotatedElement() {
-        return method;
-    }
-
     /**
      * @return Generic return type of method (may be primitive)
      */
@@ -66,4 +61,16 @@ public class InjectableMethod implements
         return this.returnType != this.genericReturnType;
     }
 
+    @Override
+    public String getElementName() {
+        String methodName = method.getName();
+        if (methodName.startsWith("get")) {
+            return methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
+        } else if (methodName.startsWith("is")) {
+            return methodName.substring(2, 3).toLowerCase() + methodName.substring(3);
+        } else {
+            return methodName;
+        }
+    }
+
 }

Modified: sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java?rev=1635342&r1=1635341&r2=1635342&view=diff
==============================================================================
--- sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java (original)
+++ sling/whiteboard/sseifert/SLING-4112_models_tuning/impl/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java Wed Oct 29 23:34:39 2014
@@ -21,6 +21,7 @@ package org.apache.sling.models.impl.inj
 import static org.junit.Assert.*;
 import static org.mockito.Mockito.*;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
 
 import javax.servlet.http.HttpServletRequest;
@@ -46,43 +47,40 @@ public class SelfInjectorTest {
     @Mock
     private AnnotatedElement annotatedElement;
     
-    @Mock
     private ConstructorParameter firstConstructorParameter;
-    
-    @Mock
     private ConstructorParameter secondConstructorParameter;
     
     @Before
     public void setup() {
-        when(firstConstructorParameter.getParameterIndex()).thenReturn(0);
-        when(secondConstructorParameter.getParameterIndex()).thenReturn(1);
+        firstConstructorParameter = new ConstructorParameter(new Annotation[0], Object.class, Object.class, true, 0);
+        secondConstructorParameter = new ConstructorParameter(new Annotation[0], Object.class, Object.class, true, 1);
     }
 
     @Test
     public void testMatchingClass() {
-        assertSame(request, injector.getValue(request, "notRelevant", SlingHttpServletRequest.class, firstConstructorParameter, null));
-        assertNull(injector.getValue(request, "notRelevant", SlingHttpServletRequest.class, secondConstructorParameter, null));
+        assertSame(request, injector.getValue(request, "notRelevant", SlingHttpServletRequest.class, firstConstructorParameter.getAnnotatedElement(), null));
+        assertNull(injector.getValue(request, "notRelevant", SlingHttpServletRequest.class, secondConstructorParameter.getAnnotatedElement(), null));
         assertNull(injector.getValue(request, "notRelevant", SlingHttpServletRequest.class, annotatedElement, null));
     }
 
     @Test
     public void testMatchingSubClass() {
-        assertSame(request, injector.getValue(request, "notRelevant", HttpServletRequest.class, firstConstructorParameter, null));
-        assertNull(injector.getValue(request, "notRelevant", HttpServletRequest.class, secondConstructorParameter, null));
+        assertSame(request, injector.getValue(request, "notRelevant", HttpServletRequest.class, firstConstructorParameter.getAnnotatedElement(), null));
+        assertNull(injector.getValue(request, "notRelevant", HttpServletRequest.class, secondConstructorParameter.getAnnotatedElement(), null));
         assertNull(injector.getValue(request, "notRelevant", HttpServletRequest.class, annotatedElement, null));
     }
 
     @Test
     public void testNotMatchingClass() {
-        assertNull(injector.getValue(request, "notRelevant", ResourceResolver.class, firstConstructorParameter, null));
-        assertNull(injector.getValue(request, "notRelevant", ResourceResolver.class, secondConstructorParameter, null));
+        assertNull(injector.getValue(request, "notRelevant", ResourceResolver.class, firstConstructorParameter.getAnnotatedElement(), null));
+        assertNull(injector.getValue(request, "notRelevant", ResourceResolver.class, secondConstructorParameter.getAnnotatedElement(), null));
         assertNull(injector.getValue(request, "notRelevant", ResourceResolver.class, annotatedElement, null));
     }
 
     @Test
     public void testWithNullName() {
-        assertSame(request, injector.getValue(request, null, SlingHttpServletRequest.class, firstConstructorParameter, null));
-        assertNull(injector.getValue(request, null, SlingHttpServletRequest.class, secondConstructorParameter, null));
+        assertSame(request, injector.getValue(request, null, SlingHttpServletRequest.class, firstConstructorParameter.getAnnotatedElement(), null));
+        assertNull(injector.getValue(request, null, SlingHttpServletRequest.class, secondConstructorParameter.getAnnotatedElement(), null));
         assertNull(injector.getValue(request, null, SlingHttpServletRequest.class, annotatedElement, null));
     }