SLING-7040 : Update commons lang 2.x to 3.5
authorCarsten Ziegeler <cziegeler@apache.org>
Wed, 9 Aug 2017 15:52:16 +0000 (15:52 +0000)
committerCarsten Ziegeler <cziegeler@apache.org>
Wed, 9 Aug 2017 15:52:16 +0000 (15:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1804564 13f79535-47bb-0310-9956-ffa450edef68

18 files changed:
pom.xml
src/main/java/org/apache/sling/models/impl/AdapterImplementations.java
src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
src/main/java/org/apache/sling/models/impl/injectors/BindingsInjector.java
src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java
src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
src/main/java/org/apache/sling/models/impl/injectors/ResourcePathInjector.java
src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
src/main/java/org/apache/sling/models/impl/via/BeanPropertyViaProvider.java
src/main/java/org/apache/sling/models/impl/via/ChildResourceViaProvider.java
src/main/java/org/apache/sling/models/impl/via/ForcedResourceTypeViaProvider.java
src/test/java/org/apache/sling/models/impl/ResourceModelClassesTest.java
src/test/java/org/apache/sling/models/impl/ResourceModelConstructorTest.java
src/test/java/org/apache/sling/models/impl/ResourceModelInterfacesTest.java
src/test/java/org/apache/sling/models/impl/ViaTest.java

diff --git a/pom.xml b/pom.xml
index c8d12c6..948eef2 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <scope>provided</scope>\r
         </dependency>\r
         <dependency>\r
+            <groupId>org.apache.commons</groupId>\r
+            <artifactId>commons-lang3</artifactId>\r
+            <version>3.4</version>\r
+            <scope>provided</scope>\r
+        </dependency>\r
+        <dependency>\r
             <groupId>org.osgi</groupId>\r
             <artifactId>org.osgi.core</artifactId>\r
             <scope>provided</scope>\r
             <scope>provided</scope>\r
         </dependency>\r
         <dependency>\r
-            <groupId>org.apache.felix</groupId>\r
-            <artifactId>org.apache.felix.scr.annotations</artifactId>\r
-            <scope>provided</scope>\r
-        </dependency>\r
-        <dependency>\r
             <groupId>javax.inject</groupId>\r
             <artifactId>javax.inject</artifactId>\r
             <version>1</version>\r
index 5a1f65b..3ee2fa5 100644 (file)
@@ -29,7 +29,7 @@ import java.util.concurrent.ConcurrentNavigableMap;
 import java.util.concurrent.ConcurrentSkipListMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -51,15 +51,15 @@ final class AdapterImplementations {
     private static final Logger log = LoggerFactory.getLogger(AdapterImplementations.class);
 
     private final ConcurrentMap<String,ConcurrentNavigableMap<String,ModelClass<?>>> adapterImplementations
-            = new ConcurrentHashMap<String,ConcurrentNavigableMap<String,ModelClass<?>>>();
+            = new ConcurrentHashMap<>();
 
     private final ConcurrentMap<String,ModelClass<?>> modelClasses
-            = new ConcurrentHashMap<String,ModelClass<?>>();
-    
-    private final ConcurrentMap<String, Class<?>> resourceTypeMappingsForResources = new ConcurrentHashMap<String, Class<?>>();
-    private final ConcurrentMap<String, Class<?>> resourceTypeMappingsForRequests = new ConcurrentHashMap<String, Class<?>>();
-    private final ConcurrentMap<Bundle, List<String>> resourceTypeRemovalListsForResources = new ConcurrentHashMap<Bundle, List<String>>();
-    private final ConcurrentMap<Bundle, List<String>> resourceTypeRemovalListsForRequests = new ConcurrentHashMap<Bundle, List<String>>();
+            = new ConcurrentHashMap<>();
+
+    private final ConcurrentMap<String, Class<?>> resourceTypeMappingsForResources = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, Class<?>> resourceTypeMappingsForRequests = new ConcurrentHashMap<>();
+    private final ConcurrentMap<Bundle, List<String>> resourceTypeRemovalListsForResources = new ConcurrentHashMap<>();
+    private final ConcurrentMap<Bundle, List<String>> resourceTypeRemovalListsForRequests = new ConcurrentHashMap<>();
 
     private volatile ImplementationPicker[] sortedImplementationPickers = new ImplementationPicker[0];
     private volatile StaticInjectAnnotationProcessorFactory[] sortedStaticInjectAnnotationProcessorFactories = new StaticInjectAnnotationProcessorFactory[0];
@@ -71,7 +71,7 @@ final class AdapterImplementations {
     public ImplementationPicker[] getImplementationPickers() {
         return this.sortedImplementationPickers;
     }
-    
+
     public StaticInjectAnnotationProcessorFactory[] getStaticInjectAnnotationProcessorFactories() {
         return sortedStaticInjectAnnotationProcessorFactories;
     }
@@ -81,13 +81,13 @@ final class AdapterImplementations {
         this.sortedStaticInjectAnnotationProcessorFactories = factories.toArray(new StaticInjectAnnotationProcessorFactory[factories.size()]);
         updateProcessorFactoriesInModelClasses();
     }
-    
+
     /**
      * Updates all {@link ModelClass} instances with updates list of static inject annotation processor factories.
      */
     private void updateProcessorFactoriesInModelClasses() {
         Iterator<ModelClass<?>> items = modelClasses.values().iterator();
-        updateProcessorFactoriesInModelClasses(items);        
+        updateProcessorFactoriesInModelClasses(items);
         Iterator<ConcurrentNavigableMap<String,ModelClass<?>>> mapItems = adapterImplementations.values().iterator();
         while (mapItems.hasNext()) {
             ConcurrentNavigableMap<String,ModelClass<?>> mapItem = mapItems.next();
@@ -100,7 +100,7 @@ final class AdapterImplementations {
             item.updateProcessorFactories(sortedStaticInjectAnnotationProcessorFactories);
         }
     }
-    
+
     /** Add implementation mapping for the given model class (implementation is the model class itself).
      * Only used for testing purposes. Use {@link #addAll(Class, Class...)} in case you want to register a different implementation.
      * @param modelClasses the model classes to register
@@ -110,7 +110,7 @@ final class AdapterImplementations {
             addAll(modelClass, modelClass);
         }
     }
-    
+
     /**
      * Add implementation mapping for the given adapter types.
      * @param implType Implementation type
@@ -140,7 +140,7 @@ final class AdapterImplementations {
                     ConcurrentNavigableMap<String, ModelClass<?>> implementations = adapterImplementations.get(key);
                     if (implementations == null) {
                         // to have a consistent ordering independent of bundle loading use a ConcurrentSkipListMap that sorts by class name
-                        implementations = new ConcurrentSkipListMap<String, ModelClass<?>>();
+                        implementations = new ConcurrentSkipListMap<>();
                         adapterImplementations.put(key, implementations);
                     }
                     implementations.put(implType.getName(), modelClass);
@@ -149,7 +149,7 @@ final class AdapterImplementations {
         }
         return true;
     }
-    
+
     /**
      * Remove implementation mapping for the given adapter type.
      * @param adapterTypeName Adapter type name
@@ -191,7 +191,7 @@ final class AdapterImplementations {
     @SuppressWarnings("unchecked")
     public <ModelType> ModelClass<ModelType> lookup(Class<ModelType> adapterType, Object adaptable) {
         String key = adapterType.getName();
-        
+
         // lookup in cache for models without adapter classes
         ModelClass<ModelType> modelClass = (ModelClass<ModelType>)modelClasses.get(key);
         if (modelClass!=null) {
@@ -205,7 +205,7 @@ final class AdapterImplementations {
         }
         Collection<ModelClass<?>> implementationsCollection = implementations.values();
         ModelClass<?>[] implementationWrappersArray = implementationsCollection.toArray(new ModelClass<?>[implementationsCollection.size()]);
-        
+
         // prepare array for implementation picker
         Class<?>[] implementationsArray = new Class<?>[implementationsCollection.size()];
         for (int i=0; i<implementationWrappersArray.length; i++) {
@@ -233,7 +233,7 @@ final class AdapterImplementations {
     @SuppressWarnings("unchecked")
     public <ModelType> boolean isModelClass(Class<ModelType> adapterType) {
         String key = adapterType.getName();
-        
+
         // lookup in cache for models without adapter classes
         ModelClass<ModelType> modelClass = (ModelClass<ModelType>)modelClasses.get(key);
         if (modelClass!=null) {
index 698fa11..8e36be4 100644 (file)
@@ -42,7 +42,7 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.PostConstruct;
 
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -124,7 +124,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
 
     private static class DisposalCallbackRegistryImpl implements DisposalCallbackRegistry {
 
-        private List<DisposalCallback> callbacks = new ArrayList<DisposalCallback>();
+        private List<DisposalCallback> callbacks = new ArrayList<>();
 
         @Override
         public void addDisposalCallback(@Nonnull DisposalCallback callback) {
@@ -174,33 +174,33 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     @Property(label = "Cleanup Job Period", description = "Period at which OSGi service references from ThreadLocals will be cleaned up.", longValue = DEFAULT_CLEANUP_JOB_PERIOD)
     private static final String PROP_CLEANUP_JOB_PERIOD = "cleanup.job.period";
 
-    private final @Nonnull ConcurrentMap<String, RankedServices<Injector>> injectors = new ConcurrentHashMap<String, RankedServices<Injector>>();
-    private final @Nonnull RankedServices<Injector> sortedInjectors = new RankedServices<Injector>();
-    private final @Nonnull ConcurrentMap<Class<? extends ViaProviderType>, ViaProvider> viaProviders = new ConcurrentHashMap<Class<? extends ViaProviderType>, ViaProvider>();
+    private final @Nonnull ConcurrentMap<String, RankedServices<Injector>> injectors = new ConcurrentHashMap<>();
+    private final @Nonnull RankedServices<Injector> sortedInjectors = new RankedServices<>();
+    private final @Nonnull ConcurrentMap<Class<? extends ViaProviderType>, ViaProvider> viaProviders = new ConcurrentHashMap<>();
 
     @Reference(name = "injectAnnotationProcessorFactory", referenceInterface = InjectAnnotationProcessorFactory.class,
             cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
-    private final @Nonnull RankedServices<InjectAnnotationProcessorFactory> injectAnnotationProcessorFactories = new RankedServices<InjectAnnotationProcessorFactory>();
+    private final @Nonnull RankedServices<InjectAnnotationProcessorFactory> injectAnnotationProcessorFactories = new RankedServices<>();
 
     @Reference(name = "injectAnnotationProcessorFactory2", referenceInterface = InjectAnnotationProcessorFactory2.class,
             cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
-    private final @Nonnull RankedServices<InjectAnnotationProcessorFactory2> injectAnnotationProcessorFactories2 = new RankedServices<InjectAnnotationProcessorFactory2>();
+    private final @Nonnull RankedServices<InjectAnnotationProcessorFactory2> injectAnnotationProcessorFactories2 = new RankedServices<>();
 
     @Reference(name = "staticInjectAnnotationProcessorFactory", referenceInterface = StaticInjectAnnotationProcessorFactory.class,
             cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
-    private final @Nonnull RankedServices<StaticInjectAnnotationProcessorFactory> staticInjectAnnotationProcessorFactories = new RankedServices<StaticInjectAnnotationProcessorFactory>();
+    private final @Nonnull RankedServices<StaticInjectAnnotationProcessorFactory> staticInjectAnnotationProcessorFactories = new RankedServices<>();
 
     @Reference(name = "implementationPicker", referenceInterface = ImplementationPicker.class,
             cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
-    private final @Nonnull RankedServices<ImplementationPicker> implementationPickers = new RankedServices<ImplementationPicker>();
-    
+    private final @Nonnull RankedServices<ImplementationPicker> implementationPickers = new RankedServices<>();
+
     // bind the service with the highest priority (if a new one comes in this service gets restarted)
     @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policyOption=ReferencePolicyOption.GREEDY)
     private ModelValidation modelValidation = null;
 
     @Reference(name = "modelExporter", cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC,
             referenceInterface = ModelExporter.class)
-    private final @Nonnull RankedServices<ModelExporter> modelExporters = new RankedServices<ModelExporter>();
+    private final @Nonnull RankedServices<ModelExporter> modelExporters = new RankedServices<>();
 
     @Reference
     private BindingsValuesProvidersByContext bindingsValuesProvidersByContext;
@@ -228,6 +228,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     private final int INNER_CACHE_INITIAL_CAPACITY = 4;
 
 
+    @Override
     public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
         Result<AdapterType> result = internalCreateModel(adaptable, type);
         if (!result.wasSuccessful()) {
@@ -287,7 +288,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     }
 
     /**
-     * 
+     *
      * @param requestedType the adapter type
      * @param adaptable the adaptable
      * @return the implementation type to use for the desired model type or null if there is none registered
@@ -315,7 +316,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
         if (threadInvocationCounter.isMaximumReached()) {
             String msg = String.format("Adapting %s to %s failed, too much recursive invocations (>=%s).",
                     adaptable, requestedType, threadInvocationCounter.maxRecursionDepth);
-            return new Result<ModelType>(new ModelClassException(msg));
+            return new Result<>(new ModelClassException(msg));
         }
         threadInvocationCounter.increase();
         try {
@@ -324,7 +325,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
 
             if (!modelClass.hasModelAnnotation()) {
                 String msg = String.format("Provided Adapter class does not have a Model annotation: %s", modelClass.getType());
-                return new Result<ModelType>(new ModelClassException(msg));
+                return new Result<>(new ModelClassException(msg));
             }
             boolean isAdaptable = false;
 
@@ -335,7 +336,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
                 if (adaptableCache != null) {
                     ModelType cachedObject = (ModelType) adaptableCache.get(requestedType);
                     if (cachedObject != null) {
-                        return new Result<ModelType>(cachedObject);
+                        return new Result<>(cachedObject);
                     }
                 }
             }
@@ -348,11 +349,11 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
             }
             if (!isAdaptable) {
                 String msg = String.format("Adaptables (%s) are not acceptable for the model class: %s", StringUtils.join(declaredAdaptable), modelClass.getType());
-                return new Result<ModelType>(new InvalidAdaptableException(msg)); 
+                return new Result<>(new InvalidAdaptableException(msg));
             } else {
                 RuntimeException t = validateModel(adaptable, modelClass.getType(), modelAnnotation);
                 if (t != null) {
-                    return new Result<ModelType>(t);
+                    return new Result<>(t);
                 }
                 if (modelClass.getType().isInterface()) {
                     Result<InvocationHandler> handlerResult = createInvocationHandler(adaptable, modelClass);
@@ -362,15 +363,15 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
                         if (modelAnnotation.cache()) {
                             Map<Class, Object> adaptableCache = adapterCache.get(adaptable);
                             if (adaptableCache == null) {
-                                adaptableCache = new ConcurrentHashMap<Class, Object>(INNER_CACHE_INITIAL_CAPACITY);
+                                adaptableCache = new ConcurrentHashMap<>(INNER_CACHE_INITIAL_CAPACITY);
                                 adapterCache.put(adaptable, adaptableCache);
                             }
                             adaptableCache.put(requestedType, model);
                         }
 
-                        result = new Result<ModelType>(model);
+                        result = new Result<>(model);
                     } else {
-                        return new Result<ModelType>(handlerResult.getThrowable());
+                        return new Result<>(handlerResult.getThrowable());
                     }
                 } else {
                     try {
@@ -379,14 +380,14 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
                         if (result.wasSuccessful() && modelAnnotation.cache()) {
                             Map<Class, Object> adaptableCache = adapterCache.get(adaptable);
                             if (adaptableCache == null) {
-                                adaptableCache = new ConcurrentHashMap<Class, Object>(INNER_CACHE_INITIAL_CAPACITY);
+                                adaptableCache = new ConcurrentHashMap<>(INNER_CACHE_INITIAL_CAPACITY);
                                 adapterCache.put(adaptable, adaptableCache);
                             }
                             adaptableCache.put(requestedType, result.getValue());
                         }
                     } catch (Exception e) {
                         String msg = String.format("Unable to create model %s", modelClass.getType());
-                        return new Result<ModelType>(new ModelClassException(msg, e));
+                        return new Result<>(new ModelClassException(msg, e));
                     }
                 }
             }
@@ -395,7 +396,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
             threadInvocationCounter.decrease();
         }
     }
-    
+
     private <ModelType> RuntimeException validateModel(Object adaptable, Class<ModelType> modelType, Model modelAnnotation) {
         if (modelAnnotation.validation() != ValidationStrategy.DISABLED) {
             if (modelValidation == null) {
@@ -489,7 +490,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
 
         RuntimeException lastInjectionException = null;
         if (injectionAdaptable != null) {
-            
+
             // prepare the set of injectors to process. if a source is given only use injectors with this name.
             final RankedServices<Injector> injectorsToProcess;
             if (StringUtils.isEmpty(source)) {
@@ -501,7 +502,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
                     throw new IllegalArgumentException("No Sling Models Injector registered for source '" + source + "'.");
                 }
             }
-            
+
             // find the right injector
             for (Injector injector : injectorsToProcess) {
                 if (name != null || injector instanceof AcceptsNullName) {
@@ -570,14 +571,14 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
 
     private <ModelType> Result<InvocationHandler> createInvocationHandler(final Object adaptable, final ModelClass<ModelType> modelClass) {
         InjectableMethod[] injectableMethods = modelClass.getInjectableMethods();
-        final Map<Method, Object> methods = new HashMap<Method, Object>();
+        final Map<Method, Object> methods = new HashMap<>();
         SetMethodsCallback callback = new SetMethodsCallback(methods);
         MapBackedInvocationHandler handler = new MapBackedInvocationHandler(methods);
 
         DisposalCallbackRegistryImpl registry = new DisposalCallbackRegistryImpl();
         registerCallbackRegistry(handler, registry);
 
-        final Map<ValuePreparer, Object> preparedValues = new HashMap<ValuePreparer, Object>(VALUE_PREPARERS_COUNT);
+        final Map<ValuePreparer, Object> preparedValues = new HashMap<>(VALUE_PREPARERS_COUNT);
 
         MissingElementsException missingElements = new MissingElementsException("Could not create all mandatory methods for interface of model " + modelClass);
         for (InjectableMethod method : injectableMethods) {
@@ -588,13 +589,13 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
         }
         registry.seal();
         if (!missingElements.isEmpty()) {
-            return new Result<InvocationHandler>(missingElements);
+            return new Result<>(missingElements);
         }
         return new Result<InvocationHandler>(handler);
     }
 
     private void registerCallbackRegistry(Object object, DisposalCallbackRegistryImpl registry) {
-        PhantomReference<Object> reference = new PhantomReference<Object>(object, queue);
+        PhantomReference<Object> reference = new PhantomReference<>(object, queue);
         disposalCallbacks.put(reference, registry);
     }
 
@@ -604,10 +605,10 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
 
         ModelClassConstructor<ModelType> constructorToUse = getBestMatchingConstructor(adaptable, modelClass);
         if (constructorToUse == null) {
-            return new Result<ModelType>(new ModelClassException("Unable to find a useable constructor for model " + modelClass.getType()));
+            return new Result<>(new ModelClassException("Unable to find a useable constructor for model " + modelClass.getType()));
         }
 
-        final Map<ValuePreparer, Object> preparedValues = new HashMap<ValuePreparer, Object>(VALUE_PREPARERS_COUNT);
+        final Map<ValuePreparer, Object> preparedValues = new HashMap<>(VALUE_PREPARERS_COUNT);
 
         final ModelType object;
         if (constructorToUse.getConstructor().getParameterTypes().length == 0) {
@@ -652,16 +653,16 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
 
         registry.seal();
         if (!missingElements.isEmpty()) {
-            return new Result<ModelType>(missingElements);
+            return new Result<>(missingElements);
         }
         try {
             invokePostConstruct(object);
         } catch (InvocationTargetException e) {
-            return new Result<ModelType>(new PostConstructException("Post-construct method has thrown an exception for model " + modelClass.getType(), e.getCause()));
+            return new Result<>(new PostConstructException("Post-construct method has thrown an exception for model " + modelClass.getType(), e.getCause()));
         } catch (IllegalAccessException e) {
             new Result<ModelType>(new ModelClassException("Could not call post-construct method for model " + modelClass.getType(), e));
         }
-        return new Result<ModelType>(object);
+        return new Result<>(object);
     }
 
     /**
@@ -701,7 +702,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
             throws InstantiationException, InvocationTargetException, IllegalAccessException {
         ConstructorParameter[] parameters = constructor.getConstructorParameters();
 
-        List<Object> paramValues = new ArrayList<Object>(Arrays.asList(new Object[parameters.length]));
+        List<Object> paramValues = new ArrayList<>(Arrays.asList(new Object[parameters.length]));
         InjectCallback callback = new SetConstructorParameterCallback(paramValues);
 
         MissingElementsException missingElements = new MissingElementsException("Required constructor parameters were not able to be injected on model " + modelClass.getType());
@@ -712,9 +713,9 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
             }
         }
         if (!missingElements.isEmpty()) {
-            return new Result<ModelType>(missingElements);
+            return new Result<>(missingElements);
         }
-        return new Result<ModelType>(constructor.getConstructor().newInstance(paramValues.toArray(new Object[paramValues.size()])));
+        return new Result<>(constructor.getConstructor().newInstance(paramValues.toArray(new Object[paramValues.size()])));
     }
 
     private Result<Boolean> injectDefaultValue(InjectableElement point, InjectAnnotationProcessor processor,
@@ -723,9 +724,9 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
             if (processor.hasDefault()) {
                 RuntimeException t = callback.inject(point, processor.getDefault());
                 if (t == null) {
-                    return new Result<Boolean>(Boolean.TRUE);
+                    return new Result<>(Boolean.TRUE);
                 } else {
-                    return new Result<Boolean>(t);
+                    return new Result<>(t);
                 }
             }
         }
@@ -734,20 +735,20 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
         if (value != null) {
             RuntimeException t = callback.inject(point, value);
             if (t == null) {
-                return new Result<Boolean>(Boolean.TRUE);
+                return new Result<>(Boolean.TRUE);
             } else {
-                return new Result<Boolean>(t);
+                return new Result<>(t);
             }
         }
         else {
-            return new Result<Boolean>(Boolean.FALSE);
+            return new Result<>(Boolean.FALSE);
         }
     }
 
     /**
      * Injects the default initial value for the given primitive class which
      * cannot be null (e.g. int = 0, boolean = false).
-     * 
+     *
      * @param point Annotated element
      * @param callback Inject callback
      */
@@ -777,7 +778,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
             return new ModelClassException(String.format("Unknown primitive type %s", primitiveType.toString()));
         }
     }
-    
+
     private Object getAdaptable(Object adaptable, InjectableElement point, InjectAnnotationProcessor processor) {
         String viaValue = null;
         Class<? extends ViaProviderType> viaProviderType = null;
@@ -831,7 +832,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
 
     private void invokePostConstruct(Object object) throws InvocationTargetException, IllegalAccessException {
         Class<?> clazz = object.getClass();
-        List<Method> postConstructMethods = new ArrayList<Method>();
+        List<Method> postConstructMethods = new ArrayList<>();
         while (clazz != null) {
             Method[] methods = clazz.getDeclaredMethods();
             for (Method method : methods) {
@@ -899,8 +900,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
                 if (value instanceof Collection &&
                         (type.equals(Collection.class) || type.equals(List.class)) &&
                         parameterizedType.getActualTypeArguments().length == 1) {
-                    
-                    List<Object> result = new ArrayList<Object>();
+
+                    List<Object> result = new ArrayList<>();
                     for (Object valueObject : (Collection<?>) value) {
                         Result<Object> singleValueResult = adapt(valueObject, (Class<?>) parameterizedType.getActualTypeArguments()[0], true);
                         if (singleValueResult.wasSuccessful()) {
@@ -911,15 +912,15 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
                     }
                     adaptedValue = result;
                 } else {
-                    return new Result<Object>(new ModelClassException(String.format("%s is neither a parameterized Collection or List",
+                    return new Result<>(new ModelClassException(String.format("%s is neither a parameterized Collection or List",
                         type)));
                 }
             } else {
                 return adapt(value, type, false);
             }
-            return new Result<Object>(adaptedValue);
+            return new Result<>(adaptedValue);
         } else {
-            return new Result<Object>(value);
+            return new Result<>(value);
         }
     }
 
@@ -938,20 +939,20 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
             if (result.wasSuccessful()) {
                 adaptedValue = result.getValue();
             } else {
-                return new Result<Object>(new ModelClassException(
+                return new Result<>(new ModelClassException(
                     String.format("Could not create model from %s: %s%s", value.getClass(), result.getThrowable().getMessage(), messageSuffix),
                     result.getThrowable()));
             }
         } else if (value instanceof Adaptable) {
             adaptedValue = ((Adaptable) value).adaptTo(type);
             if (adaptedValue == null) {
-                return new Result<Object>(new ModelClassException(String.format("Could not adapt from %s to %s%s", value.getClass(), type, messageSuffix)));
+                return new Result<>(new ModelClassException(String.format("Could not adapt from %s to %s%s", value.getClass(), type, messageSuffix)));
             }
         }
         if (adaptedValue != null) {
-            return new Result<Object>(adaptedValue);
+            return new Result<>(adaptedValue);
         } else {
-            return new Result<Object>(new ModelClassException(
+            return new Result<>(new ModelClassException(
                     String.format("Could not adapt from %s to %s%s, because this class is not adaptable!", value.getClass(), type, messageSuffix)));
         }
     }
@@ -1017,9 +1018,9 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
         this.adapterCache = Collections.synchronizedMap(new WeakHashMap<Object, Map<Class, Object>>());
 
         BundleContext bundleContext = ctx.getBundleContext();
-        this.queue = new ReferenceQueue<Object>();
-        this.disposalCallbacks = new ConcurrentHashMap<java.lang.ref.Reference<Object>, DisposalCallbackRegistryImpl>();
-        Hashtable<Object, Object> properties = new Hashtable<Object, Object>();
+        this.queue = new ReferenceQueue<>();
+        this.disposalCallbacks = new ConcurrentHashMap<>();
+        Hashtable<Object, Object> properties = new Hashtable<>();
         properties.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
         properties.put(Constants.SERVICE_DESCRIPTION, "Sling Models OSGi Service Disposal Job");
         properties.put("scheduler.name", "Sling Models OSGi Service Disposal Job");
@@ -1031,7 +1032,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
         this.scriptEngineFactory = new SlingModelsScriptEngineFactory(bundleContext.getBundle());
         this.listener = new ModelPackageBundleListener(ctx.getBundleContext(), this, this.adapterImplementations, bindingsValuesProvidersByContext, scriptEngineFactory);
 
-        Hashtable<Object, Object> printerProps = new Hashtable<Object, Object>();
+        Hashtable<Object, Object> printerProps = new Hashtable<>();
         printerProps.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
         printerProps.put(Constants.SERVICE_DESCRIPTION, "Sling Models Configuration Printer");
         printerProps.put("felix.webconsole.label", "slingmodels");
@@ -1059,7 +1060,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     }
 
     protected void bindInjector(final Injector injector, final Map<String, Object> props) {
-        RankedServices<Injector> newRankedServices = new RankedServices<Injector>();
+        RankedServices<Injector> newRankedServices = new RankedServices<>();
         RankedServices<Injector> injectorsPerInjectorName = injectors.putIfAbsent(injector.getName(), newRankedServices);
         if (injectorsPerInjectorName == null) {
             injectorsPerInjectorName = newRankedServices;
index f7f0b42..28dcc16 100644 (file)
@@ -26,8 +26,10 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
+import javax.servlet.Servlet;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.adapter.AdapterFactory;
 import org.apache.sling.api.resource.Resource;
@@ -47,9 +49,6 @@ import org.osgi.util.tracker.BundleTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.script.ScriptEngineFactory;
-import javax.servlet.Servlet;
-
 public class ModelPackageBundleListener implements BundleTrackerCustomizer {
 
     static final String PACKAGE_HEADER = "Sling-Model-Packages";
@@ -57,7 +56,7 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
 
     static final String PROP_EXPORTER_SERVLET_CLASS = "sling.models.exporter.servlet.class";
     static final String PROP_EXPORTER_SERVLET_NAME = "sling.models.exporter.servlet.name";
-    
+
     /**
      * Service registration property for the adapter condition.
      */
@@ -80,13 +79,13 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
     private final BundleTracker bundleTracker;
 
     private final ModelAdapterFactory factory;
-    
+
     private final AdapterImplementations adapterImplementations;
 
     private final BindingsValuesProvidersByContext bindingsValuesProvidersByContext;
 
     private final SlingModelsScriptEngineFactory scriptEngineFactory;
-    
+
     public ModelPackageBundleListener(BundleContext bundleContext,
                                       ModelAdapterFactory factory,
                                       AdapterImplementations adapterImplementations,
@@ -100,10 +99,10 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
         this.bundleTracker = new BundleTracker(bundleContext, Bundle.ACTIVE, this);
         this.bundleTracker.open();
     }
-    
+
     @Override
     public Object addingBundle(Bundle bundle, BundleEvent event) {
-        List<ServiceRegistration> regs = new ArrayList<ServiceRegistration>();
+        List<ServiceRegistration> regs = new ArrayList<>();
 
         Dictionary<?, ?> headers = bundle.getHeaders();
         String packageList = PropertiesUtil.toString(headers.get(PACKAGE_HEADER), null);
@@ -151,7 +150,7 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
                 if (adapterTypes.length == 0) {
                     adapterTypes = new Class<?>[] { implType };
                 } else if (!ArrayUtils.contains(adapterTypes, implType)) {
-                    adapterTypes = (Class<?>[]) ArrayUtils.add(adapterTypes, implType);
+                    adapterTypes = ArrayUtils.add(adapterTypes, implType);
                 }
                 // register adapter only if given adapters are valid
                 if (validateAdapterClasses(implType, adapterTypes)) {
@@ -234,7 +233,7 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
         }
         return arr;
     }
-    
+
     /**
      * Validate list of adapter classes. Make sure all given are either the annotated class itself,
      * or an interface or superclass of it.
@@ -253,7 +252,7 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
         }
         return true;
     }
-    
+
     /**
      * Registers an adapter factory for a annotated sling models class.
      * @param adapterTypes Adapter (either the class itself, or interface or superclass of it)
@@ -263,7 +262,7 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
      * @return Service registration
      */
     private ServiceRegistration registerAdapterFactory(Class<?>[] adapterTypes, Class<?>[] adaptableTypes, Class<?> implType, String condition) {
-        Dictionary<String, Object> registrationProps = new Hashtable<String, Object>();
+        Dictionary<String, Object> registrationProps = new Hashtable<>();
         registrationProps.put(AdapterFactory.ADAPTER_CLASSES, toStringArray(adapterTypes));
         registrationProps.put(AdapterFactory.ADAPTABLE_CLASSES, toStringArray(adaptableTypes));
         registrationProps.put(PROP_IMPLEMENTATION_CLASS, implType.getName());
@@ -282,7 +281,7 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
             Map<String, String> baseOptions = getOptions(exporterAnnotation);
             ExportServlet servlet = new ExportServlet(bundle.getBundleContext(), factory, bindingsValuesProvidersByContext,
                     scriptEngineFactory, annotatedClass, exporterAnnotation.selector(), exporterAnnotation.name(), accessor, baseOptions);
-            Dictionary<String, Object> registrationProps = new Hashtable<String, Object>();
+            Dictionary<String, Object> registrationProps = new Hashtable<>();
             registrationProps.put("sling.servlet.resourceTypes", resourceType);
             registrationProps.put("sling.servlet.selectors", exporterAnnotation.selector());
             registrationProps.put("sling.servlet.extensions", exporterAnnotation.extensions());
@@ -301,7 +300,7 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
         if (options.length == 0) {
             return Collections.emptyMap();
         } else {
-            Map<String, String> map = new HashMap<String, String>(options.length);
+            Map<String, String> map = new HashMap<>(options.length);
             for (ExporterOption option : options) {
                 map.put(option.name(), option.value());
             }
index c3ca90d..da985a4 100644 (file)
@@ -28,7 +28,7 @@ import java.util.List;
 
 import javax.inject.Inject;
 
-import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.lang3.ClassUtils;
 import org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
 
 /**
@@ -41,7 +41,7 @@ public final class ReflectionUtil {
     }
 
     public static List<Field> collectInjectableFields(Class<?> type) {
-        List<Field> result = new ArrayList<Field>();
+        List<Field> result = new ArrayList<>();
         while (type != null) {
             Field[] fields = type.getDeclaredFields();
             addAnnotated(fields, result);
@@ -51,7 +51,7 @@ public final class ReflectionUtil {
     }
 
     public static List<Method> collectInjectableMethods(Class<?> type) {
-        List<Method> result = new ArrayList<Method>();
+        List<Method> result = new ArrayList<>();
         while (type != null) {
             Method[] methods = type.getDeclaredMethods();
             addAnnotated(methods, result);
@@ -87,7 +87,7 @@ public final class ReflectionUtil {
     /**
      * Get an annotation from either the element itself or on any of the
      * element's annotations (meta-annotations).
-     * 
+     *
      * @param element the element
      * @param annotationClass the annotation class
      * @return the found annotation or null
index 7170766..50e5eb7 100644 (file)
@@ -22,7 +22,7 @@ import java.lang.reflect.Type;
 import javax.annotation.Nonnull;
 import javax.servlet.ServletRequest;
 
-import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
@@ -47,6 +47,7 @@ public class BindingsInjector implements Injector, StaticInjectAnnotationProcess
         return "script-bindings";
     }
 
+    @Override
     public Object getValue(@Nonnull Object adaptable, String name, @Nonnull Type type, @Nonnull AnnotatedElement element,
             @Nonnull DisposalCallbackRegistry callbackRegistry) {
         if (adaptable == ObjectUtils.NULL) {
@@ -98,7 +99,7 @@ public class BindingsInjector implements Injector, StaticInjectAnnotationProcess
         public InjectionStrategy getInjectionStrategy() {
             return annotation.injectionStrategy();
         }
-        
+
         @Override
         @SuppressWarnings("deprecation")
         public Boolean isOptional() {
index a4c73c6..1bdb589 100644 (file)
@@ -25,7 +25,7 @@ import java.util.List;
 
 import javax.annotation.Nonnull;
 
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
@@ -73,7 +73,7 @@ public class ChildResourceInjector extends AbstractInjector implements Injector,
     }
 
     private Object getResultList(Resource resource, Type declaredType) {
-       List<Resource> result = new ArrayList<Resource>();
+       List<Resource> result = new ArrayList<>();
        Class<?> type = getActualType((ParameterizedType) declaredType);
        if (type != null && resource != null) {
            Iterator<Resource> children = resource.listChildren();
index 5723f97..d3bddd3 100644 (file)
@@ -28,7 +28,7 @@ import java.util.List;
 
 import javax.annotation.Nonnull;
 
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
@@ -70,6 +70,7 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
         this.bundleContext = ctx.getBundleContext();
     }
 
+    @Override
     public Object getValue(@Nonnull Object adaptable, String name, @Nonnull Type type, @Nonnull AnnotatedElement element,
             @Nonnull DisposalCallbackRegistry callbackRegistry) {
         OSGiService annotation = element.getAnnotation(OSGiService.class);
@@ -123,7 +124,7 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
                 // make highest service ranking being returned first
                 Collections.reverse(references);
                 callbackRegistry.addDisposalCallback(new Callback(refs, bundleContext));
-                List<Object> services = new ArrayList<Object>();
+                List<Object> services = new ArrayList<>();
                 for (ServiceReference ref : references) {
                     Object service = bundleContext.getService(ref);
                     if (service != null) {
@@ -218,7 +219,7 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
         public InjectionStrategy getInjectionStrategy() {
             return annotation.injectionStrategy();
         }
-        
+
         @Override
         @SuppressWarnings("deprecation")
         public Boolean isOptional() {
index b8f4eb3..819bc1f 100644 (file)
@@ -25,8 +25,8 @@ import java.util.List;
 
 import javax.annotation.Nonnull;
 
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
@@ -108,7 +108,7 @@ public class ResourcePathInjector extends AbstractInjector implements Injector,
     }
 
     private List<Resource> getResources(ResourceResolver resolver, String[] paths, String fieldName) {
-        List<Resource> resources = new ArrayList<Resource>();
+        List<Resource> resources = new ArrayList<>();
         for (String path : paths) {
             Resource resource = resolver.getResource(path);
             if (resource != null) {
index ed9053f..ea835c0 100644 (file)
@@ -26,9 +26,9 @@ import java.util.List;
 
 import javax.annotation.Nonnull;
 
-import org.apache.commons.lang.ClassUtils;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.ClassUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
@@ -59,6 +59,7 @@ public class ValueMapInjector extends AbstractInjector implements Injector, Inje
         return "valuemap";
     }
 
+    @Override
     public Object getValue(@Nonnull Object adaptable, String name, @Nonnull Type type, @Nonnull AnnotatedElement element,
             @Nonnull DisposalCallbackRegistry callbackRegistry) {
         if (adaptable == ObjectUtils.NULL) {
@@ -187,7 +188,7 @@ public class ValueMapInjector extends AbstractInjector implements Injector, Inje
                 return null;
             }
         }
-        
+
         @Override
         public Boolean isOptional() {
             return annotation.optional();
index df10e84..26a6736 100644 (file)
@@ -23,8 +23,14 @@ import java.lang.reflect.Type;
 
 import javax.inject.Named;
 
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.sling.models.annotations.*;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.sling.models.annotations.Default;
+import org.apache.sling.models.annotations.DefaultInjectionStrategy;
+import org.apache.sling.models.annotations.Optional;
+import org.apache.sling.models.annotations.Required;
+import org.apache.sling.models.annotations.Source;
+import org.apache.sling.models.annotations.Via;
+import org.apache.sling.models.annotations.ViaProviderType;
 import org.apache.sling.models.annotations.via.BeanProperty;
 import org.apache.sling.models.impl.ModelAdapterFactory;
 import org.apache.sling.models.impl.ReflectionUtil;
index dbd78c8..6b6949b 100644 (file)
@@ -17,7 +17,7 @@
 package org.apache.sling.models.impl.via;
 
 import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.models.annotations.ViaProviderType;
index 653e8f4..b35b9e0 100644 (file)
@@ -16,7 +16,7 @@
  */
 package org.apache.sling.models.impl.via;
 
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.resource.Resource;
index fec2bc4..130fca0 100644 (file)
  */
 package org.apache.sling.models.impl.via;
 
-import org.apache.commons.lang.StringUtils;
+import javax.annotation.Nonnull;
+
+import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.models.annotations.ViaProviderType;
 import org.apache.sling.models.annotations.via.ForcedResourceType;
 
-import javax.annotation.Nonnull;
-
 @Component
 @Service
 public class ForcedResourceTypeViaProvider extends AbstractResourceTypeViaProvider {
index b80b684..1e35c72 100644 (file)
  */
 package org.apache.sling.models.impl;
 
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.lang.reflect.Field;
 import java.util.Arrays;
@@ -26,7 +33,7 @@ import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 
-import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.wrappers.ValueMapDecorator;
@@ -75,7 +82,7 @@ public class ResourceModelClassesTest {
         ValueMapInjector valueMapInjector = new ValueMapInjector();
         factory.bindInjector(valueMapInjector, new ServicePropertiesMap(2, 2));
         factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(1, 1));
-        
+
         factory.bindInjectAnnotationProcessorFactory(valueMapInjector,
                 Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 2L));
         factory.adapterImplementations.addClassesAsAdapterAndImplementation(SimplePropertyModel.class, ArrayWrappersModel.class, ResourceModelWithRequiredField.class, ChildValueMapModel.class, ArrayPrimitivesModel.class, ChildResourceModel.class, ResourceModelWithRequiredFieldOptionalStrategy.class, ParentModel.class, ChildModel.class, ListModel.class);
@@ -83,7 +90,7 @@ public class ResourceModelClassesTest {
 
     @Test
     public void testSimplePropertyModel() {
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         map.put("first", "first-value");
         map.put("third", "third-value");
         map.put("intProperty", new Integer(3));
@@ -111,7 +118,7 @@ public class ResourceModelClassesTest {
 
     @Test
     public void testArrayPrimitivesModel() {
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         map.put("intArray", new int[] { 1, 2, 9, 8 });
         map.put("secondIntArray", new Integer[] {1, 2, 9, 8});
 
@@ -133,7 +140,7 @@ public class ResourceModelClassesTest {
 
     @Test
     public void testArrayWrappersModel() {
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         map.put("intArray", new Integer[] {1, 2, 9, 8});
         map.put("secondIntArray", new int[] {1, 2, 9, 8});
 
@@ -155,7 +162,7 @@ public class ResourceModelClassesTest {
 
     @Test
     public void testListModel() {
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         map.put("intList", new Integer[] {1, 2, 9, 8});
         map.put("stringList", new String[] {"hello", "world"});
 
@@ -175,7 +182,7 @@ public class ResourceModelClassesTest {
 
     @Test
     public void testRequiredPropertyModel() {
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         map.put("first", "first-value");
         map.put("third", "third-value");
         ValueMap vm = spy(new ValueMapDecorator(map));
@@ -191,7 +198,7 @@ public class ResourceModelClassesTest {
 
     @Test
     public void testRequiredPropertyModelWithException() {
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         map.put("first", "first-value");
         map.put("third", "third-value");
         ValueMap vm = spy(new ValueMapDecorator(map));
@@ -213,7 +220,7 @@ public class ResourceModelClassesTest {
 
     @Test
     public void testRequiredPropertyMissingModelOptionalStrategy() {
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         map.put("first", "first-value");
         ValueMap vm = spy(new ValueMapDecorator(map));
 
@@ -229,7 +236,7 @@ public class ResourceModelClassesTest {
 
     @Test
     public void testRequiredPropertyModelOptionalStrategy() {
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         map.put("required1", "required value");
         map.put("required2", "required value");
         map.put("required3", "required value");
@@ -242,7 +249,7 @@ public class ResourceModelClassesTest {
         assertNotNull(model);
         assertEquals("required value", model.getRequired1());
         assertEquals("required value", model.getRequired2());
-        
+
         verify(vm).get("optional1", String.class);
         verify(vm).get("required1", String.class);
     }
index 8478a6d..879398d 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.Hashtable;
 
-import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.wrappers.ValueMapDecorator;
index acdbd86..9170c81 100644 (file)
  */
 package org.apache.sling.models.impl;
 
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -25,7 +32,7 @@ import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 
-import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.wrappers.ValueMapDecorator;
@@ -67,12 +74,12 @@ public class ResourceModelInterfacesTest {
         factory.activate(componentCtx);
         factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(2, 2));
         factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(1, 1));
-        factory.adapterImplementations.addClassesAsAdapterAndImplementation(SimplePropertyModel.class, ResourceModelWithRequiredField.class, ChildResourceModel.class, ChildValueMapModel.class, ParentModel.class, ChildModel.class); 
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(SimplePropertyModel.class, ResourceModelWithRequiredField.class, ChildResourceModel.class, ChildValueMapModel.class, ParentModel.class, ChildModel.class);
     }
 
     @Test
     public void testSimplePropertyModel() {
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         map.put("first", "first-value");
         map.put("third", "third-value");
         map.put("fourth", true);
@@ -93,7 +100,7 @@ public class ResourceModelInterfacesTest {
 
     @Test
     public void testRequiredPropertyModel() {
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         map.put("first", "first-value");
         map.put("third", "third-value");
         ValueMap vm = spy(new ValueMapDecorator(map));
index 24d821d..0e01e81 100644 (file)
  */
 package org.apache.sling.models.impl;
 
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
 
 import java.util.Collections;
 import java.util.Hashtable;
 
-import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;