You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2023/12/08 15:32:49 UTC
(sling-org-apache-sling-models-impl) 01/01: SLING-12186 PoC for spotless-maven-plugin
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch feature/SLING-12186-poc-for-spotless
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git
commit df9c0550f0743be73a476917f4731ceff069be99
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Fri Dec 8 16:32:42 2023 +0100
SLING-12186 PoC for spotless-maven-plugin
---
pom.xml | 162 +++++---
.../sling/models/impl/AdapterImplementations.java | 162 ++++----
.../apache/sling/models/impl/ExportServlet.java | 71 ++--
.../models/impl/FirstImplementationPicker.java | 8 +-
.../models/impl/MapBackedInvocationHandler.java | 3 +-
.../sling/models/impl/ModelAdapterFactory.java | 426 +++++++++++++--------
.../impl/ModelAdapterFactoryConfiguration.java | 33 +-
.../models/impl/ModelConfigurationPrinter.java | 77 ++--
.../models/impl/ModelPackageBundleListener.java | 107 ++++--
.../apache/sling/models/impl/ReflectionUtil.java | 6 +-
.../impl/ResourceOverridingRequestWrapper.java | 54 +--
.../impl/ResourceTypeBasedResourcePicker.java | 32 +-
.../java/org/apache/sling/models/impl/Result.java | 16 +-
.../impl/SlingModelsScriptEngineFactory.java | 51 +--
.../sling/models/impl/ThreadInvocationCounter.java | 2 +-
.../models/impl/injectors/AbstractInjector.java | 6 +-
.../models/impl/injectors/BindingsInjector.java | 41 +-
.../impl/injectors/ChildResourceInjector.java | 72 ++--
.../models/impl/injectors/OSGiServiceInjector.java | 97 +++--
.../impl/injectors/RequestAttributeInjector.java | 44 ++-
.../impl/injectors/ResourcePathInjector.java | 35 +-
.../sling/models/impl/injectors/SelfInjector.java | 47 ++-
.../models/impl/injectors/SlingObjectInjector.java | 47 ++-
.../models/impl/injectors/ValueMapInjector.java | 50 ++-
.../impl/model/AbstractInjectableElement.java | 80 ++--
.../models/impl/model/ConstructorParameter.java | 23 +-
.../sling/models/impl/model/InjectableElement.java | 1 -
.../sling/models/impl/model/InjectableField.java | 16 +-
.../sling/models/impl/model/InjectableMethod.java | 15 +-
.../apache/sling/models/impl/model/ModelClass.java | 37 +-
.../models/impl/model/ModelClassConstructor.java | 33 +-
.../impl/model/OptionalTypedInjectableElement.java | 29 +-
.../impl/model/ParameterCountInjectComparator.java | 18 +-
.../impl/via/AbstractResourceTypeViaProvider.java | 39 +-
.../models/impl/via/BeanPropertyViaProvider.java | 28 +-
.../models/impl/via/ChildResourceViaProvider.java | 32 +-
.../impl/via/ForcedResourceTypeViaProvider.java | 28 +-
.../impl/via/OriginalResourceTypeViaProvider.java | 26 +-
.../impl/via/ResourceSuperTypeViaProvider.java | 28 +-
.../via/ResourceTypeForcingRequestWrapper.java | 26 +-
.../via/ResourceTypeForcingResourceWrapper.java | 26 +-
.../sling/models/impl/AdapterFactoryTest.java | 61 +--
.../models/impl/AdapterImplementationsTest.java | 65 ++--
.../sling/models/impl/AnnotationConflictsTest.java | 34 +-
.../org/apache/sling/models/impl/CachingTest.java | 108 +++---
.../apache/sling/models/impl/ConstructorTest.java | 49 +--
.../models/impl/ConstructorVisibilityTest.java | 37 +-
.../sling/models/impl/CustomInjectorTest.java | 41 +-
.../models/impl/DefaultInterfaceMethodTest.java | 34 +-
.../org/apache/sling/models/impl/DefaultTest.java | 95 +++--
.../sling/models/impl/ExtraDefaultTests.java | 53 +--
.../sling/models/impl/ImplementsExtendsTest.java | 89 +++--
.../impl/InjectorSpecificAnnotationTest.java | 128 ++++---
.../models/impl/InterfaceInheritanceTest.java | 39 +-
.../sling/models/impl/InvalidAdaptationsTest.java | 49 ++-
.../impl/ModelPackageBundleListenerTest.java | 61 +--
.../sling/models/impl/MultipleInjectorTest.java | 44 +--
.../sling/models/impl/OSGiInjectionTest.java | 114 +++---
.../sling/models/impl/OptionalObjectsTest.java | 72 ++--
.../sling/models/impl/OptionalPrimitivesTest.java | 64 ++--
.../ParameterizedTypeFromRequestAttributeTest.java | 12 +-
.../sling/models/impl/PostConstructTest.java | 57 +--
.../sling/models/impl/RequestDisposalTest.java | 81 ++--
.../sling/models/impl/RequestInjectionTest.java | 47 +--
.../sling/models/impl/RequestWrapperTest.java | 59 +--
.../models/impl/ResourceModelClassesTest.java | 104 ++---
.../models/impl/ResourceModelConstructorTest.java | 48 ++-
.../models/impl/ResourceModelInterfacesTest.java | 70 ++--
.../models/impl/ResourcePathInjectionTest.java | 61 +--
.../sling/models/impl/SelfDependencyTest.java | 50 +--
.../sling/models/impl/ServicePropertiesMap.java | 29 +-
.../impl/StaticInjectionAPFLoadOrderTest.java | 48 ++-
.../java/org/apache/sling/models/impl/ViaTest.java | 39 +-
.../implpicker/FirstImplementationPickerTest.java | 11 +-
.../models/impl/injector/CustomAnnotation.java | 38 +-
.../impl/injector/CustomAnnotationInjector.java | 33 +-
.../sling/models/impl/injector/SimpleInjector.java | 33 +-
.../impl/injectors/BindingsInjectorTest.java | 12 +-
.../injectors/RequestAttributeInjectorTest.java | 16 +-
.../injectors/ResourceResolverInjectorTest.java | 10 +-
.../models/impl/injectors/SelfInjectorTest.java | 102 +++--
.../injectors/SlingObjectInjectorRequestTest.java | 32 +-
.../SlingObjectInjectorResourceResolverTest.java | 29 +-
.../injectors/SlingObjectInjectorResourceTest.java | 25 +-
.../impl/injectors/ValueMapInjectorTest.java | 9 +-
.../impl/via/ChildResourceViaProviderTest.java | 31 +-
.../via/OriginalResourceTypeViaProviderTest.java | 26 +-
.../models/testmodels/classes/ArrayOSGiModel.java | 31 +-
.../testmodels/classes/ArrayPrimitivesModel.java | 32 +-
.../testmodels/classes/ArrayWrappersModel.java | 32 +-
.../models/testmodels/classes/BindingsModel.java | 33 +-
.../models/testmodels/classes/CachedModel.java | 30 +-
.../classes/CachedModelWithAdapterTypes12.java | 38 +-
.../classes/CachedModelWithAdapterTypes23.java | 38 +-
.../classes/CachedModelWithSelfReference.java | 28 +-
.../models/testmodels/classes/ChildModel.java | 28 +-
.../testmodels/classes/ChildResourceModel.java | 37 +-
.../testmodels/classes/ChildResourceViaModel.java | 31 +-
.../testmodels/classes/ChildValueMapModel.java | 29 +-
.../classes/CollectionDefaultsModel.java | 35 +-
.../testmodels/classes/CollectionOSGiModel.java | 35 +-
.../classes/ConstructorWithExceptionModel.java | 28 +-
.../testmodels/classes/DefaultPrimitivesModel.java | 31 +-
.../testmodels/classes/DefaultStringModel.java | 28 +-
.../testmodels/classes/DefaultWrappersModel.java | 31 +-
.../classes/DirectCyclicSelfDependencyModel.java | 3 +-
.../classes/FailingPostConstructModel.java | 3 +-
.../classes/FalsePostConstructModel.java | 7 +-
.../IndirectCyclicSelfDependencyModelA.java | 3 +-
.../IndirectCyclicSelfDependencyModelB.java | 3 +-
.../classes/InjectorSpecificAnnotationModel.java | 27 +-
.../classes/InvalidConstructorModel.java | 26 +-
.../classes/InvalidModelWithMissingAnnotation.java | 33 +-
.../testmodels/classes/ListDefaultsModel.java | 43 ++-
.../sling/models/testmodels/classes/ListModel.java | 33 +-
.../models/testmodels/classes/ListOSGiModel.java | 35 +-
.../testmodels/classes/OptionalArrayOSGiModel.java | 34 +-
.../testmodels/classes/OptionalListOSGiModel.java | 38 +-
.../testmodels/classes/OptionalObjectsModel.java | 29 +-
.../classes/OptionalPrimitivesModel.java | 75 ++--
.../models/testmodels/classes/ParentModel.java | 36 +-
.../testmodels/classes/RequestOSGiModel.java | 31 +-
.../classes/ResourceModelWithRequiredField.java | 27 +-
...urceModelWithRequiredFieldOptionalStrategy.java | 49 +--
.../classes/ResourcePathAllOptionalModel.java | 9 +-
.../testmodels/classes/ResourcePathModel.java | 34 +-
.../classes/ResourcePathModelWrapping.java | 3 +-
.../classes/ResourcePathPartialModel.java | 22 +-
.../testmodels/classes/SelfDependencyModelA.java | 3 +-
.../testmodels/classes/SelfDependencyModelB.java | 3 +-
.../models/testmodels/classes/SetOSGiModel.java | 35 +-
.../SimpleModelWithInvalidSecondAnnotation.java | 30 +-
.../models/testmodels/classes/SimpleOSGiModel.java | 31 +-
.../testmodels/classes/SimplePropertyModel.java | 27 +-
.../sling/models/testmodels/classes/SubClass.java | 30 +-
.../classes/SubClassOverriddenPostConstruct.java | 32 +-
.../models/testmodels/classes/SuperClass.java | 27 +-
.../classes/SuperclassConstructorModel.java | 29 +-
.../testmodels/classes/TruePostConstructModel.java | 7 +-
.../models/testmodels/classes/UncachedModel.java | 27 +-
.../sling/models/testmodels/classes/ViaModel.java | 27 +-
.../classes/WithOneConstructorModel.java | 26 +-
.../classes/WithThreeConstructorsModel.java | 33 +-
.../classes/WithTwoConstructorsModel.java | 29 +-
.../testmodels/classes/annotations/Hidden.java | 30 +-
.../classes/annotations/OtherAnnotation.java | 26 +-
.../constructorinjection/BindingsModel.java | 29 +-
.../DefaultPrimitivesModel.java | 35 +-
.../constructorinjection/DefaultStringModel.java | 31 +-
.../constructorinjection/DefaultWrappersModel.java | 34 +-
.../InjectorSpecificAnnotationModel.java | 32 +-
.../constructorinjection/ListOSGiModel.java | 33 +-
.../classes/constructorinjection/NoNameModel.java | 3 +-
.../OptionalPrimitivesModel.java | 29 +-
.../classes/constructorinjection/ParentModel.java | 8 +-
.../constructorinjection/SimpleOSGiModel.java | 29 +-
.../ViaRequestSuffixModel.java | 32 +-
.../WithThreeConstructorsOneInjectModel.java | 31 +-
.../PackagePrivateConstructorModel.java | 30 +-
.../PrivateConstructorModel.java | 30 +-
.../ProtectedConstructorModel.java | 30 +-
.../implextend/EvenSimplerPropertyModel.java | 27 +-
.../implextend/ExtendsClassPropertyModel.java | 35 +-
.../ImplementsInterfacePropertyModel.java | 41 +-
.../ImplementsInterfacePropertyModel2.java | 35 +-
.../InvalidImplementsInterfacePropertyModel.java | 35 +-
.../implextend/InvalidSampleServiceInterface.java | 3 +-
.../classes/implextend/SampleServiceInterface.java | 3 +-
.../classes/implextend/SimplePropertyModel.java | 35 +-
.../models/testmodels/interfaces/AdapterType1.java | 29 +-
.../models/testmodels/interfaces/AdapterType2.java | 29 +-
.../models/testmodels/interfaces/AdapterType3.java | 29 +-
.../models/testmodels/interfaces/CachedModel.java | 30 +-
.../models/testmodels/interfaces/ChildModel.java | 26 +-
.../testmodels/interfaces/ChildResourceModel.java | 27 +-
.../testmodels/interfaces/ChildValueMapModel.java | 27 +-
.../interfaces/ModelWithDefaultMethods.java | 36 +-
.../interfaces/OptionalPrimitivesModel.java | 75 ++--
.../models/testmodels/interfaces/ParentModel.java | 38 +-
.../interfaces/PropertyModelWithDefaults.java | 35 +-
.../interfaces/ResourceModelWithRequiredField.java | 27 +-
.../testmodels/interfaces/ServiceInterface.java | 30 +-
.../testmodels/interfaces/SimplePropertyModel.java | 29 +-
.../testmodels/interfaces/SubClassModel.java | 30 +-
.../testmodels/interfaces/SuperClassModel.java | 30 +-
.../testmodels/interfaces/UncachedModel.java | 30 +-
.../models/testutil/ModelAdapterFactoryUtil.java | 8 +-
187 files changed, 4047 insertions(+), 3261 deletions(-)
diff --git a/pom.xml b/pom.xml
index c9e6be9..fdfcf4f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -33,68 +33,13 @@
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git</developerConnection>
- <url>https://github.com/apache/sling-org-apache-sling-models-impl.git</url>
<tag>HEAD</tag>
+ <url>https://github.com/apache/sling-org-apache-sling-models-impl.git</url>
</scm>
<properties>
<sling.java.version>8</sling.java.version>
<project.build.outputTimestamp>2023-05-30T08:54:10Z</project.build.outputTimestamp>
</properties>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <createSourcesJar>true</createSourcesJar>
- <shadeSourcesContent>true</shadeSourcesContent>
- <artifactSet>
- <includes>
- <include>org.apache.sling:org.apache.sling.scripting.core</include>
- </includes>
- </artifactSet>
- <relocations>
- <relocation>
- <pattern>org.apache.sling.scripting.core.impl.helper</pattern>
- <shadedPattern>slingmodelsimpl.org.apache.sling.scripting.core.impl.helper</shadedPattern>
- </relocation>
- </relocations>
- <filters>
- <filter>
- <artifact>org.apache.sling:org.apache.sling.scripting.core</artifact>
- <includes>
- <include>org/apache/sling/scripting/core/impl/helper/ProtectedBindings*</include>
- </includes>
- </filter>
- </filters>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>dependency-reduced-pom.xml</exclude>
- </excludes>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <configuration>
- <attach>false</attach>
- </configuration>
- </plugin>
- </plugins>
- </build>
<dependencies>
<dependency>
@@ -260,4 +205,107 @@
<scope>provided</scope>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <createSourcesJar>true</createSourcesJar>
+ <shadeSourcesContent>true</shadeSourcesContent>
+ <artifactSet>
+ <includes>
+ <include>org.apache.sling:org.apache.sling.scripting.core</include>
+ </includes>
+ </artifactSet>
+ <relocations>
+ <relocation>
+ <pattern>org.apache.sling.scripting.core.impl.helper</pattern>
+ <shadedPattern>slingmodelsimpl.org.apache.sling.scripting.core.impl.helper</shadedPattern>
+ </relocation>
+ </relocations>
+ <filters>
+ <filter>
+ <artifact>org.apache.sling:org.apache.sling.scripting.core</artifact>
+ <includes>
+ <include>org/apache/sling/scripting/core/impl/helper/ProtectedBindings*</include>
+ </includes>
+ </filter>
+ </filters>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>dependency-reduced-pom.xml</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <configuration>
+ <attach>false</attach>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.diffplug.spotless</groupId>
+ <artifactId>spotless-maven-plugin</artifactId>
+ <version>2.41.1</version>
+ <configuration>
+ <java>
+ <!-- orders of used formatters are important MPOM-376 -->
+ <!-- eg. palantir override importOrder, so should be first -->
+ <palantirJavaFormat>
+ <version>2.39.0</version>
+ </palantirJavaFormat>
+ <removeUnusedImports />
+ <importOrder>
+ <file>config/maven-eclipse-importorder.txt</file>
+ </importOrder>
+ <licenseHeader>
+ <file>config/maven-header-plain.txt</file>
+ </licenseHeader>
+ </java>
+ <pom>
+ <sortPom>
+ <expandEmptyElements>false</expandEmptyElements>
+ <!-- https://issues.apache.org/jira/browse/MRELEASE-1111 -->
+ <spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
+ <nrOfIndentSpace>4</nrOfIndentSpace>
+ <!-- Indentation -->
+ </sortPom>
+ </pom>
+ <upToDateChecking>
+ <enabled>true</enabled>
+ </upToDateChecking>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-shared-resources</artifactId>
+ <version>5</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <phase>process-sources</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/src/main/java/org/apache/sling/models/impl/AdapterImplementations.java b/src/main/java/org/apache/sling/models/impl/AdapterImplementations.java
index 8bac535..ef40327 100644
--- a/src/main/java/org/apache/sling/models/impl/AdapterImplementations.java
+++ b/src/main/java/org/apache/sling/models/impl/AdapterImplementations.java
@@ -50,11 +50,10 @@ final class AdapterImplementations {
private static final Logger log = LoggerFactory.getLogger(AdapterImplementations.class);
- private final ConcurrentMap<String,ConcurrentNavigableMap<String,ModelClass<?>>> adapterImplementations
- = new ConcurrentHashMap<>();
+ private final ConcurrentMap<String, ConcurrentNavigableMap<String, ModelClass<?>>> adapterImplementations =
+ new ConcurrentHashMap<>();
- private final ConcurrentMap<String,ModelClass<?>> modelClasses
- = new ConcurrentHashMap<>();
+ private final ConcurrentMap<String, ModelClass<?>> modelClasses = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Class<?>> resourceTypeMappingsForResources = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Class<?>> resourceTypeMappingsForRequests = new ConcurrentHashMap<>();
@@ -62,10 +61,12 @@ final class AdapterImplementations {
private final ConcurrentMap<Bundle, List<String>> resourceTypeRemovalListsForRequests = new ConcurrentHashMap<>();
private volatile ImplementationPicker[] sortedImplementationPickers = new ImplementationPicker[0];
- private volatile StaticInjectAnnotationProcessorFactory[] sortedStaticInjectAnnotationProcessorFactories = new StaticInjectAnnotationProcessorFactory[0];
+ private volatile StaticInjectAnnotationProcessorFactory[] sortedStaticInjectAnnotationProcessorFactories =
+ new StaticInjectAnnotationProcessorFactory[0];
public void setImplementationPickers(Collection<ImplementationPicker> implementationPickers) {
- this.sortedImplementationPickers = implementationPickers.toArray(new ImplementationPicker[implementationPickers.size()]);
+ this.sortedImplementationPickers =
+ implementationPickers.toArray(new ImplementationPicker[implementationPickers.size()]);
}
public ImplementationPicker[] getImplementationPickers() {
@@ -78,7 +79,8 @@ final class AdapterImplementations {
public void setStaticInjectAnnotationProcessorFactories(
Collection<StaticInjectAnnotationProcessorFactory> factories) {
- this.sortedStaticInjectAnnotationProcessorFactories = factories.toArray(new StaticInjectAnnotationProcessorFactory[factories.size()]);
+ this.sortedStaticInjectAnnotationProcessorFactories =
+ factories.toArray(new StaticInjectAnnotationProcessorFactory[factories.size()]);
updateProcessorFactoriesInModelClasses();
}
@@ -88,12 +90,14 @@ final class AdapterImplementations {
private void updateProcessorFactoriesInModelClasses() {
Iterator<ModelClass<?>> items = modelClasses.values().iterator();
updateProcessorFactoriesInModelClasses(items);
- Iterator<ConcurrentNavigableMap<String,ModelClass<?>>> mapItems = adapterImplementations.values().iterator();
+ Iterator<ConcurrentNavigableMap<String, ModelClass<?>>> mapItems =
+ adapterImplementations.values().iterator();
while (mapItems.hasNext()) {
- ConcurrentNavigableMap<String,ModelClass<?>> mapItem = mapItems.next();
+ ConcurrentNavigableMap<String, ModelClass<?>> mapItem = mapItems.next();
updateProcessorFactoriesInModelClasses(mapItem.values().iterator());
}
}
+
private void updateProcessorFactoriesInModelClasses(Iterator<ModelClass<?>> items) {
while (items.hasNext()) {
ModelClass<?> item = items.next();
@@ -135,11 +139,13 @@ final class AdapterImplementations {
if (adapterType == implType) {
modelClasses.put(key, modelClass);
} else {
- // although we already use a ConcurrentMap synchronize explicitly because we apply non-atomic operations on it
+ // although we already use a ConcurrentMap synchronize explicitly because we apply non-atomic operations
+ // on it
synchronized (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
+ // to have a consistent ordering independent of bundle loading use a ConcurrentSkipListMap that
+ // sorts by class name
implementations = new ConcurrentSkipListMap<>();
adapterImplementations.put(key, implementations);
}
@@ -159,11 +165,11 @@ final class AdapterImplementations {
String key = adapterTypeName;
if (StringUtils.equals(adapterTypeName, implTypeName)) {
modelClasses.remove(key);
- }
- else {
- // although we already use a ConcurrentMap synchronize explicitly because we apply non-atomic operations on it
+ } else {
+ // although we already use a ConcurrentMap synchronize explicitly because we apply non-atomic operations on
+ // it
synchronized (adapterImplementations) {
- ConcurrentNavigableMap<String,ModelClass<?>> implementations = adapterImplementations.get(key);
+ ConcurrentNavigableMap<String, ModelClass<?>> implementations = adapterImplementations.get(key);
if (implementations != null) {
implementations.remove(implTypeName);
if (implementations.isEmpty()) {
@@ -193,31 +199,32 @@ final class AdapterImplementations {
String key = adapterType.getName();
// lookup in cache for models without adapter classes
- ModelClass<ModelType> modelClass = (ModelClass<ModelType>)modelClasses.get(key);
- if (modelClass!=null) {
+ ModelClass<ModelType> modelClass = (ModelClass<ModelType>) modelClasses.get(key);
+ if (modelClass != null) {
return modelClass;
}
// not found? look in cache with adapter classes
- ConcurrentNavigableMap<String,ModelClass<?>> implementations = adapterImplementations.get(key);
- if (implementations==null || implementations.isEmpty()) {
+ ConcurrentNavigableMap<String, ModelClass<?>> implementations = adapterImplementations.get(key);
+ if (implementations == null || implementations.isEmpty()) {
return null;
}
Collection<ModelClass<?>> implementationsCollection = implementations.values();
- ModelClass<?>[] implementationWrappersArray = implementationsCollection.toArray(new ModelClass<?>[implementationsCollection.size()]);
+ 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++) {
+ for (int i = 0; i < implementationWrappersArray.length; i++) {
implementationsArray[i] = implementationWrappersArray[i].getType();
}
for (ImplementationPicker picker : this.sortedImplementationPickers) {
Class<?> implementation = picker.pick(adapterType, implementationsArray, adaptable);
if (implementation != null) {
- for (int i=0; i<implementationWrappersArray.length; i++) {
- if (implementation==implementationWrappersArray[i].getType()) {
- return (ModelClass<ModelType>)implementationWrappersArray[i];
+ for (int i = 0; i < implementationWrappersArray.length; i++) {
+ if (implementation == implementationWrappersArray[i].getType()) {
+ return (ModelClass<ModelType>) implementationWrappersArray[i];
}
}
}
@@ -235,65 +242,69 @@ final class AdapterImplementations {
String key = adapterType.getName();
// lookup in cache for models without adapter classes
- ModelClass<ModelType> modelClass = (ModelClass<ModelType>)modelClasses.get(key);
- if (modelClass!=null) {
+ ModelClass<ModelType> modelClass = (ModelClass<ModelType>) modelClasses.get(key);
+ if (modelClass != null) {
return true;
}
// not found? look in cache with adapter classes
- ConcurrentNavigableMap<String,ModelClass<?>> implementations = adapterImplementations.get(key);
- if (implementations==null || implementations.isEmpty()) {
+ ConcurrentNavigableMap<String, ModelClass<?>> implementations = adapterImplementations.get(key);
+ if (implementations == null || implementations.isEmpty()) {
return false;
}
return true;
}
- public void registerModelToResourceType(final Bundle bundle, final String resourceType, final Class<?> adaptableType, final Class<?> clazz) {
- if (resourceType.startsWith("/")) {
- log.warn("Registering model class {} for adaptable {} with absolute resourceType {}." ,
- new Object[] { clazz, adaptableType, resourceType });
- }
- ConcurrentMap<String, Class<?>> map;
- ConcurrentMap<Bundle, List<String>> resourceTypeRemovalLists;
- if (adaptableType == Resource.class) {
- map = resourceTypeMappingsForResources;
- resourceTypeRemovalLists = resourceTypeRemovalListsForResources;
- } else if (adaptableType == SlingHttpServletRequest.class) {
- map = resourceTypeMappingsForRequests;
- resourceTypeRemovalLists = resourceTypeRemovalListsForRequests;
- } else {
- log.warn("Found model class {} with resource type {} for adaptable {}. Unsupported type for resourceType binding.",
- new Object[] { clazz, resourceType, adaptableType });
- return;
- }
- Class<?> existingMapping = map.putIfAbsent(resourceType, clazz);
- if (existingMapping == null) {
- resourceTypeRemovalLists.putIfAbsent(bundle, new CopyOnWriteArrayList<String>());
- resourceTypeRemovalLists.get(bundle).add(resourceType);
- } else {
- log.warn("Skipped registering {} for resourceType {} under adaptable {} because of existing mapping to {}",
- new Object[] { clazz, resourceType, adaptableType, existingMapping });
- }
- }
-
- public void removeResourceTypeBindings(final Bundle bundle) {
- List<String> registeredResourceTypes = resourceTypeRemovalListsForResources.remove(bundle);
- if (registeredResourceTypes != null) {
- for (String resourceType : registeredResourceTypes) {
- resourceTypeMappingsForResources.remove(resourceType);
- }
- }
- registeredResourceTypes = resourceTypeRemovalListsForRequests.remove(bundle);
- if (registeredResourceTypes != null) {
- for (String resourceType : registeredResourceTypes) {
- resourceTypeMappingsForRequests.remove(resourceType);
- }
- }
- }
-
- public Class<?> getModelClassForRequest(final SlingHttpServletRequest request) {
- return getModelClassForResource(request.getResource(), resourceTypeMappingsForRequests);
- }
+ public void registerModelToResourceType(
+ final Bundle bundle, final String resourceType, final Class<?> adaptableType, final Class<?> clazz) {
+ if (resourceType.startsWith("/")) {
+ log.warn(
+ "Registering model class {} for adaptable {} with absolute resourceType {}.",
+ new Object[] {clazz, adaptableType, resourceType});
+ }
+ ConcurrentMap<String, Class<?>> map;
+ ConcurrentMap<Bundle, List<String>> resourceTypeRemovalLists;
+ if (adaptableType == Resource.class) {
+ map = resourceTypeMappingsForResources;
+ resourceTypeRemovalLists = resourceTypeRemovalListsForResources;
+ } else if (adaptableType == SlingHttpServletRequest.class) {
+ map = resourceTypeMappingsForRequests;
+ resourceTypeRemovalLists = resourceTypeRemovalListsForRequests;
+ } else {
+ log.warn(
+ "Found model class {} with resource type {} for adaptable {}. Unsupported type for resourceType binding.",
+ new Object[] {clazz, resourceType, adaptableType});
+ return;
+ }
+ Class<?> existingMapping = map.putIfAbsent(resourceType, clazz);
+ if (existingMapping == null) {
+ resourceTypeRemovalLists.putIfAbsent(bundle, new CopyOnWriteArrayList<String>());
+ resourceTypeRemovalLists.get(bundle).add(resourceType);
+ } else {
+ log.warn(
+ "Skipped registering {} for resourceType {} under adaptable {} because of existing mapping to {}",
+ new Object[] {clazz, resourceType, adaptableType, existingMapping});
+ }
+ }
+
+ public void removeResourceTypeBindings(final Bundle bundle) {
+ List<String> registeredResourceTypes = resourceTypeRemovalListsForResources.remove(bundle);
+ if (registeredResourceTypes != null) {
+ for (String resourceType : registeredResourceTypes) {
+ resourceTypeMappingsForResources.remove(resourceType);
+ }
+ }
+ registeredResourceTypes = resourceTypeRemovalListsForRequests.remove(bundle);
+ if (registeredResourceTypes != null) {
+ for (String resourceType : registeredResourceTypes) {
+ resourceTypeMappingsForRequests.remove(resourceType);
+ }
+ }
+ }
+
+ public Class<?> getModelClassForRequest(final SlingHttpServletRequest request) {
+ return getModelClassForResource(request.getResource(), resourceTypeMappingsForRequests);
+ }
public Class<?> getModelClassForResource(final Resource resource) {
return getModelClassForResource(resource, resourceTypeMappingsForResources);
@@ -327,7 +338,8 @@ final class AdapterImplementations {
}
}
- private static Class<?> getClassFromResourceTypeMap(final String resourceType, final Map<String, Class<?>> map, final ResourceResolver resolver) {
+ private static Class<?> getClassFromResourceTypeMap(
+ final String resourceType, final Map<String, Class<?>> map, final ResourceResolver resolver) {
if (resourceType == null) {
return null;
}
diff --git a/src/main/java/org/apache/sling/models/impl/ExportServlet.java b/src/main/java/org/apache/sling/models/impl/ExportServlet.java
index 736ba10..cdb318d 100644
--- a/src/main/java/org/apache/sling/models/impl/ExportServlet.java
+++ b/src/main/java/org/apache/sling/models/impl/ExportServlet.java
@@ -18,13 +18,9 @@
*/
package org.apache.sling.models.impl;
-import static org.apache.sling.api.scripting.SlingBindings.LOG;
-import static org.apache.sling.api.scripting.SlingBindings.OUT;
-import static org.apache.sling.api.scripting.SlingBindings.READER;
-import static org.apache.sling.api.scripting.SlingBindings.REQUEST;
-import static org.apache.sling.api.scripting.SlingBindings.RESOURCE;
-import static org.apache.sling.api.scripting.SlingBindings.RESPONSE;
-import static org.apache.sling.api.scripting.SlingBindings.SLING;
+import javax.script.Bindings;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
@@ -32,10 +28,6 @@ import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
-import javax.script.Bindings;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletResponse;
-
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.scripting.LazyBindings;
@@ -51,6 +43,14 @@ import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.sling.api.scripting.SlingBindings.LOG;
+import static org.apache.sling.api.scripting.SlingBindings.OUT;
+import static org.apache.sling.api.scripting.SlingBindings.READER;
+import static org.apache.sling.api.scripting.SlingBindings.REQUEST;
+import static org.apache.sling.api.scripting.SlingBindings.RESOURCE;
+import static org.apache.sling.api.scripting.SlingBindings.RESPONSE;
+import static org.apache.sling.api.scripting.SlingBindings.SLING;
+
@SuppressWarnings("serial")
class ExportServlet extends SlingSafeMethodsServlet {
@@ -68,10 +68,16 @@ class ExportServlet extends SlingSafeMethodsServlet {
private final ExportedObjectAccessor accessor;
private final Map<String, String> baseOptions;
- public ExportServlet(BundleContext bundleContext, ModelFactory modelFactory,
- BindingsValuesProvidersByContext bindingsValuesProvidersByContext, SlingModelsScriptEngineFactory scriptFactory,
- Class<?> annotatedClass, String registeredSelector, String exporterName, ExportedObjectAccessor accessor,
- Map<String, String> baseOptions) {
+ public ExportServlet(
+ BundleContext bundleContext,
+ ModelFactory modelFactory,
+ BindingsValuesProvidersByContext bindingsValuesProvidersByContext,
+ SlingModelsScriptEngineFactory scriptFactory,
+ Class<?> annotatedClass,
+ String registeredSelector,
+ String exporterName,
+ ExportedObjectAccessor accessor,
+ Map<String, String> baseOptions) {
this.bundleContext = bundleContext;
this.modelFactory = modelFactory;
this.bindingsValuesProvidersByContext = bindingsValuesProvidersByContext;
@@ -124,12 +130,14 @@ class ExportServlet extends SlingSafeMethodsServlet {
}
}
- private void addScriptBindings(SlingScriptHelper scriptHelper, SlingHttpServletRequest request, SlingHttpServletResponse response)
+ private void addScriptBindings(
+ SlingScriptHelper scriptHelper, SlingHttpServletRequest request, SlingHttpServletResponse response)
throws IOException {
Bindings bindings = new LazyBindings();
bindings.put(SLING, scriptHelper);
bindings.put(RESOURCE, request.getResource());
- bindings.put(SlingModelsScriptEngineFactory.RESOLVER, request.getResource().getResourceResolver());
+ bindings.put(
+ SlingModelsScriptEngineFactory.RESOLVER, request.getResource().getResourceResolver());
bindings.put(REQUEST, request);
bindings.put(RESPONSE, response);
try {
@@ -146,13 +154,13 @@ class ExportServlet extends SlingSafeMethodsServlet {
slingBindings.putAll(bindings);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
-
}
private Map<String, String> createOptionMap(SlingHttpServletRequest request) {
Map<String, String[]> parameterMap = request.getParameterMap();
String[] selectors = request.getRequestPathInfo().getSelectors();
- Map<String, String> result = new HashMap<String, String>(baseOptions.size() + parameterMap.size() + selectors.length - 1);
+ Map<String, String> result =
+ new HashMap<String, String>(baseOptions.size() + parameterMap.size() + selectors.length - 1);
result.putAll(baseOptions);
for (String selector : selectors) {
if (!selector.equals(registeredSelector)) {
@@ -171,7 +179,12 @@ class ExportServlet extends SlingSafeMethodsServlet {
}
public interface ExportedObjectAccessor {
- String getExportedString(SlingHttpServletRequest request, Map<String, String> options, ModelFactory modelFactory, String exporterName) throws ExportException, MissingExporterException;
+ String getExportedString(
+ SlingHttpServletRequest request,
+ Map<String, String> options,
+ ModelFactory modelFactory,
+ String exporterName)
+ throws ExportException, MissingExporterException;
}
public static final class ResourceAccessor implements ExportedObjectAccessor {
@@ -183,7 +196,12 @@ class ExportServlet extends SlingSafeMethodsServlet {
}
@Override
- public String getExportedString(SlingHttpServletRequest request, Map<String, String> options, ModelFactory modelFactory, String exporterName) throws ExportException, MissingExporterException {
+ public String getExportedString(
+ SlingHttpServletRequest request,
+ Map<String, String> options,
+ ModelFactory modelFactory,
+ String exporterName)
+ throws ExportException, MissingExporterException {
Object adapter = modelFactory.createModel(request.getResource(), adapterClass);
return modelFactory.exportModel(adapter, exporterName, String.class, options);
}
@@ -198,10 +216,15 @@ class ExportServlet extends SlingSafeMethodsServlet {
}
@Override
- public String getExportedString(SlingHttpServletRequest request, Map<String, String> options, ModelFactory modelFactory, String exporterName) throws ExportException, MissingExporterException {
+ public String getExportedString(
+ SlingHttpServletRequest request,
+ Map<String, String> options,
+ ModelFactory modelFactory,
+ String exporterName)
+ throws ExportException, MissingExporterException {
Object adapter = modelFactory.createModel(request, adapterClass);
return modelFactory.exportModel(adapter, exporterName, String.class, options);
}
- };
-
+ }
+ ;
}
diff --git a/src/main/java/org/apache/sling/models/impl/FirstImplementationPicker.java b/src/main/java/org/apache/sling/models/impl/FirstImplementationPicker.java
index 89b6c96..aba322b 100644
--- a/src/main/java/org/apache/sling/models/impl/FirstImplementationPicker.java
+++ b/src/main/java/org/apache/sling/models/impl/FirstImplementationPicker.java
@@ -30,13 +30,13 @@ import org.osgi.service.component.annotations.Component;
* But at least it gives a consistent behavior.
* It's service ranking is set to the highest value to allow more intelligent implementations to step in.
*/
-@Component(property=Constants.SERVICE_RANKING+":Integer="+Integer.MAX_VALUE, service=ImplementationPicker.class)
+@Component(property = Constants.SERVICE_RANKING + ":Integer=" + Integer.MAX_VALUE, service = ImplementationPicker.class)
public class FirstImplementationPicker implements ImplementationPicker {
@Override
- public Class<?> pick(@NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
+ public Class<?> pick(
+ @NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
// implementations is never null or empty
return implementationsTypes[0];
}
-
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/models/impl/MapBackedInvocationHandler.java b/src/main/java/org/apache/sling/models/impl/MapBackedInvocationHandler.java
index c486781..4109c1c 100644
--- a/src/main/java/org/apache/sling/models/impl/MapBackedInvocationHandler.java
+++ b/src/main/java/org/apache/sling/models/impl/MapBackedInvocationHandler.java
@@ -33,5 +33,4 @@ class MapBackedInvocationHandler implements InvocationHandler {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return methods.get(method);
}
-
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
index 9724013..2aa6ffb 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
@@ -1,21 +1,29 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
+import javax.annotation.PostConstruct;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+import javax.servlet.ServletRequestWrapper;
+
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
@@ -24,12 +32,6 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import javax.annotation.PostConstruct;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletRequestEvent;
-import javax.servlet.ServletRequestListener;
-import javax.servlet.ServletRequestWrapper;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.adapter.Adaptable;
@@ -93,10 +95,15 @@ import org.osgi.service.metatype.annotations.Designate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Component(immediate = true, service={ ModelFactory.class, ServletRequestListener.class },
- property= { HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER+"=true",
- HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT+"=(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)" })
-@Designate(ocd=ModelAdapterFactoryConfiguration.class)
+@Component(
+ immediate = true,
+ service = {ModelFactory.class, ServletRequestListener.class},
+ property = {
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER + "=true",
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=("
+ + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)"
+ })
+@Designate(ocd = ModelAdapterFactoryConfiguration.class)
@SuppressWarnings("deprecation")
public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFactory, ServletRequestListener {
@@ -122,14 +129,12 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
callbacks = Collections.unmodifiableList(callbacks);
}
-
@Override
public void onDisposed() {
for (DisposalCallback callback : callbacks) {
callback.onDisposed();
}
}
-
}
private static class CombinedDisposable implements Disposable {
@@ -147,7 +152,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
}
- private interface Disposable {
+ private interface Disposable {
void onDisposed();
}
@@ -208,18 +213,27 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
private final RankedServices<Injector> sortedInjectors = new RankedServices<>();
private final ConcurrentMap<Class<? extends ViaProviderType>, ViaProvider> viaProviders = new ConcurrentHashMap<>();
- @Reference(name="injectAnnotationProcessorFactory", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- volatile Collection<InjectAnnotationProcessorFactory> injectAnnotationProcessorFactories; // this must be non-final for fieldOption=replace!
+ @Reference(
+ name = "injectAnnotationProcessorFactory",
+ cardinality = ReferenceCardinality.MULTIPLE,
+ policy = ReferencePolicy.DYNAMIC)
+ volatile Collection<InjectAnnotationProcessorFactory>
+ injectAnnotationProcessorFactories; // this must be non-final for fieldOption=replace!
- @Reference(name="injectAnnotationProcessorFactory2", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- volatile Collection<InjectAnnotationProcessorFactory2> injectAnnotationProcessorFactories2; // this must be non-final for fieldOption=replace!
+ @Reference(
+ name = "injectAnnotationProcessorFactory2",
+ cardinality = ReferenceCardinality.MULTIPLE,
+ policy = ReferencePolicy.DYNAMIC)
+ volatile Collection<InjectAnnotationProcessorFactory2>
+ injectAnnotationProcessorFactories2; // this must be non-final for fieldOption=replace!
- private final RankedServices<StaticInjectAnnotationProcessorFactory> staticInjectAnnotationProcessorFactories = new RankedServices<>();
+ private final RankedServices<StaticInjectAnnotationProcessorFactory> staticInjectAnnotationProcessorFactories =
+ new RankedServices<>();
private final 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, policyOption=ReferencePolicyOption.GREEDY)
+ @Reference(cardinality = ReferenceCardinality.OPTIONAL, policyOption = ReferencePolicyOption.GREEDY)
private ModelValidation modelValidation = null;
@Reference(name = "modelExporter", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
@@ -239,7 +253,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
private ServiceRegistration configPrinterRegistration;
- // Use threadlocal to count recursive invocations and break recursing if a max. limit is reached (to avoid cyclic dependencies)
+ // Use threadlocal to count recursive invocations and break recursing if a max. limit is reached (to avoid cyclic
+ // dependencies)
private ThreadLocal<ThreadInvocationCounter> invocationCountThreadLocal;
private Map<Object, Map<Class<?>, SoftReference<Object>>> adapterCache;
@@ -252,7 +267,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
Result<AdapterType> result = internalCreateModel(adaptable, type);
if (!result.wasSuccessful()) {
if (result == Result.POST_CONSTRUCT_PREVENTED_MODEL_CONSTRUCTION) {
- log.debug("Could not adapt to model as PostConstruct method returned false"); // do no construct runtime exception in this case
+ log.debug("Could not adapt to model as PostConstruct method returned false"); // do no construct runtime
+ // exception in this case
} else {
log.warn("Could not adapt to model", result.getThrowable());
}
@@ -263,8 +279,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
@Override
- public @NotNull <ModelType> ModelType createModel(@NotNull Object adaptable, @NotNull Class<ModelType> type) throws MissingElementsException,
- InvalidAdaptableException, ValidationException, InvalidModelException {
+ public @NotNull <ModelType> ModelType createModel(@NotNull Object adaptable, @NotNull Class<ModelType> type)
+ throws MissingElementsException, InvalidAdaptableException, ValidationException, InvalidModelException {
Result<ModelType> result = internalCreateModel(adaptable, type);
if (!result.wasSuccessful()) {
throw result.getThrowable();
@@ -273,16 +289,22 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
@Override
- public @NotNull<T> T createModelFromWrappedRequest(@NotNull SlingHttpServletRequest request, @NotNull Resource resource, @NotNull Class<T> targetClass) {
- return createModel(new ResourceOverridingRequestWrapper(request, resource, adapterManager, scriptEngineFactory, bindingsValuesProvidersByContext), targetClass);
+ public @NotNull <T> T createModelFromWrappedRequest(
+ @NotNull SlingHttpServletRequest request, @NotNull Resource resource, @NotNull Class<T> targetClass) {
+ return createModel(
+ new ResourceOverridingRequestWrapper(
+ request, resource, adapterManager, scriptEngineFactory, bindingsValuesProvidersByContext),
+ targetClass);
}
-
+
@Override
- public boolean canCreateFromAdaptable(@NotNull Object adaptable, @NotNull Class<?> modelClass) throws ModelClassException {
+ public boolean canCreateFromAdaptable(@NotNull Object adaptable, @NotNull Class<?> modelClass)
+ throws ModelClassException {
return internalCanCreateFromAdaptable(adaptable, modelClass);
}
- private boolean internalCanCreateFromAdaptable(Object adaptable, Class<?> requestedType) throws ModelClassException {
+ private boolean internalCanCreateFromAdaptable(Object adaptable, Class<?> requestedType)
+ throws ModelClassException {
try {
ModelClass<?> modelClass = getImplementationTypeForAdapterType(requestedType, adaptable);
Class<?>[] declaredAdaptable = modelClass.getModelAnnotation().adaptables();
@@ -292,7 +314,10 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
}
} catch (ModelClassException e) {
- log.debug("Could not find implementation for given type " + requestedType + ". Probably forgot either the model annotation or it was not registered as adapter factory (yet)", e);
+ log.debug(
+ "Could not find implementation for given type " + requestedType
+ + ". Probably forgot either the model annotation or it was not registered as adapter factory (yet)",
+ e);
return false;
}
return false;
@@ -304,7 +329,9 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
try {
getImplementationTypeForAdapterType(requestedType, adaptable);
} catch (ModelClassException e) {
- log.debug("Could not find implementation for given adaptable. Probably forgot either the model annotation or it was not registered as adapter factory (yet)", e);
+ log.debug(
+ "Could not find implementation for given adaptable. Probably forgot either the model annotation or it was not registered as adapter factory (yet)",
+ e);
return false;
}
return true;
@@ -324,7 +351,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
* href="http://sling.apache.org/documentation/bundles/models.html#specifying-an-alternate-adapter-class-since-sling-models-110">Specifying
* an Alternate Adapter Class</a>
*/
- private <ModelType> ModelClass<ModelType> getImplementationTypeForAdapterType(Class<ModelType> requestedType, Object adaptable) {
+ private <ModelType> ModelClass<ModelType> getImplementationTypeForAdapterType(
+ Class<ModelType> requestedType, Object adaptable) {
// lookup ModelClass wrapper for implementation type
// additionally check if a different implementation class was registered for this adapter type
// the adapter implementation is initially filled by the ModelPackageBundleList
@@ -334,7 +362,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
return modelClass;
}
// throw exception here
- throw new ModelClassException("Could not yet find an adapter factory for the model " + requestedType + " from adaptable " + adaptable.getClass());
+ throw new ModelClassException("Could not yet find an adapter factory for the model " + requestedType
+ + " from adaptable " + adaptable.getClass());
}
@SuppressWarnings("unchecked")
@@ -348,7 +377,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
request.setAttribute(REQUEST_CACHE_ATTRIBUTE, adaptableCache);
}
} else {
- adaptableCache = adapterCache.computeIfAbsent(adaptable, k -> Collections.synchronizedMap(new WeakHashMap<>()));
+ adaptableCache =
+ adapterCache.computeIfAbsent(adaptable, k -> Collections.synchronizedMap(new WeakHashMap<>()));
}
return adaptableCache;
}
@@ -358,7 +388,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
Result<ModelType> result;
ThreadInvocationCounter threadInvocationCounter = invocationCountThreadLocal.get();
if (threadInvocationCounter.isMaximumReached()) {
- String msg = String.format("Adapting %s to %s failed, too much recursive invocations (>=%s).",
+ String msg = String.format(
+ "Adapting %s to %s failed, too much recursive invocations (>=%s).",
adaptable, requestedType, threadInvocationCounter.maxRecursionDepth);
return new Result<>(new ModelClassException(msg));
}
@@ -368,7 +399,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
ModelClass<ModelType> modelClass = getImplementationTypeForAdapterType(requestedType, adaptable);
if (!modelClass.hasModelAnnotation()) {
- String msg = String.format("Provided Adapter class does not have a Model annotation: %s", modelClass.getType());
+ String msg = String.format(
+ "Provided Adapter class does not have a Model annotation: %s", modelClass.getType());
return new Result<>(new ModelClassException(msg));
}
boolean isAdaptable = false;
@@ -394,7 +426,9 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
}
if (!isAdaptable) {
- String msg = String.format("Given adaptable (%s) is not acceptable for the model class: %s which only supports adaptables %s", adaptable.getClass(), modelClass.getType(), StringUtils.join(declaredAdaptable));
+ String msg = String.format(
+ "Given adaptable (%s) is not acceptable for the model class: %s which only supports adaptables %s",
+ adaptable.getClass(), modelClass.getType(), StringUtils.join(declaredAdaptable));
return new Result<>(new InvalidAdaptableException(msg));
} else {
RuntimeException t = validateModel(adaptable, modelClass.getType(), modelAnnotation);
@@ -404,7 +438,10 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
if (modelClass.getType().isInterface()) {
Result<InvocationHandler> handlerResult = createInvocationHandler(adaptable, modelClass);
if (handlerResult.wasSuccessful()) {
- ModelType model = (ModelType) Proxy.newProxyInstance(modelClass.getType().getClassLoader(), new Class<?>[] { modelClass.getType() }, handlerResult.getValue());
+ ModelType model = (ModelType) Proxy.newProxyInstance(
+ modelClass.getType().getClassLoader(),
+ new Class<?>[] {modelClass.getType()},
+ handlerResult.getValue());
if (modelAnnotation.cache() && adaptableCache != null) {
adaptableCache.put(modelClass.getType(), new SoftReference<>(model));
@@ -433,12 +470,15 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
}
- private <ModelType> RuntimeException validateModel(Object adaptable, Class<ModelType> modelType, Model modelAnnotation) {
+ private <ModelType> RuntimeException validateModel(
+ Object adaptable, Class<ModelType> modelType, Model modelAnnotation) {
if (modelAnnotation.validation() != ValidationStrategy.DISABLED) {
if (modelValidation == null) {
- return new ValidationException("No active service for ModelValidation found, therefore no validation can be performed.");
+ return new ValidationException(
+ "No active service for ModelValidation found, therefore no validation can be performed.");
}
- return modelValidation.validate(adaptable, modelType, modelAnnotation.validation() == ValidationStrategy.REQUIRED);
+ return modelValidation.validate(
+ adaptable, modelType, modelAnnotation.validation() == ValidationStrategy.REQUIRED);
}
return null;
}
@@ -471,7 +511,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
private final Map<Method, Object> methods;
- private SetMethodsCallback( Map<Method, Object> methods) {
+ private SetMethodsCallback(Map<Method, Object> methods) {
this.methods = methods;
}
@@ -491,7 +531,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
@Override
public RuntimeException inject(InjectableElement element, Object value) {
- return setConstructorParameter((ConstructorParameter)element, parameterValues, value);
+ return setConstructorParameter((ConstructorParameter) element, parameterValues, value);
}
}
@@ -507,18 +547,21 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
@Override
public RuntimeException inject(InjectableElement element1, Object value) {
- return chainedCallback.inject(element, value.equals(Optional.empty())
- ? value // if the value is null it's already represented as Optional.empty(), return as is
- : Optional.of(value)); // otherwise wrap in Optional
+ return chainedCallback.inject(
+ element,
+ value.equals(Optional.empty())
+ ? value // if the value is null it's already represented as Optional.empty(), return as is
+ : Optional.of(value)); // otherwise wrap in Optional
}
}
- private
- @Nullable
- RuntimeException injectElement(final InjectableElement element, final Object adaptable,
- final @NotNull DisposalCallbackRegistry registry, final InjectCallback callback,
- final @NotNull Map<ValuePreparer, Object> preparedValues,
- final @Nullable BundleContext modelContext) {
+ private @Nullable RuntimeException injectElement(
+ final InjectableElement element,
+ final Object adaptable,
+ final @NotNull DisposalCallbackRegistry registry,
+ final InjectCallback callback,
+ final @NotNull Map<ValuePreparer, Object> preparedValues,
+ final @Nullable BundleContext modelContext) {
if (element instanceof InjectableField) {
Type genericType = ((InjectableField) element).getFieldGenericType();
@@ -526,10 +569,12 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
ParameterizedType pType = (ParameterizedType) genericType;
if (pType.getRawType().equals(Optional.class)) {
- InjectableElement el = new OptionalTypedInjectableElement(element, pType.getActualTypeArguments()[0]);
+ InjectableElement el =
+ new OptionalTypedInjectableElement(element, pType.getActualTypeArguments()[0]);
InjectCallback wrappedCallback = new OptionalWrappingCallback(callback, element);
- return injectElementInternal(el, adaptable, registry, wrappedCallback, preparedValues, modelContext);
+ return injectElementInternal(
+ el, adaptable, registry, wrappedCallback, preparedValues, modelContext);
}
}
}
@@ -537,12 +582,13 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
return injectElementInternal(element, adaptable, registry, callback, preparedValues, modelContext);
}
- private
- @Nullable
- RuntimeException injectElementInternal(final InjectableElement element, final Object adaptable,
- final @NotNull DisposalCallbackRegistry registry, final InjectCallback callback,
- final @NotNull Map<ValuePreparer, Object> preparedValues,
- final @Nullable BundleContext modelContext) {
+ private @Nullable RuntimeException injectElementInternal(
+ final InjectableElement element,
+ final Object adaptable,
+ final @NotNull DisposalCallbackRegistry registry,
+ final InjectCallback callback,
+ final @NotNull Map<ValuePreparer, Object> preparedValues,
+ final @Nullable BundleContext modelContext) {
InjectAnnotationProcessor annotationProcessor = null;
String source = element.getSource();
@@ -574,11 +620,11 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
final RankedServices<Injector> injectorsToProcess;
if (StringUtils.isEmpty(source)) {
injectorsToProcess = sortedInjectors;
- }
- else {
+ } else {
injectorsToProcess = injectors.get(source);
if (injectorsToProcess == null) {
- throw new IllegalArgumentException("No Sling Models Injector registered for source '" + source + "'.");
+ throw new IllegalArgumentException(
+ "No Sling Models Injector registered for source '" + source + "'.");
}
}
@@ -600,9 +646,17 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
Object value = null;
if (injector instanceof OSGiServiceInjector) {
- value = ((OSGiServiceInjector)injector).getValue(preparedValue, name, element.getType(), element.getAnnotatedElement(), registry, modelContext);
+ value = ((OSGiServiceInjector) injector)
+ .getValue(
+ preparedValue,
+ name,
+ element.getType(),
+ element.getAnnotatedElement(),
+ registry,
+ modelContext);
} else {
- value = injector.getValue(preparedValue, name, element.getType(), element.getAnnotatedElement(), registry);
+ value = injector.getValue(
+ preparedValue, name, element.getType(), element.getAnnotatedElement(), registry);
}
if (value != null) {
lastInjectionException = callback.inject(element, value);
@@ -621,7 +675,11 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
wasInjectionSuccessful = defaultInjectionResult.getValue();
// log previous injection error, if there was any
if (lastInjectionException != null && wasInjectionSuccessful) {
- log.debug("Although falling back to default value worked, injection into {} failed because of: " + lastInjectionException.getMessage(), element.getAnnotatedElement(), lastInjectionException);
+ log.debug(
+ "Although falling back to default value worked, injection into {} failed because of: "
+ + lastInjectionException.getMessage(),
+ element.getAnnotatedElement(),
+ lastInjectionException);
}
} else {
return defaultInjectionResult.getThrowable();
@@ -633,7 +691,11 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
if (element.isOptional(annotationProcessor)) {
// log previous injection error, if there was any
if (lastInjectionException != null) {
- log.debug("Injection into optional element {} failed because of: " + lastInjectionException.getMessage(), element.getAnnotatedElement(), lastInjectionException);
+ log.debug(
+ "Injection into optional element {} failed because of: "
+ + lastInjectionException.getMessage(),
+ element.getAnnotatedElement(),
+ lastInjectionException);
}
if (element.isPrimitive()) {
RuntimeException throwable = injectPrimitiveInitialValue(element, callback);
@@ -660,7 +722,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
return null;
}
- private <ModelType> Result<InvocationHandler> createInvocationHandler(final Object adaptable, final ModelClass<ModelType> modelClass) {
+ private <ModelType> Result<InvocationHandler> createInvocationHandler(
+ final Object adaptable, final ModelClass<ModelType> modelClass) {
InjectableMethod[] injectableMethods = modelClass.getInjectableMethods();
final Map<Method, Object> methods = new HashMap<>();
SetMethodsCallback callback = new SetMethodsCallback(methods);
@@ -684,15 +747,17 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
if (!registry.callbacks.isEmpty()) {
registry.seal();
- if (adaptable instanceof SlingHttpServletRequest &&
- ((SlingHttpServletRequest) adaptable).getAttribute(REQUEST_MARKER_ATTRIBUTE) == REQUEST_MARKER_VALUE) {
+ if (adaptable instanceof SlingHttpServletRequest
+ && ((SlingHttpServletRequest) adaptable).getAttribute(REQUEST_MARKER_ATTRIBUTE)
+ == REQUEST_MARKER_VALUE) {
registerRequestCallbackRegistry((SlingHttpServletRequest) adaptable, registry);
} else {
registerCallbackRegistry(handler, registry);
}
}
if (missingElements != null) {
- MissingElementsException missingElementsException = new MissingElementsException("Could not create all mandatory methods for interface of model " + modelClass);
+ MissingElementsException missingElementsException = new MissingElementsException(
+ "Could not create all mandatory methods for interface of model " + modelClass);
for (MissingElementException me : missingElements) {
missingElementsException.addMissingElementExceptions(me);
}
@@ -725,7 +790,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
ModelClassConstructor<ModelType> constructorToUse = getBestMatchingConstructor(adaptable, modelClass);
if (constructorToUse == null) {
- return new Result<>(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<>(VALUE_PREPARERS_COUNT);
@@ -739,7 +805,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
// instantiate with constructor injection
// if this fails, make sure resources that may be claimed by injectors are cleared up again
try {
- Result<ModelType> result = newInstanceWithConstructorInjection(constructorToUse, adaptable, modelClass, registry, preparedValues);
+ Result<ModelType> result = newInstanceWithConstructorInjection(
+ constructorToUse, adaptable, modelClass, registry, preparedValues);
if (!result.wasSuccessful()) {
registry.onDisposed();
return result;
@@ -770,16 +837,17 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
if (!registry.callbacks.isEmpty()) {
registry.seal();
- if (adaptable instanceof SlingHttpServletRequest &&
- ((SlingHttpServletRequest) adaptable).getAttribute(REQUEST_MARKER_ATTRIBUTE) == REQUEST_MARKER_VALUE) {
+ if (adaptable instanceof SlingHttpServletRequest
+ && ((SlingHttpServletRequest) adaptable).getAttribute(REQUEST_MARKER_ATTRIBUTE)
+ == REQUEST_MARKER_VALUE) {
registerRequestCallbackRegistry((SlingHttpServletRequest) adaptable, registry);
} else {
registerCallbackRegistry(object, registry);
}
-
}
if (missingElements != null) {
- MissingElementsException missingElementsException = new MissingElementsException("Could not inject all required fields into " + modelClass.getType());
+ MissingElementsException missingElementsException =
+ new MissingElementsException("Could not inject all required fields into " + modelClass.getType());
for (MissingElementException me : missingElements) {
missingElementsException.addMissingElementExceptions(me);
}
@@ -791,9 +859,11 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
return (Result<ModelType>) Result.POST_CONSTRUCT_PREVENTED_MODEL_CONSTRUCTION;
}
} catch (InvocationTargetException e) {
- return new Result<>(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));
+ new Result<ModelType>(new ModelClassException(
+ "Could not call post-construct method for model " + modelClass.getType(), e));
}
return new Result<>(object);
}
@@ -804,7 +874,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
* @param type Model type
* @return Constructor or null if none found
*/
- private <ModelType> ModelClassConstructor<ModelType> getBestMatchingConstructor(Object adaptable, ModelClass<ModelType> type) {
+ private <ModelType> ModelClassConstructor<ModelType> getBestMatchingConstructor(
+ Object adaptable, ModelClass<ModelType> type) {
ModelClassConstructor<ModelType>[] constructors = type.getConstructors();
for (ModelClassConstructor<ModelType> constructor : constructors) {
@@ -829,8 +900,12 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
return null;
}
- private <ModelType> Result<ModelType> newInstanceWithConstructorInjection(final ModelClassConstructor<ModelType> constructor, final Object adaptable,
- final ModelClass<ModelType> modelClass, final DisposalCallbackRegistry registry, final @NotNull Map<ValuePreparer, Object> preparedValues)
+ private <ModelType> Result<ModelType> newInstanceWithConstructorInjection(
+ final ModelClassConstructor<ModelType> constructor,
+ final Object adaptable,
+ final ModelClass<ModelType> modelClass,
+ final DisposalCallbackRegistry registry,
+ final @NotNull Map<ValuePreparer, Object> preparedValues)
throws InstantiationException, InvocationTargetException, IllegalAccessException {
ConstructorParameter[] parameters = constructor.getConstructorParameters();
@@ -840,7 +915,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
final BundleContext modelContext = getModelBundleContext(modelClass);
List<MissingElementException> missingElements = null;
for (int i = 0; i < parameters.length; i++) {
- RuntimeException t = injectElement(parameters[i], adaptable, registry, callback, preparedValues, modelContext);
+ RuntimeException t =
+ injectElement(parameters[i], adaptable, registry, callback, preparedValues, modelContext);
if (t != null) {
if (missingElements == null) {
missingElements = new ArrayList<>();
@@ -849,7 +925,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
}
if (missingElements != null) {
- MissingElementsException missingElementsException = new MissingElementsException("Required constructor parameters were not able to be injected on model " + modelClass.getType());
+ MissingElementsException missingElementsException = new MissingElementsException(
+ "Required constructor parameters were not able to be injected on model " + modelClass.getType());
for (MissingElementException me : missingElements) {
missingElementsException.addMissingElementExceptions(me);
}
@@ -858,8 +935,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
return new Result<>(constructor.newInstance(paramValues.toArray(new Object[paramValues.size()])));
}
- private Result<Boolean> injectDefaultValue(InjectableElement point, InjectAnnotationProcessor processor,
- InjectCallback callback) {
+ private Result<Boolean> injectDefaultValue(
+ InjectableElement point, InjectAnnotationProcessor processor, InjectCallback callback) {
if (processor != null) {
if (processor.hasDefault()) {
RuntimeException t = callback.inject(point, processor.getDefault());
@@ -879,8 +956,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
} else {
return new Result<>(t);
}
- }
- else {
+ } else {
return new Result<>(Boolean.FALSE);
}
}
@@ -961,7 +1037,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
private boolean addMethodIfNotOverriden(List<Method> methods, Method newMethod) {
for (Method method : methods) {
if (method.getName().equals(newMethod.getName())) {
- if (Arrays.equals(method.getParameterTypes(),newMethod.getParameterTypes())) {
+ if (Arrays.equals(method.getParameterTypes(), newMethod.getParameterTypes())) {
return false;
}
}
@@ -971,7 +1047,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
@SuppressWarnings("null")
- private <ModelType> ModelType invokePostConstruct(ModelType object) throws InvocationTargetException, IllegalAccessException {
+ private <ModelType> ModelType invokePostConstruct(ModelType object)
+ throws InvocationTargetException, IllegalAccessException {
Class<?> clazz = object.getClass();
List<Method> postConstructMethods = new ArrayList<>();
while (clazz != null) {
@@ -988,7 +1065,10 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
method.setAccessible(true);
Object result = method.invoke(object);
if (result instanceof Boolean && !((Boolean) result).booleanValue()) {
- log.debug("PostConstruct method {}.{} returned false. Returning null model.", method.getDeclaringClass().getName(), method.getName());
+ log.debug(
+ "PostConstruct method {}.{} returned false. Returning null model.",
+ method.getDeclaringClass().getName(),
+ method.getName());
return null;
}
}
@@ -996,7 +1076,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
private RuntimeException setField(InjectableField injectableField, Object createdObject, Object value) {
- Result<Object> result = adaptIfNecessary(value, injectableField.getFieldType(), injectableField.getFieldGenericType());
+ Result<Object> result =
+ adaptIfNecessary(value, injectableField.getFieldType(), injectableField.getFieldGenericType());
if (result.wasSuccessful()) {
return injectableField.set(createdObject, result);
} else {
@@ -1015,17 +1096,20 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
}
- private RuntimeException setConstructorParameter(ConstructorParameter constructorParameter, List<Object> parameterValues, Object value) {
+ private RuntimeException setConstructorParameter(
+ ConstructorParameter constructorParameter, List<Object> parameterValues, Object value) {
if (constructorParameter.getParameterType() instanceof Class<?>) {
- Result<Object> result = adaptIfNecessary(value, (Class<?>) constructorParameter.getParameterType(), constructorParameter.getGenericType());
- if (result.wasSuccessful() ) {
+ Result<Object> result = adaptIfNecessary(
+ value, (Class<?>) constructorParameter.getParameterType(), constructorParameter.getGenericType());
+ if (result.wasSuccessful()) {
parameterValues.set(constructorParameter.getParameterIndex(), result.getValue());
return null;
} else {
return result.getThrowable();
}
} else {
- return new ModelClassException(String.format("Constructor parameter with index %d is not a class!", constructorParameter.getParameterIndex()));
+ return new ModelClassException(String.format(
+ "Constructor parameter with index %d is not a class!", constructorParameter.getParameterIndex()));
}
}
@@ -1035,13 +1119,14 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
if (!isAcceptableType(type, genericType, value)) {
if (genericType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) genericType;
- if (value instanceof Collection &&
- (type.equals(Collection.class) || type.equals(List.class)) &&
- parameterizedType.getActualTypeArguments().length == 1) {
+ if (value instanceof Collection
+ && (type.equals(Collection.class) || type.equals(List.class))
+ && parameterizedType.getActualTypeArguments().length == 1) {
List<Object> result = new ArrayList<>();
for (Object valueObject : (Collection<?>) value) {
- Result<Object> singleValueResult = adapt(valueObject, (Class<?>) parameterizedType.getActualTypeArguments()[0], true);
+ Result<Object> singleValueResult =
+ adapt(valueObject, (Class<?>) parameterizedType.getActualTypeArguments()[0], true);
if (singleValueResult.wasSuccessful()) {
result.add(singleValueResult.getValue());
} else {
@@ -1050,8 +1135,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
adaptedValue = result;
} else {
- return new Result<>(new ModelClassException(String.format("%s is neither a parameterized Collection or List",
- type)));
+ return new Result<>(new ModelClassException(
+ String.format("%s is neither a parameterized Collection or List", type)));
}
} else {
return adapt(value, type, false);
@@ -1078,28 +1163,33 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
adaptedValue = result.getValue();
} else {
return new Result<>(new ModelClassException(
- String.format("Could not create model from %s: %s%s", value.getClass(), result.getThrowable().getMessage(), messageSuffix),
- result.getThrowable()));
+ 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<>(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<>(adaptedValue);
} else {
- 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)));
+ 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)));
}
}
@SuppressWarnings("null")
private static boolean isAcceptableType(Class<?> type, Type genericType, Object value) {
if (type.isInstance(value)) {
- if ((type == Collection.class || type == List.class) && genericType instanceof ParameterizedType &&
- value instanceof Collection) {
+ if ((type == Collection.class || type == List.class)
+ && genericType instanceof ParameterizedType
+ && value instanceof Collection) {
Iterator<?> it = ((Collection<?>) value).iterator();
if (!it.hasNext()) {
// empty collection, so it doesn't really matter
@@ -1107,7 +1197,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
} else {
// this is not an ideal way to get the actual component type, but erasure...
Class<?> actualComponentType = it.next().getClass();
- Class<?> desiredComponentType = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
+ Class<?> desiredComponentType =
+ (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
return desiredComponentType.isAssignableFrom(actualComponentType);
}
} else {
@@ -1152,7 +1243,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
};
- this.adapterCache = Collections.synchronizedMap(new WeakHashMap<Object, Map<Class<?>, SoftReference<Object>>>());
+ this.adapterCache =
+ Collections.synchronizedMap(new WeakHashMap<Object, Map<Class<?>, SoftReference<Object>>>());
BundleContext bundleContext = ctx.getBundleContext();
this.queue = new ReferenceQueue<>();
@@ -1168,7 +1260,12 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
this.jobRegistration = bundleContext.registerService(Runnable.class, this, properties);
this.scriptEngineFactory = new SlingModelsScriptEngineFactory(bundleContext.getBundle());
- this.listener = new ModelPackageBundleListener(ctx.getBundleContext(), this, this.adapterImplementations, bindingsValuesProvidersByContext, scriptEngineFactory);
+ this.listener = new ModelPackageBundleListener(
+ ctx.getBundleContext(),
+ this,
+ this.adapterImplementations,
+ bindingsValuesProvidersByContext,
+ scriptEngineFactory);
Hashtable<String, Object> printerProps = new Hashtable<>();
printerProps.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
@@ -1177,9 +1274,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
printerProps.put("felix.webconsole.title", "Sling Models");
printerProps.put("felix.webconsole.configprinter.modes", "always");
- this.configPrinterRegistration = bundleContext.registerService(Object.class,
- new ModelConfigurationPrinter(this, bundleContext, adapterImplementations), printerProps);
-
+ this.configPrinterRegistration = bundleContext.registerService(
+ Object.class, new ModelConfigurationPrinter(this, bundleContext, adapterImplementations), printerProps);
}
@Deactivate
@@ -1204,11 +1300,11 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
}
- @Reference(cardinality = ReferenceCardinality.MULTIPLE,
- policy = ReferencePolicy.DYNAMIC)
+ @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected void bindInjector(final Injector injector, final Map<String, Object> props) {
RankedServices<Injector> newRankedServices = new RankedServices<>();
- RankedServices<Injector> injectorsPerInjectorName = injectors.putIfAbsent(injector.getName(), newRankedServices);
+ RankedServices<Injector> injectorsPerInjectorName =
+ injectors.putIfAbsent(injector.getName(), newRankedServices);
if (injectorsPerInjectorName == null) {
injectorsPerInjectorName = newRankedServices;
}
@@ -1225,40 +1321,45 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- protected void bindStaticInjectAnnotationProcessorFactory(final StaticInjectAnnotationProcessorFactory factory, final Map<String, Object> props) {
+ protected void bindStaticInjectAnnotationProcessorFactory(
+ final StaticInjectAnnotationProcessorFactory factory, final Map<String, Object> props) {
synchronized (staticInjectAnnotationProcessorFactories) {
staticInjectAnnotationProcessorFactories.bind(factory, props);
- this.adapterImplementations.setStaticInjectAnnotationProcessorFactories(staticInjectAnnotationProcessorFactories.get());
+ this.adapterImplementations.setStaticInjectAnnotationProcessorFactories(
+ staticInjectAnnotationProcessorFactories.get());
}
}
- protected void unbindStaticInjectAnnotationProcessorFactory(final StaticInjectAnnotationProcessorFactory factory, final Map<String, Object> props) {
+ protected void unbindStaticInjectAnnotationProcessorFactory(
+ final StaticInjectAnnotationProcessorFactory factory, final Map<String, Object> props) {
synchronized (staticInjectAnnotationProcessorFactories) {
staticInjectAnnotationProcessorFactories.unbind(factory, props);
- this.adapterImplementations.setStaticInjectAnnotationProcessorFactories(staticInjectAnnotationProcessorFactories.get());
+ this.adapterImplementations.setStaticInjectAnnotationProcessorFactories(
+ staticInjectAnnotationProcessorFactories.get());
}
}
- @Reference(name="implementationPicker", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- protected void bindImplementationPicker(final ImplementationPicker implementationPicker, final Map<String, Object> props) {
+ @Reference(
+ name = "implementationPicker",
+ cardinality = ReferenceCardinality.MULTIPLE,
+ policy = ReferencePolicy.DYNAMIC)
+ protected void bindImplementationPicker(
+ final ImplementationPicker implementationPicker, final Map<String, Object> props) {
synchronized (implementationPickers) {
implementationPickers.bind(implementationPicker, props);
this.adapterImplementations.setImplementationPickers(implementationPickers.get());
}
}
- protected void unbindImplementationPicker(final ImplementationPicker implementationPicker, final Map<String, Object> props) {
+ protected void unbindImplementationPicker(
+ final ImplementationPicker implementationPicker, final Map<String, Object> props) {
synchronized (implementationPickers) {
implementationPickers.unbind(implementationPicker, props);
this.adapterImplementations.setImplementationPickers(implementationPickers.get());
}
}
- @Reference(
- name = "viaProvider",
- cardinality = ReferenceCardinality.MULTIPLE,
- policy = ReferencePolicy.DYNAMIC
- )
+ @Reference(name = "viaProvider", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected void bindViaProvider(final ViaProvider viaProvider, final Map<String, Object> props) {
Class<? extends ViaProviderType> type = viaProvider.getType();
viaProviders.put(type, viaProvider);
@@ -1269,27 +1370,33 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
viaProviders.remove(type, viaProvider);
}
- @NotNull Collection<Injector> getInjectors() {
+ @NotNull
+ Collection<Injector> getInjectors() {
return sortedInjectors.get();
}
- @NotNull Collection<InjectAnnotationProcessorFactory> getInjectAnnotationProcessorFactories() {
+ @NotNull
+ Collection<InjectAnnotationProcessorFactory> getInjectAnnotationProcessorFactories() {
return injectAnnotationProcessorFactories;
}
- @NotNull Collection<InjectAnnotationProcessorFactory2> getInjectAnnotationProcessorFactories2() {
+ @NotNull
+ Collection<InjectAnnotationProcessorFactory2> getInjectAnnotationProcessorFactories2() {
return injectAnnotationProcessorFactories2;
}
- @NotNull Collection<StaticInjectAnnotationProcessorFactory> getStaticInjectAnnotationProcessorFactories() {
+ @NotNull
+ Collection<StaticInjectAnnotationProcessorFactory> getStaticInjectAnnotationProcessorFactories() {
return staticInjectAnnotationProcessorFactories.get();
}
- @NotNull ImplementationPicker[] getImplementationPickers() {
+ @NotNull
+ ImplementationPicker[] getImplementationPickers() {
return adapterImplementations.getImplementationPickers();
}
- @NotNull Map<Class<? extends ViaProviderType>, ViaProvider> getViaProviders() {
+ @NotNull
+ Map<Class<? extends ViaProviderType>, ViaProvider> getViaProviders() {
return viaProviders;
}
@@ -1307,7 +1414,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
public Object getModelFromResource(@NotNull Resource resource) {
Class<?> clazz = this.adapterImplementations.getModelClassForResource(resource);
if (clazz == null) {
- throw new ModelClassException("Could find model registered for resource type: " + resource.getResourceType());
+ throw new ModelClassException(
+ "Could find model registered for resource type: " + resource.getResourceType());
}
return handleBoundModelResult(internalCreateModel(resource, clazz));
}
@@ -1343,18 +1451,21 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
@Override
- public <T> T exportModelForResource(Resource resource, String name, Class<T> targetClass, Map<String, String> options)
+ public <T> T exportModelForResource(
+ Resource resource, String name, Class<T> targetClass, Map<String, String> options)
throws ExportException, MissingExporterException {
Class<?> clazz = this.adapterImplementations.getModelClassForResource(resource);
if (clazz == null) {
- throw new ModelClassException("Could find model registered for resource type: " + resource.getResourceType());
+ throw new ModelClassException(
+ "Could find model registered for resource type: " + resource.getResourceType());
}
Result<?> result = internalCreateModel(resource, clazz);
return handleAndExportResult(result, name, targetClass, options);
}
@Override
- public <T> T exportModelForRequest(SlingHttpServletRequest request, String name, Class<T> targetClass, Map<String, String> options)
+ public <T> T exportModelForRequest(
+ SlingHttpServletRequest request, String name, Class<T> targetClass, Map<String, String> options)
throws ExportException, MissingExporterException {
Class<?> clazz = this.adapterImplementations.getModelClassForRequest(request);
if (clazz == null) {
@@ -1364,7 +1475,9 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
return handleAndExportResult(result, name, targetClass, options);
}
- protected <T> T handleAndExportResult(Result<?> result, String name, Class<T> targetClass, Map<String, String> options) throws ExportException, MissingExporterException {
+ protected <T> T handleAndExportResult(
+ Result<?> result, String name, Class<T> targetClass, Map<String, String> options)
+ throws ExportException, MissingExporterException {
if (result.wasSuccessful()) {
return exportModel(result.getValue(), name, targetClass, options);
} else {
@@ -1373,9 +1486,11 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
@Override
- public <T> T getModelFromWrappedRequest(@NotNull SlingHttpServletRequest request, @NotNull Resource resource, @NotNull Class<T> targetClass) {
- return new ResourceOverridingRequestWrapper(request, resource, adapterManager,
- scriptEngineFactory, bindingsValuesProvidersByContext).adaptTo(targetClass);
+ public <T> T getModelFromWrappedRequest(
+ @NotNull SlingHttpServletRequest request, @NotNull Resource resource, @NotNull Class<T> targetClass) {
+ return new ResourceOverridingRequestWrapper(
+ request, resource, adapterManager, scriptEngineFactory, bindingsValuesProvidersByContext)
+ .adaptTo(targetClass);
}
@Override
@@ -1391,5 +1506,4 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
public void requestInitialized(ServletRequestEvent sre) {
sre.getServletRequest().setAttribute(REQUEST_MARKER_ATTRIBUTE, REQUEST_MARKER_VALUE);
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactoryConfiguration.java b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactoryConfiguration.java
index 9433265..86b25e1 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactoryConfiguration.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactoryConfiguration.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -21,8 +23,11 @@ import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@ObjectClassDefinition(name = "Apache Sling Model Adapter Factory")
public @interface ModelAdapterFactoryConfiguration {
- @AttributeDefinition(name="Maximum Recursion Depth", description= "Maximum depth adaptation will be attempted.")
+ @AttributeDefinition(name = "Maximum Recursion Depth", description = "Maximum depth adaptation will be attempted.")
int max_recursion_depth() default 20;
- @AttributeDefinition(name="Cleanup Job Period", description= "Period in seconds at which OSGi service references from ThreadLocals will be cleaned up.")
+
+ @AttributeDefinition(
+ name = "Cleanup Job Period",
+ description = "Period in seconds at which OSGi service references from ThreadLocals will be cleaned up.")
long cleanup_job_period() default 30l;
}
diff --git a/src/main/java/org/apache/sling/models/impl/ModelConfigurationPrinter.java b/src/main/java/org/apache/sling/models/impl/ModelConfigurationPrinter.java
index 36c95b0..3172c3f 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelConfigurationPrinter.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelConfigurationPrinter.java
@@ -1,21 +1,25 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
+import javax.servlet.Servlet;
+
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Map;
@@ -31,25 +35,27 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
-import javax.servlet.Servlet;
-
@SuppressWarnings("deprecation")
public class ModelConfigurationPrinter {
- private static final String EXPORT_SERVLET_FILTER = "(" + ModelPackageBundleListener.PROP_EXPORTER_SERVLET_CLASS + "=*)";
+ private static final String EXPORT_SERVLET_FILTER =
+ "(" + ModelPackageBundleListener.PROP_EXPORTER_SERVLET_CLASS + "=*)";
private final ModelAdapterFactory modelAdapterFactory;
private final BundleContext bundleContext;
private final AdapterImplementations adapterImplementations;
- ModelConfigurationPrinter(ModelAdapterFactory modelAdapterFactory, BundleContext bundleContext, AdapterImplementations adapterImplementations) {
+ ModelConfigurationPrinter(
+ ModelAdapterFactory modelAdapterFactory,
+ BundleContext bundleContext,
+ AdapterImplementations adapterImplementations) {
this.modelAdapterFactory = modelAdapterFactory;
this.bundleContext = bundleContext;
this.adapterImplementations = adapterImplementations;
}
public void printConfiguration(PrintWriter printWriter) {
-
+
// injectors
printWriter.println("Sling Models Injectors:");
Collection<Injector> injectors = modelAdapterFactory.getInjectors();
@@ -57,20 +63,22 @@ public class ModelConfigurationPrinter {
printWriter.println("none");
} else {
for (Injector injector : injectors) {
- printWriter.printf("%s - %s", injector.getName(), injector.getClass().getName());
+ printWriter.printf(
+ "%s - %s", injector.getName(), injector.getClass().getName());
printWriter.println();
}
}
printWriter.println();
-
+
// inject annotations processor factories
printWriter.println("Sling Models Inject Annotation Processor Factories:");
- Collection<InjectAnnotationProcessorFactory> factories = modelAdapterFactory.getInjectAnnotationProcessorFactories();
- Collection<InjectAnnotationProcessorFactory2> factories2 = modelAdapterFactory.getInjectAnnotationProcessorFactories2();
- Collection<StaticInjectAnnotationProcessorFactory> staticFactories = modelAdapterFactory.getStaticInjectAnnotationProcessorFactories();
- if ((factories.isEmpty())
- && (factories2.isEmpty())
- && (staticFactories.isEmpty())) {
+ Collection<InjectAnnotationProcessorFactory> factories =
+ modelAdapterFactory.getInjectAnnotationProcessorFactories();
+ Collection<InjectAnnotationProcessorFactory2> factories2 =
+ modelAdapterFactory.getInjectAnnotationProcessorFactories2();
+ Collection<StaticInjectAnnotationProcessorFactory> staticFactories =
+ modelAdapterFactory.getStaticInjectAnnotationProcessorFactories();
+ if ((factories.isEmpty()) && (factories2.isEmpty()) && (staticFactories.isEmpty())) {
printWriter.println("none");
} else {
for (StaticInjectAnnotationProcessorFactory factory : staticFactories) {
@@ -87,7 +95,7 @@ public class ModelConfigurationPrinter {
}
}
printWriter.println();
-
+
// implementation pickers
printWriter.println("Sling Models Implementation Pickers:");
ImplementationPicker[] pickers = modelAdapterFactory.getImplementationPickers();
@@ -109,17 +117,19 @@ public class ModelConfigurationPrinter {
printWriter.println("none");
} else {
for (Map.Entry<Class<? extends ViaProviderType>, ViaProvider> entry : viaProviders.entrySet()) {
- printWriter.printf("%s (Type: %s)", entry.getValue().getClass().getName(), entry.getKey().getName());
+ printWriter.printf(
+ "%s (Type: %s)",
+ entry.getValue().getClass().getName(), entry.getKey().getName());
printWriter.println();
}
}
-
printWriter.println();
// models bound to resource types
printWriter.println("Sling Models Bound to Resource Types *For Resources*:");
- for (Map.Entry<String, Class<?>> entry : adapterImplementations.getResourceTypeMappingsForResources().entrySet()) {
+ for (Map.Entry<String, Class<?>> entry :
+ adapterImplementations.getResourceTypeMappingsForResources().entrySet()) {
printWriter.print(entry.getValue().getName());
printWriter.print(" - ");
printWriter.println(entry.getKey());
@@ -127,7 +137,8 @@ public class ModelConfigurationPrinter {
printWriter.println();
printWriter.println("Sling Models Bound to Resource Types *For Requests*:");
- for (Map.Entry<String, Class<?>> entry : adapterImplementations.getResourceTypeMappingsForRequests().entrySet()) {
+ for (Map.Entry<String, Class<?>> entry :
+ adapterImplementations.getResourceTypeMappingsForRequests().entrySet()) {
printWriter.print(entry.getValue().getName());
printWriter.print(" - ");
printWriter.println(entry.getKey());
@@ -138,7 +149,8 @@ public class ModelConfigurationPrinter {
// registered exporter servlets
printWriter.println("Sling Models Exporter Servlets:");
try {
- ServiceReference[] servlets = bundleContext.getServiceReferences(Servlet.class.getName(), EXPORT_SERVLET_FILTER);
+ ServiceReference[] servlets =
+ bundleContext.getServiceReferences(Servlet.class.getName(), EXPORT_SERVLET_FILTER);
if (servlets != null) {
for (ServiceReference ref : servlets) {
printWriter.print(ref.getProperty(ModelPackageBundleListener.PROP_EXPORTER_SERVLET_CLASS));
@@ -157,5 +169,4 @@ public class ModelConfigurationPrinter {
// ignore
}
}
-
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java b/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
index b80377a..191b0e2 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
@@ -1,21 +1,25 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
+import javax.servlet.Servlet;
+
import java.lang.annotation.AnnotationFormatError;
import java.net.URL;
import java.util.ArrayList;
@@ -27,8 +31,6 @@ import java.util.Hashtable;
import java.util.List;
import java.util.Map;
-import javax.servlet.Servlet;
-
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
@@ -87,11 +89,12 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
private final SlingModelsScriptEngineFactory scriptEngineFactory;
- public ModelPackageBundleListener(BundleContext bundleContext,
- ModelAdapterFactory factory,
- AdapterImplementations adapterImplementations,
- BindingsValuesProvidersByContext bindingsValuesProvidersByContext,
- SlingModelsScriptEngineFactory scriptEngineFactory) {
+ public ModelPackageBundleListener(
+ BundleContext bundleContext,
+ ModelAdapterFactory factory,
+ AdapterImplementations adapterImplementations,
+ BindingsValuesProvidersByContext bindingsValuesProvidersByContext,
+ SlingModelsScriptEngineFactory scriptEngineFactory) {
this.bundleContext = bundleContext;
this.factory = factory;
this.adapterImplementations = adapterImplementations;
@@ -122,7 +125,6 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
URL url = classUrls.nextElement();
String className = toClassName(url);
analyzeClass(bundle, className, regs);
-
}
}
}
@@ -147,21 +149,23 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
// get list of adapters from annotation - if not given use annotated class itself
Class<?>[] adapterTypes = annotation.adapters();
if (adapterTypes.length == 0) {
- adapterTypes = new Class<?>[] { implType };
+ adapterTypes = new Class<?>[] {implType};
} else if (!ArrayUtils.contains(adapterTypes, implType)) {
adapterTypes = ArrayUtils.add(adapterTypes, implType);
}
// register adapter only if given adapters are valid
if (validateAdapterClasses(implType, adapterTypes)) {
if (adapterImplementations.addAll(implType, adapterTypes)) {
- ServiceRegistration reg = registerAdapterFactory(adapterTypes, annotation.adaptables(), implType, annotation.condition());
+ ServiceRegistration reg = registerAdapterFactory(
+ adapterTypes, annotation.adaptables(), implType, annotation.condition());
regs.add(reg);
String[] resourceTypes = annotation.resourceType();
for (String resourceType : resourceTypes) {
if (StringUtils.isNotEmpty(resourceType)) {
for (Class<?> adaptable : annotation.adaptables()) {
- adapterImplementations.registerModelToResourceType(bundle, resourceType, adaptable, implType);
+ adapterImplementations.registerModelToResourceType(
+ bundle, resourceType, adaptable, implType);
ExportServlet.ExportedObjectAccessor accessor = null;
if (adaptable == Resource.class) {
accessor = new ExportServlet.ResourceAccessor(implType);
@@ -170,7 +174,8 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
}
Exporter exporterAnnotation = implType.getAnnotation(Exporter.class);
if (exporterAnnotation != null) {
- registerExporter(bundle, implType, resourceType, exporterAnnotation, regs, accessor);
+ registerExporter(
+ bundle, implType, resourceType, exporterAnnotation, regs, accessor);
}
Exporters exportersAnnotation = implType.getAnnotation(Exporters.class);
if (exportersAnnotation != null) {
@@ -178,22 +183,24 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
registerExporter(bundle, implType, resourceType, ann, regs, accessor);
}
}
-
}
}
}
}
}
-
}
- } catch (ClassNotFoundException|AnnotationFormatError e) {
- log.warn("Unable to load class '{}' from bundle '{}': {}", className, bundle.getSymbolicName(), e.getLocalizedMessage(), e);
+ } catch (ClassNotFoundException | AnnotationFormatError e) {
+ log.warn(
+ "Unable to load class '{}' from bundle '{}': {}",
+ className,
+ bundle.getSymbolicName(),
+ e.getLocalizedMessage(),
+ e);
}
}
@Override
- public void modifiedBundle(Bundle bundle, BundleEvent event, ServiceRegistration[] object) {
- }
+ public void modifiedBundle(Bundle bundle, BundleEvent event, ServiceRegistration[] object) {}
@Override
public void removedBundle(Bundle bundle, BundleEvent event, ServiceRegistration[] object) {
@@ -209,7 +216,6 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
reg.unregister();
}
adapterImplementations.removeResourceTypeBindings(bundle);
-
}
public synchronized void unregisterAll() {
@@ -242,8 +248,10 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
private boolean validateAdapterClasses(Class<?> clazz, Class<?>[] adapterClasses) {
for (Class<?> adapterClass : adapterClasses) {
if (!adapterClass.isAssignableFrom(clazz)) {
- log.warn("Unable to register model class {} because adapter class {} is not valid.",
- clazz.getName(), adapterClass.getName());
+ log.warn(
+ "Unable to register model class {} because adapter class {} is not valid.",
+ clazz.getName(),
+ adapterClass.getName());
return false;
}
}
@@ -258,7 +266,8 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
* @param condition Condition (optional)
* @return Service registration
*/
- private ServiceRegistration registerAdapterFactory(Class<?>[] adapterTypes, Class<?>[] adaptableTypes, Class<?> implType, String condition) {
+ private ServiceRegistration registerAdapterFactory(
+ Class<?>[] adapterTypes, Class<?>[] adaptableTypes, Class<?> implType, String condition) {
Dictionary<String, Object> registrationProps = new Hashtable<>();
registrationProps.put(AdapterFactory.ADAPTER_CLASSES, toStringArray(adapterTypes));
registrationProps.put(AdapterFactory.ADAPTABLE_CLASSES, toStringArray(adaptableTypes));
@@ -271,13 +280,25 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
return bundleContext.registerService(AdapterFactory.SERVICE_NAME, factory, registrationProps);
}
-
- private void registerExporter(Bundle bundle, Class<?> annotatedClass, String resourceType, Exporter exporterAnnotation,
- List<ServiceRegistration> regs, ExportServlet.ExportedObjectAccessor accessor) {
+ private void registerExporter(
+ Bundle bundle,
+ Class<?> annotatedClass,
+ String resourceType,
+ Exporter exporterAnnotation,
+ List<ServiceRegistration> regs,
+ ExportServlet.ExportedObjectAccessor accessor) {
if (accessor != null) {
Map<String, String> baseOptions = getOptions(exporterAnnotation);
- ExportServlet servlet = new ExportServlet(bundle.getBundleContext(), factory, bindingsValuesProvidersByContext,
- scriptEngineFactory, annotatedClass, exporterAnnotation.selector(), exporterAnnotation.name(), accessor, baseOptions);
+ ExportServlet servlet = new ExportServlet(
+ bundle.getBundleContext(),
+ factory,
+ bindingsValuesProvidersByContext,
+ scriptEngineFactory,
+ annotatedClass,
+ exporterAnnotation.selector(),
+ exporterAnnotation.name(),
+ accessor,
+ baseOptions);
Dictionary<String, Object> registrationProps = new Hashtable<>();
registrationProps.put("sling.servlet.resourceTypes", resourceType);
registrationProps.put("sling.servlet.selectors", exporterAnnotation.selector());
@@ -285,9 +306,12 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
registrationProps.put(PROP_EXPORTER_SERVLET_CLASS, annotatedClass.getName());
registrationProps.put(PROP_EXPORTER_SERVLET_NAME, exporterAnnotation.name());
- log.debug("registering servlet for {}, {}, {}", new Object[]{resourceType, exporterAnnotation.selector(), exporterAnnotation.extensions()});
+ log.debug(
+ "registering servlet for {}, {}, {}",
+ new Object[] {resourceType, exporterAnnotation.selector(), exporterAnnotation.extensions()});
- ServiceRegistration reg = bundleContext.registerService(Servlet.class.getName(), servlet, registrationProps);
+ ServiceRegistration reg =
+ bundleContext.registerService(Servlet.class.getName(), servlet, registrationProps);
regs.add(reg);
}
}
@@ -304,5 +328,4 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
return map;
}
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java b/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
index 456b1c7..528c1f1 100644
--- a/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
+++ b/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
@@ -18,6 +18,8 @@
*/
package org.apache.sling.models.impl;
+import javax.inject.Inject;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
@@ -26,8 +28,6 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
-import javax.inject.Inject;
-
import org.apache.commons.lang3.ClassUtils;
import org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
@@ -59,7 +59,6 @@ public final class ReflectionUtil {
type = type.getSuperclass();
}
return result;
-
}
private static void addAnnotatedMethodsFromInterfaces(Class<?> type, List<Method> result) {
@@ -124,5 +123,4 @@ public final class ReflectionUtil {
return type;
}
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/ResourceOverridingRequestWrapper.java b/src/main/java/org/apache/sling/models/impl/ResourceOverridingRequestWrapper.java
index c37e588..18b19c6 100644
--- a/src/main/java/org/apache/sling/models/impl/ResourceOverridingRequestWrapper.java
+++ b/src/main/java/org/apache/sling/models/impl/ResourceOverridingRequestWrapper.java
@@ -1,29 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.apache.sling.api.scripting.SlingBindings.LOG;
-import static org.apache.sling.api.scripting.SlingBindings.OUT;
-import static org.apache.sling.api.scripting.SlingBindings.READER;
-import static org.apache.sling.api.scripting.SlingBindings.REQUEST;
-import static org.apache.sling.api.scripting.SlingBindings.RESOURCE;
-import static org.apache.sling.api.scripting.SlingBindings.RESPONSE;
-import static org.apache.sling.api.scripting.SlingBindings.SLING;
-
import javax.script.Bindings;
import org.apache.sling.api.SlingHttpServletRequest;
@@ -33,6 +27,14 @@ import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;
import org.apache.sling.scripting.api.BindingsValuesProvidersByContext;
+import static org.apache.sling.api.scripting.SlingBindings.LOG;
+import static org.apache.sling.api.scripting.SlingBindings.OUT;
+import static org.apache.sling.api.scripting.SlingBindings.READER;
+import static org.apache.sling.api.scripting.SlingBindings.REQUEST;
+import static org.apache.sling.api.scripting.SlingBindings.RESOURCE;
+import static org.apache.sling.api.scripting.SlingBindings.RESPONSE;
+import static org.apache.sling.api.scripting.SlingBindings.SLING;
+
/**
* This request wrapper allows to adapt the given resource and request to a Sling Model
*/
@@ -42,9 +44,12 @@ class ResourceOverridingRequestWrapper extends SlingHttpServletRequestWrapper {
private final AdapterManager adapterManager;
private final Bindings bindings;
- ResourceOverridingRequestWrapper(SlingHttpServletRequest wrappedRequest, Resource resource,
- AdapterManager adapterManager, SlingModelsScriptEngineFactory scriptEngineFactory,
- BindingsValuesProvidersByContext bindingsValuesProvidersByContext) {
+ ResourceOverridingRequestWrapper(
+ SlingHttpServletRequest wrappedRequest,
+ Resource resource,
+ AdapterManager adapterManager,
+ SlingModelsScriptEngineFactory scriptEngineFactory,
+ BindingsValuesProvidersByContext bindingsValuesProvidersByContext) {
super(wrappedRequest);
this.resource = resource;
this.adapterManager = adapterManager;
@@ -74,6 +79,7 @@ class ResourceOverridingRequestWrapper extends SlingHttpServletRequestWrapper {
return super.getAttribute(name);
}
}
+
@Override
public Resource getResource() {
return resource;
@@ -83,4 +89,4 @@ class ResourceOverridingRequestWrapper extends SlingHttpServletRequestWrapper {
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
return adapterManager.getAdapter(this, type);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/models/impl/ResourceTypeBasedResourcePicker.java b/src/main/java/org/apache/sling/models/impl/ResourceTypeBasedResourcePicker.java
index 00df685..5a97c72 100644
--- a/src/main/java/org/apache/sling/models/impl/ResourceTypeBasedResourcePicker.java
+++ b/src/main/java/org/apache/sling/models/impl/ResourceTypeBasedResourcePicker.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -27,11 +29,12 @@ import org.jetbrains.annotations.NotNull;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
-@Component(property=Constants.SERVICE_RANKING+":Integer=0") // this must come before FirstImplementationPicker
+@Component(property = Constants.SERVICE_RANKING + ":Integer=0") // this must come before FirstImplementationPicker
public class ResourceTypeBasedResourcePicker implements ImplementationPicker {
@Override
- public Class<?> pick(@NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
+ public Class<?> pick(
+ @NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
final Resource resource = findResource(adaptable);
if (resource == null) {
return null;
@@ -68,5 +71,4 @@ public class ResourceTypeBasedResourcePicker implements ImplementationPicker {
}
return retval;
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/Result.java b/src/main/java/org/apache/sling/models/impl/Result.java
index df9612c..cba2573 100644
--- a/src/main/java/org/apache/sling/models/impl/Result.java
+++ b/src/main/java/org/apache/sling/models/impl/Result.java
@@ -89,13 +89,13 @@ public class Result<SuccessObjectType> {
return object != null;
}
- public static final Result<Object> POST_CONSTRUCT_PREVENTED_MODEL_CONSTRUCTION = new Result<Object>((RuntimeException)null) {
+ public static final Result<Object> POST_CONSTRUCT_PREVENTED_MODEL_CONSTRUCTION =
+ new Result<Object>((RuntimeException) null) {
- @Override
- public @NotNull RuntimeException getThrowable() {
- // generate exception lazily
- return new PostConstructException("PostConstruct method returned false", null);
- }
-
- };
+ @Override
+ public @NotNull RuntimeException getThrowable() {
+ // generate exception lazily
+ return new PostConstructException("PostConstruct method returned false", null);
+ }
+ };
}
diff --git a/src/main/java/org/apache/sling/models/impl/SlingModelsScriptEngineFactory.java b/src/main/java/org/apache/sling/models/impl/SlingModelsScriptEngineFactory.java
index bd6d40d..35c52a8 100644
--- a/src/main/java/org/apache/sling/models/impl/SlingModelsScriptEngineFactory.java
+++ b/src/main/java/org/apache/sling/models/impl/SlingModelsScriptEngineFactory.java
@@ -1,28 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
-import org.apache.sling.scripting.api.BindingsValuesProvider;
-import org.apache.sling.scripting.api.BindingsValuesProvidersByContext;
-import org.apache.sling.scripting.core.impl.helper.ProtectedBindings;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-
import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
@@ -32,6 +27,13 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
+import org.apache.sling.scripting.api.BindingsValuesProvider;
+import org.apache.sling.scripting.api.BindingsValuesProvidersByContext;
+import org.apache.sling.scripting.core.impl.helper.ProtectedBindings;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+
import static org.apache.sling.api.scripting.SlingBindings.*;
/**
@@ -53,7 +55,9 @@ class SlingModelsScriptEngineFactory extends AbstractScriptEngineFactory impleme
super();
setEngineName("Apache Sling Models");
// really the only time this is null is during testing
- if (bundle != null && bundle.getHeaders() != null && bundle.getHeaders().get(Constants.BUNDLE_VERSION) != null) {
+ if (bundle != null
+ && bundle.getHeaders() != null
+ && bundle.getHeaders().get(Constants.BUNDLE_VERSION) != null) {
setEngineVersion(bundle.getHeaders().get(Constants.BUNDLE_VERSION).toString());
}
setNames("sling-models-exporter", "sling-models");
@@ -74,9 +78,11 @@ class SlingModelsScriptEngineFactory extends AbstractScriptEngineFactory impleme
return null;
}
- void invokeBindingsValuesProviders(BindingsValuesProvidersByContext bindingsValuesProvidersByContext, Bindings bindings) {
+ void invokeBindingsValuesProviders(
+ BindingsValuesProvidersByContext bindingsValuesProvidersByContext, Bindings bindings) {
final Collection<BindingsValuesProvider> bindingsValuesProviders =
- bindingsValuesProvidersByContext.getBindingsValuesProviders(this, SlingModelsScriptEngineFactory.BINDINGS_CONTEXT);
+ bindingsValuesProvidersByContext.getBindingsValuesProviders(
+ this, SlingModelsScriptEngineFactory.BINDINGS_CONTEXT);
if (!bindingsValuesProviders.isEmpty()) {
Set<String> protectedKeys = new HashSet<String>();
@@ -86,7 +92,6 @@ class SlingModelsScriptEngineFactory extends AbstractScriptEngineFactory impleme
for (BindingsValuesProvider provider : bindingsValuesProviders) {
provider.addBindings(protectedBindings);
}
-
}
}
}
diff --git a/src/main/java/org/apache/sling/models/impl/ThreadInvocationCounter.java b/src/main/java/org/apache/sling/models/impl/ThreadInvocationCounter.java
index b386aa5..e10fe0e 100644
--- a/src/main/java/org/apache/sling/models/impl/ThreadInvocationCounter.java
+++ b/src/main/java/org/apache/sling/models/impl/ThreadInvocationCounter.java
@@ -39,4 +39,4 @@ class ThreadInvocationCounter {
public void decrease() {
this.count--;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/AbstractInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/AbstractInjector.java
index b1d37c3..f653bb0 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/AbstractInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/AbstractInjector.java
@@ -60,7 +60,7 @@ abstract class AbstractInjector {
if (adaptable instanceof ValueMap) {
return (ValueMap) adaptable;
} else if (adaptable instanceof SlingHttpServletRequest) {
- final Resource resource = ((SlingHttpServletRequest)adaptable).getResource();
+ final Resource resource = ((SlingHttpServletRequest) adaptable).getResource();
// resource may be null for mocked adaptables, therefore do a check here
if (resource != null) {
return resource.adaptTo(ValueMap.class);
@@ -79,10 +79,8 @@ abstract class AbstractInjector {
if (declaredType instanceof ParameterizedType) {
ParameterizedType type = (ParameterizedType) declaredType;
Class<?> collectionType = (Class<?>) type.getRawType();
- isCollection = collectionType.equals(Collection.class)
- || collectionType.equals(List.class);
+ isCollection = collectionType.equals(Collection.class) || collectionType.equals(List.class);
}
return isCollection;
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/BindingsInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/BindingsInjector.java
index 1fd5495..5cae97b 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/BindingsInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/BindingsInjector.java
@@ -1,26 +1,28 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.injectors;
+import javax.servlet.ServletRequest;
+
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Type;
-import javax.servlet.ServletRequest;
-
import org.apache.commons.lang3.ObjectUtils;
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
@@ -35,7 +37,9 @@ import org.jetbrains.annotations.NotNull;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
-@Component(property=Constants.SERVICE_RANKING+":Integer=1000", service={Injector.class, StaticInjectAnnotationProcessorFactory.class, ValuePreparer.class})
+@Component(
+ property = Constants.SERVICE_RANKING + ":Integer=1000",
+ service = {Injector.class, StaticInjectAnnotationProcessorFactory.class, ValuePreparer.class})
public class BindingsInjector implements Injector, StaticInjectAnnotationProcessorFactory, ValuePreparer {
@Override
@@ -44,7 +48,11 @@ public class BindingsInjector implements Injector, StaticInjectAnnotationProcess
}
@Override
- public Object getValue(@NotNull Object adaptable, String name, @NotNull Type type, @NotNull AnnotatedElement element,
+ public Object getValue(
+ @NotNull Object adaptable,
+ String name,
+ @NotNull Type type,
+ @NotNull AnnotatedElement element,
@NotNull DisposalCallbackRegistry callbackRegistry) {
if (adaptable == ObjectUtils.NULL) {
return null;
@@ -113,5 +121,4 @@ public class BindingsInjector implements Injector, StaticInjectAnnotationProcess
return annotation.name();
}
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java
index b32cf7e..e4e4585 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.injectors;
@@ -37,7 +39,9 @@ import org.jetbrains.annotations.NotNull;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
-@Component(property=Constants.SERVICE_RANKING+":Integer=3000", service={Injector.class, InjectAnnotationProcessorFactory2.class})
+@Component(
+ property = Constants.SERVICE_RANKING + ":Integer=3000",
+ service = {Injector.class, InjectAnnotationProcessorFactory2.class})
public class ChildResourceInjector extends AbstractInjector implements Injector, InjectAnnotationProcessorFactory2 {
@Override
@@ -46,7 +50,11 @@ public class ChildResourceInjector extends AbstractInjector implements Injector,
}
@Override
- public Object getValue(@NotNull Object adaptable, String name, @NotNull Type declaredType, @NotNull AnnotatedElement element,
+ public Object getValue(
+ @NotNull Object adaptable,
+ String name,
+ @NotNull Type declaredType,
+ @NotNull AnnotatedElement element,
@NotNull DisposalCallbackRegistry callbackRegistry) {
if (adaptable instanceof Resource) {
Resource child = ((Resource) adaptable).getChild(name);
@@ -68,25 +76,24 @@ public class ChildResourceInjector extends AbstractInjector implements Injector,
}
private Object getResultList(Resource resource, Type declaredType) {
- List<Resource> result = new ArrayList<>();
- Class<?> type = getActualType((ParameterizedType) declaredType);
- if (type != null && resource != null) {
- Iterator<Resource> children = resource.listChildren();
- while (children.hasNext()) {
- result.add(children.next());
- }
- }
- return result;
- }
-
- private Class<?> getActualType(ParameterizedType declaredType) {
- Type[] types = declaredType.getActualTypeArguments();
- if (types != null && types.length > 0) {
- return (Class<?>) types[0];
- }
- return null;
- }
+ List<Resource> result = new ArrayList<>();
+ Class<?> type = getActualType((ParameterizedType) declaredType);
+ if (type != null && resource != null) {
+ Iterator<Resource> children = resource.listChildren();
+ while (children.hasNext()) {
+ result.add(children.next());
+ }
+ }
+ return result;
+ }
+ private Class<?> getActualType(ParameterizedType declaredType) {
+ Type[] types = declaredType.getActualTypeArguments();
+ if (types != null && types.length > 0) {
+ return (Class<?>) types[0];
+ }
+ return null;
+ }
@Override
@SuppressWarnings("unused")
@@ -143,5 +150,4 @@ public class ChildResourceInjector extends AbstractInjector implements Injector,
}
}
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
index 086982c..f2c3acf 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.injectors;
@@ -48,7 +50,9 @@ import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Component(property=Constants.SERVICE_RANKING+":Integer=5000", service={Injector.class, StaticInjectAnnotationProcessorFactory.class, AcceptsNullName.class})
+@Component(
+ property = Constants.SERVICE_RANKING + ":Integer=5000",
+ service = {Injector.class, StaticInjectAnnotationProcessorFactory.class, AcceptsNullName.class})
public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProcessorFactory, AcceptsNullName {
private static final Logger log = LoggerFactory.getLogger(OSGiServiceInjector.class);
@@ -66,7 +70,11 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
}
@Override
- public Object getValue(@NotNull Object adaptable, String name, @NotNull Type type, @NotNull AnnotatedElement element,
+ public Object getValue(
+ @NotNull Object adaptable,
+ String name,
+ @NotNull Type type,
+ @NotNull AnnotatedElement element,
@NotNull DisposalCallbackRegistry callbackRegistry) {
return getValue(adaptable, name, type, element, callbackRegistry, bundleContext);
}
@@ -80,9 +88,14 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
* @param modelContext Model context
* @return Object
*/
- @SuppressWarnings({ "null", "unused" })
- public Object getValue(@NotNull Object adaptable, String name, @NotNull Type type, @NotNull AnnotatedElement element,
- @NotNull DisposalCallbackRegistry callbackRegistry, @Nullable BundleContext modelContext) {
+ @SuppressWarnings({"null", "unused"})
+ public Object getValue(
+ @NotNull Object adaptable,
+ String name,
+ @NotNull Type type,
+ @NotNull AnnotatedElement element,
+ @NotNull DisposalCallbackRegistry callbackRegistry,
+ @Nullable BundleContext modelContext) {
OSGiService annotation = element.getAnnotation(OSGiService.class);
String filterString = null;
if (annotation != null) {
@@ -95,21 +108,27 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
filterString = filter.value();
}
}
- return getValue(adaptable, type, filterString, callbackRegistry, modelContext == null ? bundleContext : modelContext);
+ return getValue(
+ adaptable, type, filterString, callbackRegistry, modelContext == null ? bundleContext : modelContext);
}
- private <T> Object getService(Object adaptable, Class<T> type, String filter,
- DisposalCallbackRegistry callbackRegistry, BundleContext modelContext) {
- // cannot use SlingScriptHelper since it does not support ordering by service ranking due to https://issues.apache.org/jira/browse/SLING-5665
+ private <T> Object getService(
+ Object adaptable,
+ Class<T> type,
+ String filter,
+ DisposalCallbackRegistry callbackRegistry,
+ BundleContext modelContext) {
+ // cannot use SlingScriptHelper since it does not support ordering by service ranking due to
+ // https://issues.apache.org/jira/browse/SLING-5665
try {
ServiceReference<?>[] refs = modelContext.getServiceReferences(type.getName(), filter);
if (refs != null && refs.length > 0) {
// sort by reverse service ranking (highest first) (see ServiceReference.compareTo)
List<ServiceReference<?>> references = Arrays.asList(refs);
Collections.sort(references, Collections.reverseOrder());
- for(final ServiceReference<?> ref : references) {
+ for (final ServiceReference<?> ref : references) {
final Object obj = modelContext.getService(ref);
- if ( obj != null ) {
+ if (obj != null) {
callbackRegistry.addDisposalCallback(new Callback(new ServiceReference[] {ref}, modelContext));
return obj;
}
@@ -121,9 +140,14 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
return null;
}
- private <T> Object[] getServices(Object adaptable, Class<T> type, String filter,
- DisposalCallbackRegistry callbackRegistry, BundleContext modelContext) {
- // cannot use SlingScriptHelper since it does not support ordering by service ranking due to https://issues.apache.org/jira/browse/SLING-5665
+ private <T> Object[] getServices(
+ Object adaptable,
+ Class<T> type,
+ String filter,
+ DisposalCallbackRegistry callbackRegistry,
+ BundleContext modelContext) {
+ // cannot use SlingScriptHelper since it does not support ordering by service ranking due to
+ // https://issues.apache.org/jira/browse/SLING-5665
try {
ServiceReference<?>[] refs = modelContext.getServiceReferences(type.getName(), filter);
if (refs != null && refs.length > 0) {
@@ -139,8 +163,9 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
usedRefs.add(ref);
}
}
- if ( !services.isEmpty() ) {
- callbackRegistry.addDisposalCallback(new Callback(usedRefs.toArray(new ServiceReference[usedRefs.size()]), modelContext));
+ if (!services.isEmpty()) {
+ callbackRegistry.addDisposalCallback(
+ new Callback(usedRefs.toArray(new ServiceReference[usedRefs.size()]), modelContext));
return services.toArray(new Object[services.size()]);
}
}
@@ -150,13 +175,17 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
return null;
}
- private Object getValue(Object adaptable, Type type, String filterString, DisposalCallbackRegistry callbackRegistry,
- BundleContext modelContext) {
+ private Object getValue(
+ Object adaptable,
+ Type type,
+ String filterString,
+ DisposalCallbackRegistry callbackRegistry,
+ BundleContext modelContext) {
if (type instanceof Class) {
Class<?> injectedClass = (Class<?>) type;
if (injectedClass.isArray()) {
- Object[] services = getServices(adaptable, injectedClass.getComponentType(), filterString,
- callbackRegistry, modelContext);
+ Object[] services = getServices(
+ adaptable, injectedClass.getComponentType(), filterString, callbackRegistry, modelContext);
if (services == null) {
return null;
}
@@ -214,7 +243,7 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
}
@Override
- @SuppressWarnings({ "unused", "null" })
+ @SuppressWarnings({"unused", "null"})
public InjectAnnotationProcessor2 createAnnotationProcessor(AnnotatedElement element) {
// check if the element has the expected annotation
OSGiService annotation = element.getAnnotation(OSGiService.class);
@@ -243,6 +272,4 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
return annotation.optional();
}
}
-
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/RequestAttributeInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/RequestAttributeInjector.java
index 9df6b37..35d9e97 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/RequestAttributeInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/RequestAttributeInjector.java
@@ -1,26 +1,28 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.injectors;
+import javax.servlet.ServletRequest;
+
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Type;
-import javax.servlet.ServletRequest;
-
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.RequestAttribute;
import org.apache.sling.models.spi.DisposalCallbackRegistry;
@@ -32,7 +34,9 @@ import org.jetbrains.annotations.NotNull;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
-@Component(property=Constants.SERVICE_RANKING+":Integer=4000", service={Injector.class, StaticInjectAnnotationProcessorFactory.class})
+@Component(
+ property = Constants.SERVICE_RANKING + ":Integer=4000",
+ service = {Injector.class, StaticInjectAnnotationProcessorFactory.class})
public class RequestAttributeInjector implements Injector, StaticInjectAnnotationProcessorFactory {
@Override
@@ -41,7 +45,11 @@ public class RequestAttributeInjector implements Injector, StaticInjectAnnotatio
}
@Override
- public Object getValue(@NotNull Object adaptable, String name, @NotNull Type declaredType, @NotNull AnnotatedElement element,
+ public Object getValue(
+ @NotNull Object adaptable,
+ String name,
+ @NotNull Type declaredType,
+ @NotNull AnnotatedElement element,
@NotNull DisposalCallbackRegistry callbackRegistry) {
if (!(adaptable instanceof ServletRequest)) {
return null;
@@ -51,7 +59,7 @@ public class RequestAttributeInjector implements Injector, StaticInjectAnnotatio
}
@Override
- @SuppressWarnings({ "unused", "null" })
+ @SuppressWarnings({"unused", "null"})
public InjectAnnotationProcessor2 createAnnotationProcessor(AnnotatedElement element) {
// check if the element has the expected annotation
RequestAttribute annotation = element.getAnnotation(RequestAttribute.class);
@@ -90,6 +98,4 @@ public class RequestAttributeInjector implements Injector, StaticInjectAnnotatio
return annotation.name();
}
}
-
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/ResourcePathInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/ResourcePathInjector.java
index f49a1d7..fc65281 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/ResourcePathInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/ResourcePathInjector.java
@@ -43,9 +43,11 @@ import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Component(property=Constants.SERVICE_RANKING+":Integer=2500", service={Injector.class, StaticInjectAnnotationProcessorFactory.class, AcceptsNullName.class})
-public class ResourcePathInjector extends AbstractInjector implements Injector, AcceptsNullName,
- StaticInjectAnnotationProcessorFactory {
+@Component(
+ property = Constants.SERVICE_RANKING + ":Integer=2500",
+ service = {Injector.class, StaticInjectAnnotationProcessorFactory.class, AcceptsNullName.class})
+public class ResourcePathInjector extends AbstractInjector
+ implements Injector, AcceptsNullName, StaticInjectAnnotationProcessorFactory {
private static final Logger LOG = LoggerFactory.getLogger(ResourcePathInjector.class);
@@ -55,8 +57,12 @@ public class ResourcePathInjector extends AbstractInjector implements Injector,
}
@Override
- @SuppressWarnings({ "unused", "null" })
- public Object getValue(@NotNull Object adaptable, String name, @NotNull Type declaredType, @NotNull AnnotatedElement element,
+ @SuppressWarnings({"unused", "null"})
+ public Object getValue(
+ @NotNull Object adaptable,
+ String name,
+ @NotNull Type declaredType,
+ @NotNull AnnotatedElement element,
@NotNull DisposalCallbackRegistry callbackRegistry) {
String[] resourcePaths = null;
Path pathAnnotation = element.getAnnotation(Path.class);
@@ -91,17 +97,17 @@ public class ResourcePathInjector extends AbstractInjector implements Injector,
// unwrap/wrap if necessary
if (isDeclaredTypeCollection(declaredType)) {
return resources;
- } if (declaredType instanceof Class<?> && ((Class<?>)declaredType).isArray()){
+ }
+ if (declaredType instanceof Class<?> && ((Class<?>) declaredType).isArray()) {
return resources.toArray(new Resource[0]);
}
- if (resources.size() == 1) {
+ if (resources.size() == 1) {
return resources.get(0);
} else {
// multiple resources to inject, but field is not a list
LOG.warn("Cannot inject multiple resources into field {} since it is not declared as a list", name);
return null;
}
-
}
private List<Resource> getResources(ResourceResolver resolver, String[] paths, String fieldName) {
@@ -111,8 +117,10 @@ public class ResourcePathInjector extends AbstractInjector implements Injector,
if (resource != null) {
resources.add(resource);
} else {
- LOG.warn("Could not retrieve resource at path {} for field {}. Since it is required it won't be injected.",
- path, fieldName);
+ LOG.warn(
+ "Could not retrieve resource at path {} for field {}. Since it is required it won't be injected.",
+ path,
+ fieldName);
// all resources should've been injected. we stop
return null;
}
@@ -128,7 +136,7 @@ public class ResourcePathInjector extends AbstractInjector implements Injector,
private String[] getPathsFromAnnotation(Path pathAnnotation) {
String[] resourcePaths = null;
if (StringUtils.isNotEmpty(pathAnnotation.value())) {
- resourcePaths = new String[] { pathAnnotation.value() };
+ resourcePaths = new String[] {pathAnnotation.value()};
} else {
resourcePaths = pathAnnotation.paths();
}
@@ -143,7 +151,7 @@ public class ResourcePathInjector extends AbstractInjector implements Injector,
private String[] getPathsFromAnnotation(ResourcePath resourcePathAnnotation) {
String[] resourcePaths = null;
if (StringUtils.isNotEmpty(resourcePathAnnotation.path())) {
- resourcePaths = new String[] { resourcePathAnnotation.path() };
+ resourcePaths = new String[] {resourcePathAnnotation.path()};
} else {
resourcePaths = resourcePathAnnotation.paths();
}
@@ -151,7 +159,7 @@ public class ResourcePathInjector extends AbstractInjector implements Injector,
}
@Override
- @SuppressWarnings({ "unused", "null" })
+ @SuppressWarnings({"unused", "null"})
public InjectAnnotationProcessor2 createAnnotationProcessor(AnnotatedElement element) {
// check if the element has the expected annotation
ResourcePath annotation = element.getAnnotation(ResourcePath.class);
@@ -190,5 +198,4 @@ public class ResourcePathInjector extends AbstractInjector implements Injector,
return annotation.injectionStrategy();
}
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java
index d59192f..33c2708 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.injectors;
@@ -35,7 +37,9 @@ import org.osgi.service.component.annotations.Component;
/**
* Injects the adaptable object itself.
*/
-@Component(property=Constants.SERVICE_RANKING+":Integer="+Integer.MAX_VALUE, service={Injector.class, StaticInjectAnnotationProcessorFactory.class, AcceptsNullName.class})
+@Component(
+ property = Constants.SERVICE_RANKING + ":Integer=" + Integer.MAX_VALUE,
+ service = {Injector.class, StaticInjectAnnotationProcessorFactory.class, AcceptsNullName.class})
public class SelfInjector implements Injector, StaticInjectAnnotationProcessorFactory, AcceptsNullName {
@Override
@@ -43,7 +47,11 @@ public class SelfInjector implements Injector, StaticInjectAnnotationProcessorFa
return "self";
}
- public Object getValue(@NotNull Object adaptable, String name, @NotNull Type type, @NotNull AnnotatedElement element,
+ public Object getValue(
+ @NotNull Object adaptable,
+ String name,
+ @NotNull Type type,
+ @NotNull AnnotatedElement element,
@NotNull DisposalCallbackRegistry callbackRegistry) {
// if the @Self annotation is present return the adaptable to be inserted directly or to be adapted from
if (element.isAnnotationPresent(Self.class)) {
@@ -51,10 +59,10 @@ public class SelfInjector implements Injector, StaticInjectAnnotationProcessorFa
} else {
// special handling for the first constructor parameter
// apply class-based injection only if class matches or is a superclass
- if (element instanceof ConstructorParameter.FakeAnnotatedElement &&
- ((ConstructorParameter.FakeAnnotatedElement)element).getParameterIndex() == 0 &&
- type instanceof Class<?> &&
- ((Class<?>)type).isAssignableFrom(adaptable.getClass())) {
+ if (element instanceof ConstructorParameter.FakeAnnotatedElement
+ && ((ConstructorParameter.FakeAnnotatedElement) element).getParameterIndex() == 0
+ && type instanceof Class<?>
+ && ((Class<?>) type).isAssignableFrom(adaptable.getClass())) {
return adaptable;
}
}
@@ -62,7 +70,7 @@ public class SelfInjector implements Injector, StaticInjectAnnotationProcessorFa
}
@Override
- @SuppressWarnings({ "unused", "null" })
+ @SuppressWarnings({"unused", "null"})
public InjectAnnotationProcessor2 createAnnotationProcessor(AnnotatedElement element) {
// check if the element has the expected annotation
Self annotation = element.getAnnotation(Self.class);
@@ -91,5 +99,4 @@ public class SelfInjector implements Injector, StaticInjectAnnotationProcessorFa
return annotation.optional();
}
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/SlingObjectInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/SlingObjectInjector.java
index f582ad8..dbd59b4 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/SlingObjectInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/SlingObjectInjector.java
@@ -1,27 +1,29 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.injectors;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Type;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Type;
+
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
@@ -45,7 +47,9 @@ import org.osgi.service.component.annotations.Component;
* Resource.
* Documentation see {@link SlingObject}.
*/
-@Component(property=Constants.SERVICE_RANKING+":Integer="+Integer.MAX_VALUE, service={Injector.class, StaticInjectAnnotationProcessorFactory.class, AcceptsNullName.class})
+@Component(
+ property = Constants.SERVICE_RANKING + ":Integer=" + Integer.MAX_VALUE,
+ service = {Injector.class, StaticInjectAnnotationProcessorFactory.class, AcceptsNullName.class})
public final class SlingObjectInjector implements Injector, StaticInjectAnnotationProcessorFactory, AcceptsNullName {
/**
@@ -59,7 +63,11 @@ public final class SlingObjectInjector implements Injector, StaticInjectAnnotati
}
@Override
- public Object getValue(final @NotNull Object adaptable, final String name, final @NotNull Type type, final @NotNull AnnotatedElement element,
+ public Object getValue(
+ final @NotNull Object adaptable,
+ final String name,
+ final @NotNull Type type,
+ final @NotNull AnnotatedElement element,
final @NotNull DisposalCallbackRegistry callbackRegistry) {
// only class types are supported
@@ -77,7 +85,8 @@ public final class SlingObjectInjector implements Injector, StaticInjectAnnotati
if (requestedClass.equals(Resource.class) && element.isAnnotationPresent(SlingObject.class)) {
return request.getResource();
}
- if (requestedClass.equals(SlingHttpServletRequest.class) || requestedClass.equals(HttpServletRequest.class)) {
+ if (requestedClass.equals(SlingHttpServletRequest.class)
+ || requestedClass.equals(HttpServletRequest.class)) {
return request;
}
if (requestedClass.equals(SlingHttpServletResponse.class)
@@ -122,7 +131,7 @@ public final class SlingObjectInjector implements Injector, StaticInjectAnnotati
}
@Override
- @SuppressWarnings({ "unused", "null" })
+ @SuppressWarnings({"unused", "null"})
public InjectAnnotationProcessor2 createAnnotationProcessor(final AnnotatedElement element) {
// check if the element has the expected annotation
SlingObject annotation = element.getAnnotation(SlingObject.class);
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
index 1a36844..e70e6a7 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.injectors;
@@ -42,9 +44,12 @@ import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Component(property=Constants.SERVICE_RANKING+":Integer=2000", service={Injector.class, InjectAnnotationProcessorFactory.class, ValuePreparer.class})
+@Component(
+ property = Constants.SERVICE_RANKING + ":Integer=2000",
+ service = {Injector.class, InjectAnnotationProcessorFactory.class, ValuePreparer.class})
@SuppressWarnings("deprecation")
-public class ValueMapInjector extends AbstractInjector implements Injector, InjectAnnotationProcessorFactory, ValuePreparer {
+public class ValueMapInjector extends AbstractInjector
+ implements Injector, InjectAnnotationProcessorFactory, ValuePreparer {
private static final Logger log = LoggerFactory.getLogger(ValueMapInjector.class);
@@ -54,8 +59,12 @@ public class ValueMapInjector extends AbstractInjector implements Injector, Inje
}
@Override
- @SuppressWarnings({ "unused", "null" })
- public Object getValue(@NotNull Object adaptable, String name, @NotNull Type type, @NotNull AnnotatedElement element,
+ @SuppressWarnings({"unused", "null"})
+ public Object getValue(
+ @NotNull Object adaptable,
+ String name,
+ @NotNull Type type,
+ @NotNull AnnotatedElement element,
@NotNull DisposalCallbackRegistry callbackRegistry) {
if (adaptable == ObjectUtils.NULL) {
return null;
@@ -74,7 +83,8 @@ public class ValueMapInjector extends AbstractInjector implements Injector, Inje
if (componentType.isPrimitive()) {
Class<?> wrapper = ClassUtils.primitiveToWrapper(componentType);
if (wrapper != componentType) {
- Object wrapperArray = map.get(name, Array.newInstance(wrapper, 0).getClass());
+ Object wrapperArray =
+ map.get(name, Array.newInstance(wrapper, 0).getClass());
if (wrapperArray != null) {
return unwrapArray(wrapperArray, componentType);
}
@@ -82,7 +92,8 @@ public class ValueMapInjector extends AbstractInjector implements Injector, Inje
} else {
Class<?> primitiveType = ClassUtils.wrapperToPrimitive(componentType);
if (primitiveType != componentType) {
- Object primitiveArray = map.get(name, Array.newInstance(primitiveType, 0).getClass());
+ Object primitiveArray = map.get(
+ name, Array.newInstance(primitiveType, 0).getClass());
if (primitiveArray != null) {
return wrapArray(primitiveArray, componentType);
}
@@ -106,7 +117,6 @@ public class ValueMapInjector extends AbstractInjector implements Injector, Inje
Object array = map.get(name, Array.newInstance(itemType, 0).getClass());
if (array == null) {
return null;
-
}
return Arrays.asList((Object[]) array);
@@ -141,7 +151,7 @@ public class ValueMapInjector extends AbstractInjector implements Injector, Inje
}
@Override
- @SuppressWarnings({ "unused", "null" })
+ @SuppressWarnings({"unused", "null"})
public InjectAnnotationProcessor createAnnotationProcessor(Object adaptable, AnnotatedElement element) {
// check if the element has the expected annotation
ValueMapValue annotation = element.getAnnotation(ValueMapValue.class);
diff --git a/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java b/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
index 1ed8b53..21dbe5a 100644
--- a/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
+++ b/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
@@ -18,6 +18,8 @@
*/
package org.apache.sling.models.impl.model;
+import javax.inject.Named;
+
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Array;
import java.lang.reflect.ParameterizedType;
@@ -26,8 +28,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import javax.inject.Named;
-
import org.apache.commons.lang3.ArrayUtils;
import org.apache.sling.models.annotations.Default;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
@@ -63,8 +63,12 @@ abstract class AbstractInjectableElement implements InjectableElement {
private static final Logger log = LoggerFactory.getLogger(ModelAdapterFactory.class);
- public AbstractInjectableElement(AnnotatedElement element, Type type, String defaultName,
- StaticInjectAnnotationProcessorFactory[] processorFactories, DefaultInjectionStrategy defaultInjectionStrategy) {
+ public AbstractInjectableElement(
+ AnnotatedElement element,
+ Type type,
+ String defaultName,
+ StaticInjectAnnotationProcessorFactory[] processorFactories,
+ DefaultInjectionStrategy defaultInjectionStrategy) {
this.element = element;
this.type = type;
InjectAnnotationProcessor2 annotationProcessor = getAnnotationProcessor(element, processorFactories);
@@ -79,7 +83,8 @@ abstract class AbstractInjectableElement implements InjectableElement {
this.defaultInjectionStrategy = defaultInjectionStrategy;
}
- private static InjectAnnotationProcessor2 getAnnotationProcessor(AnnotatedElement element, StaticInjectAnnotationProcessorFactory[] processorFactories) {
+ private static InjectAnnotationProcessor2 getAnnotationProcessor(
+ AnnotatedElement element, StaticInjectAnnotationProcessorFactory[] processorFactories) {
for (StaticInjectAnnotationProcessorFactory processorFactory : processorFactories) {
InjectAnnotationProcessor2 annotationProcessor = processorFactory.createAnnotationProcessor(element);
if (annotationProcessor != null) {
@@ -90,7 +95,8 @@ abstract class AbstractInjectableElement implements InjectableElement {
}
@SuppressWarnings("unused")
- private static String getName(AnnotatedElement element, String defaultName, InjectAnnotationProcessor2 annotationProcessor) {
+ private static String getName(
+ AnnotatedElement element, String defaultName, InjectAnnotationProcessor2 annotationProcessor) {
String name = null;
if (annotationProcessor != null) {
name = annotationProcessor.getName();
@@ -99,8 +105,7 @@ abstract class AbstractInjectableElement implements InjectableElement {
Named namedAnnotation = element.getAnnotation(Named.class);
if (namedAnnotation != null) {
name = namedAnnotation.value();
- }
- else {
+ } else {
name = defaultName;
}
}
@@ -134,7 +139,8 @@ abstract class AbstractInjectableElement implements InjectableElement {
return spec;
}
- private static boolean getHasDefaultValue(AnnotatedElement element, InjectAnnotationProcessor2 annotationProcessor) {
+ private static boolean getHasDefaultValue(
+ AnnotatedElement element, InjectAnnotationProcessor2 annotationProcessor) {
if (annotationProcessor != null) {
return annotationProcessor.hasDefault();
}
@@ -142,7 +148,8 @@ abstract class AbstractInjectableElement implements InjectableElement {
}
@SuppressWarnings("unused")
- private static Object getDefaultValue(AnnotatedElement element, Type type, InjectAnnotationProcessor2 annotationProcessor) {
+ private static Object getDefaultValue(
+ AnnotatedElement element, Type type, InjectAnnotationProcessor2 annotationProcessor) {
if (annotationProcessor != null && annotationProcessor.hasDefault()) {
return annotationProcessor.getDefault();
}
@@ -155,7 +162,7 @@ abstract class AbstractInjectableElement implements InjectableElement {
Object value = null;
if (type instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType)type;
+ ParameterizedType parameterizedType = (ParameterizedType) type;
Type rawType = parameterizedType.getRawType();
if ((rawType == Collection.class || rawType == List.class)
&& parameterizedType.getActualTypeArguments().length > 0) {
@@ -177,12 +184,10 @@ abstract class AbstractInjectableElement implements InjectableElement {
} else {
log.warn("Default values for {} List/Collection are not supported (used on {})", itemType, element);
}
- }
- else {
+ } else {
log.warn("Cannot provide default for {} (used on {})", type, element);
}
- }
- else if (type instanceof Class) {
+ } else if (type instanceof Class) {
Class<?> injectedClass = (Class<?>) type;
if (injectedClass.isArray()) {
Class<?> componentType = injectedClass.getComponentType();
@@ -217,19 +222,33 @@ abstract class AbstractInjectableElement implements InjectableElement {
}
} else {
if (injectedClass == String.class) {
- value = defaultAnnotation.values().length == 0 ? "" : defaultAnnotation.values()[0];
+ value = defaultAnnotation.values().length == 0
+ ? ""
+ : defaultAnnotation.values()[0];
} else if (injectedClass == Integer.class) {
- value = defaultAnnotation.intValues().length == 0 ? 0 : defaultAnnotation.intValues()[0];
+ value = defaultAnnotation.intValues().length == 0
+ ? 0
+ : defaultAnnotation.intValues()[0];
} else if (injectedClass == Long.class) {
- value = defaultAnnotation.longValues().length == 0 ? 0l : defaultAnnotation.longValues()[0];
+ value = defaultAnnotation.longValues().length == 0
+ ? 0l
+ : defaultAnnotation.longValues()[0];
} else if (injectedClass == Boolean.class) {
- value = defaultAnnotation.booleanValues().length == 0 ? false : defaultAnnotation.booleanValues()[0];
+ value = defaultAnnotation.booleanValues().length == 0
+ ? false
+ : defaultAnnotation.booleanValues()[0];
} else if (injectedClass == Short.class) {
- value = defaultAnnotation.shortValues().length == 0 ? ((short) 0) : defaultAnnotation.shortValues()[0];
+ value = defaultAnnotation.shortValues().length == 0
+ ? ((short) 0)
+ : defaultAnnotation.shortValues()[0];
} else if (injectedClass == Float.class) {
- value = defaultAnnotation.floatValues().length == 0 ? 0f : defaultAnnotation.floatValues()[0];
+ value = defaultAnnotation.floatValues().length == 0
+ ? 0f
+ : defaultAnnotation.floatValues()[0];
} else if (injectedClass == Double.class) {
- value = defaultAnnotation.doubleValues().length == 0 ? 0d : defaultAnnotation.doubleValues()[0];
+ value = defaultAnnotation.doubleValues().length == 0
+ ? 0d
+ : defaultAnnotation.doubleValues()[0];
} else {
log.warn("Default values for {} are not supported (used on {})", injectedClass, element);
}
@@ -252,12 +271,11 @@ abstract class AbstractInjectableElement implements InjectableElement {
int arrayLength = Array.getLength(array);
if (arrayLength > 0) {
List<T> result = new ArrayList<>();
- for (int i=0; i<arrayLength; i++) {
- result.add((T)Array.get(array, i));
+ for (int i = 0; i < arrayLength; i++) {
+ result.add((T) Array.get(array, i));
}
return result;
}
-
}
return null;
}
@@ -281,10 +299,13 @@ abstract class AbstractInjectableElement implements InjectableElement {
return element.isAnnotationPresent(Required.class);
}
- private static DefaultInjectionStrategy getInjectionStrategy(AnnotatedElement element, InjectAnnotationProcessor annotationProcessor, DefaultInjectionStrategy defaultInjectionStrategy) {
+ private static DefaultInjectionStrategy getInjectionStrategy(
+ AnnotatedElement element,
+ InjectAnnotationProcessor annotationProcessor,
+ DefaultInjectionStrategy defaultInjectionStrategy) {
if (annotationProcessor != null) {
if (annotationProcessor instanceof InjectAnnotationProcessor2) {
- switch (((InjectAnnotationProcessor2)annotationProcessor).getInjectionStrategy()) {
+ switch (((InjectAnnotationProcessor2) annotationProcessor).getInjectionStrategy()) {
case OPTIONAL:
return DefaultInjectionStrategy.OPTIONAL;
case REQUIRED:
@@ -323,7 +344,9 @@ abstract class AbstractInjectableElement implements InjectableElement {
}
@Override
- public Class<? extends ViaProviderType> getViaProviderType() { return this.via.type; }
+ public Class<? extends ViaProviderType> getViaProviderType() {
+ return this.via.type;
+ }
@Override
public boolean hasDefaultValue() {
@@ -358,5 +381,4 @@ abstract class AbstractInjectableElement implements InjectableElement {
String via;
Class<? extends ViaProviderType> type;
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java b/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java
index 2eb525c..5394dbd 100644
--- a/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java
+++ b/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java
@@ -38,9 +38,20 @@ public class ConstructorParameter extends AbstractInjectableElement {
private final boolean isPrimitive;
private final int parameterIndex;
- public ConstructorParameter(Annotation[] annotations, Type parameterType, Type genericType, boolean isPrimitive,
- int parameterIndex, StaticInjectAnnotationProcessorFactory[] processorFactories, DefaultInjectionStrategy defaultInjectionStrategy) {
- super(new FakeAnnotatedElement(annotations, parameterIndex), genericType, null, processorFactories, defaultInjectionStrategy);
+ public ConstructorParameter(
+ Annotation[] annotations,
+ Type parameterType,
+ Type genericType,
+ boolean isPrimitive,
+ int parameterIndex,
+ StaticInjectAnnotationProcessorFactory[] processorFactories,
+ DefaultInjectionStrategy defaultInjectionStrategy) {
+ super(
+ new FakeAnnotatedElement(annotations, parameterIndex),
+ genericType,
+ null,
+ processorFactories,
+ defaultInjectionStrategy);
this.parameterType = parameterType;
this.genericType = genericType;
this.isPrimitive = isPrimitive;
@@ -83,12 +94,12 @@ public class ConstructorParameter extends AbstractInjectableElement {
return getAnnotation(paramClass) != null;
}
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
@Override
public <T extends Annotation> T getAnnotation(Class<T> paramClass) {
for (Annotation annotation : this.annotations) {
if (paramClass.isInstance(annotation)) {
- return (T)annotation;
+ return (T) annotation;
}
}
return null;
@@ -113,7 +124,5 @@ public class ConstructorParameter extends AbstractInjectableElement {
return "FakeAnnotatedElement [annotations=" + Arrays.toString(annotations) + ", parameterIndex="
+ parameterIndex + "]";
}
-
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/model/InjectableElement.java b/src/main/java/org/apache/sling/models/impl/model/InjectableElement.java
index 105b826..6ff7489 100644
--- a/src/main/java/org/apache/sling/models/impl/model/InjectableElement.java
+++ b/src/main/java/org/apache/sling/models/impl/model/InjectableElement.java
@@ -74,5 +74,4 @@ public interface InjectableElement {
* @return {@code true} if the element is optional otherwise {@code false}
*/
boolean isOptional(InjectAnnotationProcessor annotationProcessor);
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/model/InjectableField.java b/src/main/java/org/apache/sling/models/impl/model/InjectableField.java
index 10a70e1..56f5081 100644
--- a/src/main/java/org/apache/sling/models/impl/model/InjectableField.java
+++ b/src/main/java/org/apache/sling/models/impl/model/InjectableField.java
@@ -28,11 +28,19 @@ import org.apache.sling.models.impl.Result;
import org.apache.sling.models.spi.injectorspecific.StaticInjectAnnotationProcessorFactory;
public class InjectableField extends AbstractInjectableElement {
-
+
private final Field field;
-
- public InjectableField(Field field, StaticInjectAnnotationProcessorFactory[] processorFactories, DefaultInjectionStrategy defaultInjectionStrategy) {
- super(field, ReflectionUtil.mapPrimitiveClasses(field.getGenericType()), field.getName(), processorFactories, defaultInjectionStrategy);
+
+ public InjectableField(
+ Field field,
+ StaticInjectAnnotationProcessorFactory[] processorFactories,
+ DefaultInjectionStrategy defaultInjectionStrategy) {
+ super(
+ field,
+ ReflectionUtil.mapPrimitiveClasses(field.getGenericType()),
+ field.getName(),
+ processorFactories,
+ defaultInjectionStrategy);
this.field = field;
}
diff --git a/src/main/java/org/apache/sling/models/impl/model/InjectableMethod.java b/src/main/java/org/apache/sling/models/impl/model/InjectableMethod.java
index b0d954b..04437a0 100644
--- a/src/main/java/org/apache/sling/models/impl/model/InjectableMethod.java
+++ b/src/main/java/org/apache/sling/models/impl/model/InjectableMethod.java
@@ -26,12 +26,20 @@ import org.apache.sling.models.impl.ReflectionUtil;
import org.apache.sling.models.spi.injectorspecific.StaticInjectAnnotationProcessorFactory;
public class InjectableMethod extends AbstractInjectableElement {
-
+
private final Method method;
private final Type genericReturnType;
- public InjectableMethod(Method method, StaticInjectAnnotationProcessorFactory[] processorFactories, DefaultInjectionStrategy defaultInjectionStrategy) {
- super(method, ReflectionUtil.mapPrimitiveClasses(method.getGenericReturnType()), getDefaultName(method), processorFactories, defaultInjectionStrategy);
+ public InjectableMethod(
+ Method method,
+ StaticInjectAnnotationProcessorFactory[] processorFactories,
+ DefaultInjectionStrategy defaultInjectionStrategy) {
+ super(
+ method,
+ ReflectionUtil.mapPrimitiveClasses(method.getGenericReturnType()),
+ getDefaultName(method),
+ processorFactories,
+ defaultInjectionStrategy);
this.method = method;
this.genericReturnType = method.getGenericReturnType();
}
@@ -61,5 +69,4 @@ public class InjectableMethod extends AbstractInjectableElement {
return methodName;
}
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/model/ModelClass.java b/src/main/java/org/apache/sling/models/impl/model/ModelClass.java
index 4f81a62..2e35892 100644
--- a/src/main/java/org/apache/sling/models/impl/model/ModelClass.java
+++ b/src/main/java/org/apache/sling/models/impl/model/ModelClass.java
@@ -48,7 +48,7 @@ public class ModelClass<ModelType> {
}
updateProcessorFactories(processorFactories);
}
-
+
/**
* Updates processor factories after the model class was instantiated.
* @param processorFactories Static injector annotation processor factories
@@ -58,43 +58,53 @@ public class ModelClass<ModelType> {
this.injectableFields = getInjectableFields(type, processorFactories, defaultInjectionStrategy);
this.injectableMethods = getInjectableMethods(type, processorFactories, defaultInjectionStrategy);
}
-
+
@SuppressWarnings("unchecked")
- private static <T> ModelClassConstructor<T>[] getConstructors(Class<T> type, StaticInjectAnnotationProcessorFactory[] processorFactories, DefaultInjectionStrategy defaultInjectionStrategy) {
+ private static <T> ModelClassConstructor<T>[] getConstructors(
+ Class<T> type,
+ StaticInjectAnnotationProcessorFactory[] processorFactories,
+ DefaultInjectionStrategy defaultInjectionStrategy) {
if (type.isInterface()) {
return new ModelClassConstructor[0];
}
Constructor<T>[] constructors = (Constructor<T>[]) type.getDeclaredConstructors();
-
- // sort the constructor list in order from most params to least params, and constructors with @Inject annotation first
+
+ // sort the constructor list in order from most params to least params, and constructors with @Inject annotation
+ // first
Arrays.sort(constructors, new ParameterCountInjectComparator());
ModelClassConstructor<T>[] array = new ModelClassConstructor[constructors.length];
- for (int i=0; i<array.length; i++) {
+ for (int i = 0; i < array.length; i++) {
array[i] = new ModelClassConstructor<>(constructors[i], processorFactories, defaultInjectionStrategy);
}
return array;
}
- private static InjectableField[] getInjectableFields(Class<?> type, StaticInjectAnnotationProcessorFactory[] processorFactories, DefaultInjectionStrategy defaultInjectionStrategy) {
+ private static InjectableField[] getInjectableFields(
+ Class<?> type,
+ StaticInjectAnnotationProcessorFactory[] processorFactories,
+ DefaultInjectionStrategy defaultInjectionStrategy) {
if (type.isInterface()) {
return new InjectableField[0];
}
List<Field> injectableFields = ReflectionUtil.collectInjectableFields(type);
InjectableField[] array = new InjectableField[injectableFields.size()];
- for (int i=0; i<array.length; i++) {
+ for (int i = 0; i < array.length; i++) {
array[i] = new InjectableField(injectableFields.get(i), processorFactories, defaultInjectionStrategy);
}
return array;
}
- private static InjectableMethod[] getInjectableMethods(Class<?> type, StaticInjectAnnotationProcessorFactory[] processorFactories, DefaultInjectionStrategy defaultInjectionStrategy) {
+ private static InjectableMethod[] getInjectableMethods(
+ Class<?> type,
+ StaticInjectAnnotationProcessorFactory[] processorFactories,
+ DefaultInjectionStrategy defaultInjectionStrategy) {
if (!type.isInterface()) {
return new InjectableMethod[0];
}
List<Method> injectableMethods = ReflectionUtil.collectInjectableMethods(type);
InjectableMethod[] array = new InjectableMethod[injectableMethods.size()];
- for (int i=0; i<array.length; i++) {
+ for (int i = 0; i < array.length; i++) {
array[i] = new InjectableMethod(injectableMethods.get(i), processorFactories, defaultInjectionStrategy);
}
return array;
@@ -103,15 +113,15 @@ public class ModelClass<ModelType> {
public Class<ModelType> getType() {
return this.type;
}
-
+
public Model getModelAnnotation() {
return this.modelAnnotation;
}
-
+
public boolean hasModelAnnotation() {
return this.modelAnnotation != null;
}
-
+
public ModelClassConstructor<ModelType>[] getConstructors() {
return constructors;
}
@@ -123,5 +133,4 @@ public class ModelClass<ModelType> {
public InjectableMethod[] getInjectableMethods() {
return this.injectableMethods;
}
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/model/ModelClassConstructor.java b/src/main/java/org/apache/sling/models/impl/model/ModelClassConstructor.java
index 23460be..ffcdfca 100644
--- a/src/main/java/org/apache/sling/models/impl/model/ModelClassConstructor.java
+++ b/src/main/java/org/apache/sling/models/impl/model/ModelClassConstructor.java
@@ -18,12 +18,12 @@
*/
package org.apache.sling.models.impl.model;
+import javax.inject.Inject;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
-import javax.inject.Inject;
-
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.impl.ReflectionUtil;
import org.apache.sling.models.spi.injectorspecific.StaticInjectAnnotationProcessorFactory;
@@ -34,7 +34,10 @@ public class ModelClassConstructor<M> {
private final boolean hasInjectAnnotation;
private final ConstructorParameter[] constructorParametersArray;
- public ModelClassConstructor(Constructor<M> constructor, StaticInjectAnnotationProcessorFactory[] processorFactories, DefaultInjectionStrategy defaultInjectionStrategy) {
+ public ModelClassConstructor(
+ Constructor<M> constructor,
+ StaticInjectAnnotationProcessorFactory[] processorFactories,
+ DefaultInjectionStrategy defaultInjectionStrategy) {
this.constructor = constructor;
this.hasInjectAnnotation = constructor.isAnnotationPresent(Inject.class);
@@ -45,29 +48,35 @@ public class ModelClassConstructor<M> {
Type genericType = ReflectionUtil.mapPrimitiveClasses(parameterTypes[i]);
boolean isPrimitive = (parameterTypes[i] != genericType);
this.constructorParametersArray[i] = new ConstructorParameter(
- constructor.getParameterAnnotations()[i], constructor.getParameterTypes()[i], genericType, isPrimitive, i,
- processorFactories, defaultInjectionStrategy);
+ constructor.getParameterAnnotations()[i],
+ constructor.getParameterTypes()[i],
+ genericType,
+ isPrimitive,
+ i,
+ processorFactories,
+ defaultInjectionStrategy);
}
}
/**
* Proxies the call to {@link Constructor#newInstance(Object...)}, checking (and
* setting) accessibility first.
- *
+ *
* @param parameters
* the constructor parameters that are passed to
* {@link Constructor#newInstance(Object...)}
* @return The constructed object
- *
+ *
* @throws InstantiationException when {@link Constructor#newInstance(Object...)} would throw
* @throws IllegalAccessException when {@link Constructor#newInstance(Object...)} would throw
* @throws IllegalArgumentException when {@link Constructor#newInstance(Object...)} would throw
* @throws InvocationTargetException when {@link Constructor#newInstance(Object...)} would throw
- *
+ *
* @see Constructor#newInstance(Object...)
*/
- @SuppressWarnings({"java:S3011","java:S1874"})
- public M newInstance(Object... parameters) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ @SuppressWarnings({"java:S3011", "java:S1874"})
+ public M newInstance(Object... parameters)
+ throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
constructor.setAccessible(true);
return constructor.newInstance(parameters);
}
@@ -82,6 +91,6 @@ public class ModelClassConstructor<M> {
public ConstructorParameter[] getConstructorParameters() {
return constructorParametersArray;
- };
-
+ }
+ ;
}
diff --git a/src/main/java/org/apache/sling/models/impl/model/OptionalTypedInjectableElement.java b/src/main/java/org/apache/sling/models/impl/model/OptionalTypedInjectableElement.java
index ba4f160..8a50bfb 100644
--- a/src/main/java/org/apache/sling/models/impl/model/OptionalTypedInjectableElement.java
+++ b/src/main/java/org/apache/sling/models/impl/model/OptionalTypedInjectableElement.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -75,7 +77,8 @@ public class OptionalTypedInjectableElement implements InjectableElement {
@Override
public Object getDefaultValue() {
- // Default value injector will be evaluated last, make sure we return a value here so the injection is successful
+ // Default value injector will be evaluated last, make sure we return a value here so the injection is
+ // successful
return element.getDefaultValue() == null ? Optional.empty() : element.getDefaultValue();
}
diff --git a/src/main/java/org/apache/sling/models/impl/model/ParameterCountInjectComparator.java b/src/main/java/org/apache/sling/models/impl/model/ParameterCountInjectComparator.java
index b75caf6..2618828 100644
--- a/src/main/java/org/apache/sling/models/impl/model/ParameterCountInjectComparator.java
+++ b/src/main/java/org/apache/sling/models/impl/model/ParameterCountInjectComparator.java
@@ -18,11 +18,11 @@
*/
package org.apache.sling.models.impl.model;
+import javax.inject.Inject;
+
import java.lang.reflect.Constructor;
import java.util.Comparator;
-import javax.inject.Inject;
-
/**
* Comparator which sorts constructors by the number of parameters
* in reverse order (most params to least params).
@@ -34,10 +34,9 @@ class ParameterCountInjectComparator implements Comparator<Constructor<?>> {
@Override
public int compare(Constructor<?> o1, Constructor<?> o2) {
int result = compareParameterCount(o2.getParameterTypes().length, o1.getParameterTypes().length);
- if (result==0) {
+ if (result == 0) {
return compareInjectAnnotation(o1, o2);
- }
- else {
+ } else {
return result;
}
}
@@ -51,13 +50,10 @@ class ParameterCountInjectComparator implements Comparator<Constructor<?>> {
boolean hasInject2 = o2.isAnnotationPresent(Inject.class);
if (hasInject1 && !hasInject2) {
return -1;
- }
- else if (hasInject2 && !hasInject1) {
+ } else if (hasInject2 && !hasInject1) {
return 1;
- }
- else {
+ } else {
return 0;
}
}
-
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/models/impl/via/AbstractResourceTypeViaProvider.java b/src/main/java/org/apache/sling/models/impl/via/AbstractResourceTypeViaProvider.java
index ecacb3d..b6094a4 100644
--- a/src/main/java/org/apache/sling/models/impl/via/AbstractResourceTypeViaProvider.java
+++ b/src/main/java/org/apache/sling/models/impl/via/AbstractResourceTypeViaProvider.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.via;
@@ -33,7 +35,7 @@ public abstract class AbstractResourceTypeViaProvider implements ViaProvider {
if (!handle(value)) {
return ORIGINAL;
}
- if (original instanceof Resource) {
+ if (original instanceof Resource) {
final Resource resource = (Resource) original;
final String resourceType = getResourceType(resource, value);
if (resourceType == null) {
@@ -41,7 +43,7 @@ public abstract class AbstractResourceTypeViaProvider implements ViaProvider {
return null;
}
return new ResourceTypeForcingResourceWrapper(resource, resourceType);
- } else if (original instanceof SlingHttpServletRequest) {
+ } else if (original instanceof SlingHttpServletRequest) {
final SlingHttpServletRequest request = (SlingHttpServletRequest) original;
final Resource resource = request.getResource();
if (resource == null) {
@@ -53,14 +55,15 @@ public abstract class AbstractResourceTypeViaProvider implements ViaProvider {
return null;
}
return new ResourceTypeForcingRequestWrapper(request, resource, resourceType);
- } else {
- log.warn("Received unexpected adaptable of type {}.", original.getClass().getName());
+ } else {
+ log.warn(
+ "Received unexpected adaptable of type {}.",
+ original.getClass().getName());
return null;
- }
+ }
}
protected abstract boolean handle(@NotNull String value);
protected abstract @Nullable String getResourceType(@NotNull Resource resource, @NotNull String value);
-
}
diff --git a/src/main/java/org/apache/sling/models/impl/via/BeanPropertyViaProvider.java b/src/main/java/org/apache/sling/models/impl/via/BeanPropertyViaProvider.java
index 3051fa1..f383822 100644
--- a/src/main/java/org/apache/sling/models/impl/via/BeanPropertyViaProvider.java
+++ b/src/main/java/org/apache/sling/models/impl/via/BeanPropertyViaProvider.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.via;
@@ -28,7 +30,7 @@ import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Component(service=ViaProvider.class)
+@Component(service = ViaProvider.class)
public class BeanPropertyViaProvider implements ViaProvider {
private static final Logger log = LoggerFactory.getLogger(BeanPropertyViaProvider.class);
diff --git a/src/main/java/org/apache/sling/models/impl/via/ChildResourceViaProvider.java b/src/main/java/org/apache/sling/models/impl/via/ChildResourceViaProvider.java
index 6ccc9a4..128a06c 100644
--- a/src/main/java/org/apache/sling/models/impl/via/ChildResourceViaProvider.java
+++ b/src/main/java/org/apache/sling/models/impl/via/ChildResourceViaProvider.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.via;
@@ -27,7 +29,7 @@ import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Component(service=ViaProvider.class)
+@Component(service = ViaProvider.class)
public class ChildResourceViaProvider implements ViaProvider {
private static final Logger log = LoggerFactory.getLogger(ChildResourceViaProvider.class);
@@ -57,7 +59,9 @@ public class ChildResourceViaProvider implements ViaProvider {
}
return new ChildResourceRequestWrapper(request, child);
} else {
- log.warn("Received unexpected adaptable of type {}.", original.getClass().getName());
+ log.warn(
+ "Received unexpected adaptable of type {}.",
+ original.getClass().getName());
return null;
}
}
diff --git a/src/main/java/org/apache/sling/models/impl/via/ForcedResourceTypeViaProvider.java b/src/main/java/org/apache/sling/models/impl/via/ForcedResourceTypeViaProvider.java
index d6c29ec..55d30e6 100644
--- a/src/main/java/org/apache/sling/models/impl/via/ForcedResourceTypeViaProvider.java
+++ b/src/main/java/org/apache/sling/models/impl/via/ForcedResourceTypeViaProvider.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.via;
@@ -24,7 +26,7 @@ import org.apache.sling.models.spi.ViaProvider;
import org.jetbrains.annotations.NotNull;
import org.osgi.service.component.annotations.Component;
-@Component(service=ViaProvider.class)
+@Component(service = ViaProvider.class)
public class ForcedResourceTypeViaProvider extends AbstractResourceTypeViaProvider {
@Override
public Class<? extends ViaProviderType> getType() {
diff --git a/src/main/java/org/apache/sling/models/impl/via/OriginalResourceTypeViaProvider.java b/src/main/java/org/apache/sling/models/impl/via/OriginalResourceTypeViaProvider.java
index 00ef495..9344da6 100644
--- a/src/main/java/org/apache/sling/models/impl/via/OriginalResourceTypeViaProvider.java
+++ b/src/main/java/org/apache/sling/models/impl/via/OriginalResourceTypeViaProvider.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.via;
diff --git a/src/main/java/org/apache/sling/models/impl/via/ResourceSuperTypeViaProvider.java b/src/main/java/org/apache/sling/models/impl/via/ResourceSuperTypeViaProvider.java
index 2ed229b..b6fc4f4 100644
--- a/src/main/java/org/apache/sling/models/impl/via/ResourceSuperTypeViaProvider.java
+++ b/src/main/java/org/apache/sling/models/impl/via/ResourceSuperTypeViaProvider.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.via;
@@ -23,7 +25,7 @@ import org.apache.sling.models.spi.ViaProvider;
import org.jetbrains.annotations.NotNull;
import org.osgi.service.component.annotations.Component;
-@Component(service=ViaProvider.class)
+@Component(service = ViaProvider.class)
public class ResourceSuperTypeViaProvider extends AbstractResourceTypeViaProvider {
@Override
diff --git a/src/main/java/org/apache/sling/models/impl/via/ResourceTypeForcingRequestWrapper.java b/src/main/java/org/apache/sling/models/impl/via/ResourceTypeForcingRequestWrapper.java
index 9a57490..35e2e29 100644
--- a/src/main/java/org/apache/sling/models/impl/via/ResourceTypeForcingRequestWrapper.java
+++ b/src/main/java/org/apache/sling/models/impl/via/ResourceTypeForcingRequestWrapper.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.via;
diff --git a/src/main/java/org/apache/sling/models/impl/via/ResourceTypeForcingResourceWrapper.java b/src/main/java/org/apache/sling/models/impl/via/ResourceTypeForcingResourceWrapper.java
index beff897..1227ef0 100644
--- a/src/main/java/org/apache/sling/models/impl/via/ResourceTypeForcingResourceWrapper.java
+++ b/src/main/java/org/apache/sling/models/impl/via/ResourceTypeForcingResourceWrapper.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.via;
diff --git a/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java b/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
index 8b20b31..314dd3d 100644
--- a/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
+++ b/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
@@ -1,24 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -57,6 +56,9 @@ import org.osgi.service.component.ComponentContext;
import org.osgi.util.converter.Converter;
import org.osgi.util.converter.Converters;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class AdapterFactoryTest {
@@ -92,8 +94,16 @@ public class AdapterFactoryTest {
factory = createModelAdapterFactory();
factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(0, 0));
factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(1, 1));
- factory.modelExporters = Arrays.<ModelExporter>asList(new FirstStringExporter(), new SecondStringExporter(), new FirstIntegerExporter());
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(DefaultStringModel.class, ConstructorWithExceptionModel.class, NestedModel.class, NestedModelWithInvalidAdaptable.class, NestedModelWithInvalidAdaptable2.class, ResourceModelWithRequiredField.class, CachedModelWithSelfReference.class) ;
+ factory.modelExporters = Arrays.<ModelExporter>asList(
+ new FirstStringExporter(), new SecondStringExporter(), new FirstIntegerExporter());
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ DefaultStringModel.class,
+ ConstructorWithExceptionModel.class,
+ NestedModel.class,
+ NestedModelWithInvalidAdaptable.class,
+ NestedModelWithInvalidAdaptable2.class,
+ ResourceModelWithRequiredField.class,
+ CachedModelWithSelfReference.class);
}
@Test
@@ -176,7 +186,7 @@ public class AdapterFactoryTest {
Assert.assertEquals("required", model.getNestedModel().getRequired());
}
- @Test(expected=MissingElementsException.class)
+ @Test(expected = MissingElementsException.class)
public void testCreatedNestedModelWithMissingElements() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("invalid", "required");
@@ -193,7 +203,8 @@ public class AdapterFactoryTest {
when(result.wasSuccessful()).thenReturn(true);
when(result.getValue()).thenReturn(new Object());
- String exported = factory.handleAndExportResult(result, "second", String.class, Collections.<String, String>emptyMap());
+ String exported =
+ factory.handleAndExportResult(result, "second", String.class, Collections.<String, String>emptyMap());
Assert.assertEquals("Export from second", exported);
}
@@ -204,7 +215,8 @@ public class AdapterFactoryTest {
when(result.wasSuccessful()).thenReturn(true);
when(result.getValue()).thenReturn(new Object());
- Integer exported = factory.handleAndExportResult(result, "first", Integer.class, Collections.<String, String>emptyMap());
+ Integer exported =
+ factory.handleAndExportResult(result, "first", Integer.class, Collections.<String, String>emptyMap());
Assert.assertEquals(Integer.valueOf(42), exported);
}
@@ -227,7 +239,8 @@ public class AdapterFactoryTest {
@Nullable
@Override
@SuppressWarnings("unchecked")
- public <T> T export(@NotNull Object o, @NotNull Class<T> aClass, @NotNull Map<String, String> map) throws ExportException {
+ public <T> T export(@NotNull Object o, @NotNull Class<T> aClass, @NotNull Map<String, String> map)
+ throws ExportException {
if (aClass == String.class) {
return (T) "Export from first";
} else {
@@ -251,7 +264,8 @@ public class AdapterFactoryTest {
@Nullable
@Override
- public <T> T export(@NotNull Object o, @NotNull Class<T> aClass, @NotNull Map<String, String> map) throws ExportException {
+ public <T> T export(@NotNull Object o, @NotNull Class<T> aClass, @NotNull Map<String, String> map)
+ throws ExportException {
if (aClass == String.class) {
return (T) "Export from second";
} else {
@@ -275,7 +289,8 @@ public class AdapterFactoryTest {
@Nullable
@Override
- public <T> T export(@NotNull Object o, @NotNull Class<T> aClass, @NotNull Map<String, String> map) throws ExportException {
+ public <T> T export(@NotNull Object o, @NotNull Class<T> aClass, @NotNull Map<String, String> map)
+ throws ExportException {
if (aClass == Integer.class) {
return (T) Integer.valueOf(42);
} else {
diff --git a/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java b/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java
index ddb5071..093f52d 100644
--- a/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java
+++ b/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java
@@ -18,11 +18,6 @@
*/
package org.apache.sling.models.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.when;
-
import java.util.Arrays;
import org.apache.sling.api.SlingHttpServletRequest;
@@ -38,6 +33,11 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.osgi.framework.BundleContext;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class AdapterImplementationsTest {
@@ -61,9 +61,7 @@ public class AdapterImplementationsTest {
@Before
public void setUp() {
underTest = new AdapterImplementations();
- underTest.setImplementationPickers(Arrays.asList(new ImplementationPicker[] {
- new FirstImplementationPicker()
- }));
+ underTest.setImplementationPickers(Arrays.asList(new ImplementationPicker[] {new FirstImplementationPicker()}));
}
@Test
@@ -78,7 +76,8 @@ public class AdapterImplementationsTest {
public void testSingleMapping() {
underTest.addAll(String.class, SAMPLE_ADAPTER);
- assertEquals(String.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
+ assertEquals(
+ String.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
underTest.remove(SAMPLE_ADAPTER.getName(), String.class.getName());
@@ -91,11 +90,14 @@ public class AdapterImplementationsTest {
underTest.addAll(Integer.class, SAMPLE_ADAPTER);
underTest.addAll(Long.class, SAMPLE_ADAPTER);
- assertEquals(Integer.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
+ assertEquals(
+ Integer.class,
+ underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
underTest.remove(SAMPLE_ADAPTER.getName(), Integer.class.getName());
- assertEquals(Long.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
+ assertEquals(
+ Long.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
underTest.remove(SAMPLE_ADAPTER.getName(), Long.class.getName());
underTest.remove(SAMPLE_ADAPTER.getName(), String.class.getName());
@@ -117,23 +119,23 @@ public class AdapterImplementationsTest {
@Test
public void testMultipleImplementationPickers() {
underTest.setImplementationPickers(Arrays.asList(
- new NoneImplementationPicker(),
- new LastImplementationPicker(),
- new FirstImplementationPicker()
- ));
+ new NoneImplementationPicker(), new LastImplementationPicker(), new FirstImplementationPicker()));
underTest.addAll(String.class, SAMPLE_ADAPTER);
underTest.addAll(Integer.class, SAMPLE_ADAPTER);
underTest.addAll(Long.class, SAMPLE_ADAPTER);
- assertEquals(String.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
+ assertEquals(
+ String.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
}
@Test
public void testSimpleModel() {
underTest.addAll(SAMPLE_ADAPTER, SAMPLE_ADAPTER);
- assertEquals(SAMPLE_ADAPTER, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
+ assertEquals(
+ SAMPLE_ADAPTER,
+ underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
}
@Test
@@ -144,7 +146,7 @@ public class AdapterImplementationsTest {
when(childResource.getResourceResolver()).thenReturn(resourceResolver);
when(resourceResolver.getParentResourceType(resource)).thenReturn(null);
when(resourceResolver.getParentResourceType(childResource)).thenReturn("sling/rt/one");
- when(resourceResolver.getSearchPath()).thenReturn(new String[] { "/apps/", "/libs/" });
+ when(resourceResolver.getSearchPath()).thenReturn(new String[] {"/apps/", "/libs/"});
// ensure we don't have any registrations for 'sling/rt/one'
assertNull(underTest.getModelClassForResource(resource));
@@ -158,7 +160,8 @@ public class AdapterImplementationsTest {
// ensure that trying to reregister the resource type is a no-op
BundleContext secondBundleContext = MockOsgi.newBundleContext();
- underTest.registerModelToResourceType(secondBundleContext.getBundle(), "sling/rt/one", Resource.class, Integer.class);
+ underTest.registerModelToResourceType(
+ secondBundleContext.getBundle(), "sling/rt/one", Resource.class, Integer.class);
assertEquals(String.class, underTest.getModelClassForResource(resource));
assertEquals(String.class, underTest.getModelClassForResource(childResource));
@@ -175,7 +178,7 @@ public class AdapterImplementationsTest {
when(childResource.getResourceResolver()).thenReturn(resourceResolver);
when(resourceResolver.getParentResourceType(resource)).thenReturn(null);
when(resourceResolver.getParentResourceType(childResource)).thenReturn("sling/rt/one");
- when(resourceResolver.getSearchPath()).thenReturn(new String[] { "/apps/", "/libs/" });
+ when(resourceResolver.getSearchPath()).thenReturn(new String[] {"/apps/", "/libs/"});
// ensure we don't have any registrations for 'sling/rt/one'
assertNull(underTest.getModelClassForResource(resource));
@@ -183,7 +186,8 @@ public class AdapterImplementationsTest {
// now add a mapping for Resource -> String
BundleContext bundleContext = MockOsgi.newBundleContext();
- underTest.registerModelToResourceType(bundleContext.getBundle(), "/apps/sling/rt/one", Resource.class, String.class);
+ underTest.registerModelToResourceType(
+ bundleContext.getBundle(), "/apps/sling/rt/one", Resource.class, String.class);
assertEquals(String.class, underTest.getModelClassForResource(resource));
assertEquals(String.class, underTest.getModelClassForResource(childResource));
@@ -200,7 +204,7 @@ public class AdapterImplementationsTest {
when(childResource.getResourceResolver()).thenReturn(resourceResolver);
when(resourceResolver.getParentResourceType(resource)).thenReturn(null);
when(resourceResolver.getParentResourceType(childResource)).thenReturn("/apps/sling/rt/one");
- when(resourceResolver.getSearchPath()).thenReturn(new String[] { "/apps/", "/libs/" });
+ when(resourceResolver.getSearchPath()).thenReturn(new String[] {"/apps/", "/libs/"});
// ensure we don't have any registrations for 'sling/rt/one'
assertNull(underTest.getModelClassForResource(resource));
@@ -222,7 +226,7 @@ public class AdapterImplementationsTest {
when(resource.getResourceType()).thenReturn("sling/rt/one");
when(resource.getResourceResolver()).thenReturn(resourceResolver);
when(resourceResolver.getParentResourceType(resource)).thenReturn(null);
- when(resourceResolver.getSearchPath()).thenReturn(new String[] { "/apps/", "/libs/" });
+ when(resourceResolver.getSearchPath()).thenReturn(new String[] {"/apps/", "/libs/"});
when(request.getResource()).thenReturn(resource);
// ensure we don't have any registrations for 'sling/rt/one'
@@ -231,14 +235,16 @@ public class AdapterImplementationsTest {
// now add a mapping for SlingHttpServletRequest -> String
BundleContext bundleContext = MockOsgi.newBundleContext();
- underTest.registerModelToResourceType(bundleContext.getBundle(), "sling/rt/one", SlingHttpServletRequest.class, String.class);
+ underTest.registerModelToResourceType(
+ bundleContext.getBundle(), "sling/rt/one", SlingHttpServletRequest.class, String.class);
underTest.registerModelToResourceType(bundleContext.getBundle(), "sling/rt/one", Resource.class, Integer.class);
assertEquals(String.class, underTest.getModelClassForRequest(request));
assertEquals(Integer.class, underTest.getModelClassForResource(resource));
// ensure that trying to reregister the resource type is a no-op
BundleContext secondBundleContext = MockOsgi.newBundleContext();
- underTest.registerModelToResourceType(secondBundleContext.getBundle(), "sling/rt/one", SlingHttpServletRequest.class, Integer.class);
+ underTest.registerModelToResourceType(
+ secondBundleContext.getBundle(), "sling/rt/one", SlingHttpServletRequest.class, Integer.class);
assertEquals(String.class, underTest.getModelClassForRequest(request));
underTest.removeResourceTypeBindings(bundleContext.getBundle());
@@ -250,7 +256,7 @@ public class AdapterImplementationsTest {
public void testResourceTypeRegistrationForResourceWithoutResourceType() {
lenient().when(resource.getResourceType()).thenReturn(null);
lenient().when(resource.getResourceResolver()).thenReturn(resourceResolver);
- lenient().when(resourceResolver.getSearchPath()).thenReturn(new String[] { "/apps/", "/libs/" });
+ lenient().when(resourceResolver.getSearchPath()).thenReturn(new String[] {"/apps/", "/libs/"});
// ensure we don't have any registrations and no exception is thrown
assertNull(underTest.getModelClassForResource(resource));
@@ -258,16 +264,17 @@ public class AdapterImplementationsTest {
static final class NoneImplementationPicker implements ImplementationPicker {
@Override
- public Class<?> pick(@NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
+ public Class<?> pick(
+ @NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
return null;
}
}
static final class LastImplementationPicker implements ImplementationPicker {
@Override
- public Class<?> pick(@NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
+ public Class<?> pick(
+ @NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
return implementationsTypes[implementationsTypes.length - 1];
}
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/AnnotationConflictsTest.java b/src/test/java/org/apache/sling/models/impl/AnnotationConflictsTest.java
index c2ae291..0cbcdb3 100644
--- a/src/test/java/org/apache/sling/models/impl/AnnotationConflictsTest.java
+++ b/src/test/java/org/apache/sling/models/impl/AnnotationConflictsTest.java
@@ -18,12 +18,6 @@
*/
package org.apache.sling.models.impl;
-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.when;
-
import java.util.Collections;
import org.apache.sling.api.resource.Resource;
@@ -45,6 +39,12 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+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.when;
+
@SuppressWarnings("deprecation")
@RunWith(MockitoJUnitRunner.class)
public class AnnotationConflictsTest {
@@ -59,7 +59,8 @@ public class AnnotationConflictsTest {
factory = AdapterFactoryTest.createModelAdapterFactory();
ValueMapInjector injector = new ValueMapInjector();
factory.bindInjector(injector, new ServicePropertiesMap(1, 1));
- factory.injectAnnotationProcessorFactories = Collections.<InjectAnnotationProcessorFactory>singletonList(new ValueMapInjector());
+ factory.injectAnnotationProcessorFactories =
+ Collections.<InjectAnnotationProcessorFactory>singletonList(new ValueMapInjector());
for (Class<?> clazz : this.getClass().getDeclaredClasses()) {
if (!clazz.isInterface()) {
@@ -263,6 +264,7 @@ public class AnnotationConflictsTest {
private interface Methods {
String getOtherText();
+
String getEmptyText();
}
@@ -272,8 +274,13 @@ public class AnnotationConflictsTest {
Methods model = factory.createModel(resource, modelClass);
assertNotNull("Adaptation to " + modelClass.getSimpleName() + " was not null.", model);
- assertNull("Adaptation to " + modelClass.getSimpleName() + " had a non-null emptyText value.", model.getEmptyText());
- assertEquals("Adaptation to " + modelClass.getSimpleName() + " had an unexpected value in the otherText value.", "hello", model.getOtherText());
+ assertNull(
+ "Adaptation to " + modelClass.getSimpleName() + " had a non-null emptyText value.",
+ model.getEmptyText());
+ assertEquals(
+ "Adaptation to " + modelClass.getSimpleName() + " had an unexpected value in the otherText value.",
+ "hello",
+ model.getOtherText());
}
private <T extends Methods> void failing(Class<T> modelClass) {
@@ -285,9 +292,14 @@ public class AnnotationConflictsTest {
try {
factory.createModel(resource, modelClass);
} catch (MissingElementsException e) {
- assertEquals("Adaptation to " + modelClass.getSimpleName() + " failed, but with the wrong number of exceptions.",1, e.getMissingElements().size());
+ assertEquals(
+ "Adaptation to " + modelClass.getSimpleName() + " failed, but with the wrong number of exceptions.",
+ 1,
+ e.getMissingElements().size());
MissingElementException me = e.getMissingElements().iterator().next();
- assertTrue("Adaptation to " + modelClass.getSimpleName() + " didn't fail due to emptyText.", me.getElement().toString().endsWith("emptyText"));
+ assertTrue(
+ "Adaptation to " + modelClass.getSimpleName() + " didn't fail due to emptyText.",
+ me.getElement().toString().endsWith("emptyText"));
thrown = true;
}
assertTrue("Adaptation to " + modelClass.getSimpleName() + " was successful.", thrown);
diff --git a/src/test/java/org/apache/sling/models/impl/CachingTest.java b/src/test/java/org/apache/sling/models/impl/CachingTest.java
index 553f16c..f22ed75 100644
--- a/src/test/java/org/apache/sling/models/impl/CachingTest.java
+++ b/src/test/java/org/apache/sling/models/impl/CachingTest.java
@@ -1,28 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
import java.util.Collections;
import java.util.Enumeration;
@@ -47,6 +42,13 @@ import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class CachingTest {
@@ -66,16 +68,20 @@ public class CachingTest {
factory.bindInjector(new RequestAttributeInjector(), new ServicePropertiesMap(0, 0));
factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(1, 1));
factory.adapterImplementations.addClassesAsAdapterAndImplementation(
- CachedModel.class,
- UncachedModel.class,
- org.apache.sling.models.testmodels.interfaces.CachedModel.class,
- org.apache.sling.models.testmodels.interfaces.UncachedModel.class);
+ CachedModel.class,
+ UncachedModel.class,
+ org.apache.sling.models.testmodels.interfaces.CachedModel.class,
+ org.apache.sling.models.testmodels.interfaces.UncachedModel.class);
factory.adapterImplementations.addAll(
- CachedModelWithAdapterTypes12.class,
- CachedModelWithAdapterTypes12.class, AdapterType1.class, AdapterType2.class);
+ CachedModelWithAdapterTypes12.class,
+ CachedModelWithAdapterTypes12.class,
+ AdapterType1.class,
+ AdapterType2.class);
factory.adapterImplementations.addAll(
- CachedModelWithAdapterTypes23.class,
- CachedModelWithAdapterTypes23.class, AdapterType2.class, AdapterType3.class);
+ CachedModelWithAdapterTypes23.class,
+ CachedModelWithAdapterTypes23.class,
+ AdapterType2.class,
+ AdapterType3.class);
when(request.getAttribute("testValue")).thenReturn("test");
requestWrapper = new SlingHttpServletRequestWrapper(request);
@@ -134,10 +140,10 @@ public class CachingTest {
@Test
public void testCachedInterface() {
- org.apache.sling.models.testmodels.interfaces.CachedModel cached1 = factory.getAdapter(request,
- org.apache.sling.models.testmodels.interfaces.CachedModel.class);
- org.apache.sling.models.testmodels.interfaces.CachedModel cached2 = factory.getAdapter(request,
- org.apache.sling.models.testmodels.interfaces.CachedModel.class);
+ org.apache.sling.models.testmodels.interfaces.CachedModel cached1 =
+ factory.getAdapter(request, org.apache.sling.models.testmodels.interfaces.CachedModel.class);
+ org.apache.sling.models.testmodels.interfaces.CachedModel cached2 =
+ factory.getAdapter(request, org.apache.sling.models.testmodels.interfaces.CachedModel.class);
assertSame(cached1, cached2);
assertEquals("test", cached1.getTestValue());
@@ -148,10 +154,10 @@ public class CachingTest {
@Test
public void testNoCachedInterface() {
- org.apache.sling.models.testmodels.interfaces.UncachedModel uncached1 = factory.getAdapter(request,
- org.apache.sling.models.testmodels.interfaces.UncachedModel.class);
- org.apache.sling.models.testmodels.interfaces.UncachedModel uncached2 = factory.getAdapter(request,
- org.apache.sling.models.testmodels.interfaces.UncachedModel.class);
+ org.apache.sling.models.testmodels.interfaces.UncachedModel uncached1 =
+ factory.getAdapter(request, org.apache.sling.models.testmodels.interfaces.UncachedModel.class);
+ org.apache.sling.models.testmodels.interfaces.UncachedModel uncached2 =
+ factory.getAdapter(request, org.apache.sling.models.testmodels.interfaces.UncachedModel.class);
assertNotSame(uncached1, uncached2);
assertEquals("test", uncached1.getTestValue());
@@ -182,10 +188,10 @@ public class CachingTest {
@Test
public void testCachedInterfaceWithRequestWrapper() {
- org.apache.sling.models.testmodels.interfaces.CachedModel cached1 = factory.getAdapter(request,
- org.apache.sling.models.testmodels.interfaces.CachedModel.class);
- org.apache.sling.models.testmodels.interfaces.CachedModel cached2 = factory.getAdapter(requestWrapper,
- org.apache.sling.models.testmodels.interfaces.CachedModel.class);
+ org.apache.sling.models.testmodels.interfaces.CachedModel cached1 =
+ factory.getAdapter(request, org.apache.sling.models.testmodels.interfaces.CachedModel.class);
+ org.apache.sling.models.testmodels.interfaces.CachedModel cached2 =
+ factory.getAdapter(requestWrapper, org.apache.sling.models.testmodels.interfaces.CachedModel.class);
assertSame(cached1, cached2);
assertEquals("test", cached1.getTestValue());
@@ -196,19 +202,20 @@ public class CachingTest {
@Test
public void testCachedModelWithAdapterTypes() {
- // test 2 model implementations that share a common adapter type, with an implementation picker that selects exactly one of the
+ // test 2 model implementations that share a common adapter type, with an implementation picker that selects
+ // exactly one of the
// implementations for the common adapter type. verify that the models are cached accordingly
factory.bindImplementationPicker(
- (adapterType, impls, adaptable) -> {
- if (AdapterType1.class.equals(adapterType)) {
- return CachedModelWithAdapterTypes12.class;
- } else if (AdapterType2.class.equals(adapterType) || AdapterType3.class.equals(adapterType)) {
- return CachedModelWithAdapterTypes23.class;
- } else {
- return null;
- }
- },
- new ServicePropertiesMap(2, 0));
+ (adapterType, impls, adaptable) -> {
+ if (AdapterType1.class.equals(adapterType)) {
+ return CachedModelWithAdapterTypes12.class;
+ } else if (AdapterType2.class.equals(adapterType) || AdapterType3.class.equals(adapterType)) {
+ return CachedModelWithAdapterTypes23.class;
+ } else {
+ return null;
+ }
+ },
+ new ServicePropertiesMap(2, 0));
CachedModelWithAdapterTypes12 byImpl12 = factory.getAdapter(request, CachedModelWithAdapterTypes12.class);
CachedModelWithAdapterTypes23 byImpl23 = factory.getAdapter(request, CachedModelWithAdapterTypes23.class);
@@ -221,4 +228,3 @@ public class CachingTest {
assertSame(byImpl23, byAdapterType3);
}
}
-
diff --git a/src/test/java/org/apache/sling/models/impl/ConstructorTest.java b/src/test/java/org/apache/sling/models/impl/ConstructorTest.java
index 5507a5c..7bfc250 100644
--- a/src/test/java/org/apache/sling/models/impl/ConstructorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ConstructorTest.java
@@ -1,29 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
@@ -54,6 +48,14 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class ConstructorTest {
@@ -84,8 +86,7 @@ public class ConstructorTest {
InvalidConstructorModel.class,
WithThreeConstructorsOneInjectModel.class,
NoNameModel.class,
- ViaRequestSuffixModel.class
- );
+ ViaRequestSuffixModel.class);
}
@Test
@@ -137,8 +138,8 @@ public class ConstructorTest {
*/
@Test
public void testThreeConstructorsOneInjectInjection() {
- WithThreeConstructorsOneInjectModel model = factory.getAdapter(request,
- WithThreeConstructorsOneInjectModel.class);
+ WithThreeConstructorsOneInjectModel model =
+ factory.getAdapter(request, WithThreeConstructorsOneInjectModel.class);
assertNotNull(model);
assertNull(model.getRequest());
assertEquals(INT_VALUE, model.getAttribute());
diff --git a/src/test/java/org/apache/sling/models/impl/ConstructorVisibilityTest.java b/src/test/java/org/apache/sling/models/impl/ConstructorVisibilityTest.java
index b1c449f..115bd0b 100644
--- a/src/test/java/org/apache/sling/models/impl/ConstructorVisibilityTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ConstructorVisibilityTest.java
@@ -1,23 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertNotNull;
-
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.impl.injectors.RequestAttributeInjector;
import org.apache.sling.models.impl.injectors.SelfInjector;
@@ -30,6 +30,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertNotNull;
+
@RunWith(MockitoJUnitRunner.class)
public class ConstructorVisibilityTest {
private ModelAdapterFactory factory;
@@ -42,7 +44,8 @@ public class ConstructorVisibilityTest {
factory = AdapterFactoryTest.createModelAdapterFactory();
factory.bindInjector(new RequestAttributeInjector(), new ServicePropertiesMap(1, 1));
factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(2, 2));
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(ProtectedConstructorModel.class, PackagePrivateConstructorModel.class, PrivateConstructorModel.class);
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ ProtectedConstructorModel.class, PackagePrivateConstructorModel.class, PrivateConstructorModel.class);
}
@Test
@@ -50,13 +53,13 @@ public class ConstructorVisibilityTest {
ProtectedConstructorModel model = factory.createModel(request, ProtectedConstructorModel.class);
assertNotNull(model);
}
-
+
@Test
public void testNonPublicConstructorPackagePrivateModel() {
PackagePrivateConstructorModel model = factory.createModel(request, PackagePrivateConstructorModel.class);
assertNotNull(model);
}
-
+
@Test
public void testNonPublicConstructorPrivateModel() {
PrivateConstructorModel model = factory.createModel(request, PrivateConstructorModel.class);
diff --git a/src/test/java/org/apache/sling/models/impl/CustomInjectorTest.java b/src/test/java/org/apache/sling/models/impl/CustomInjectorTest.java
index c84c714..f149af2 100644
--- a/src/test/java/org/apache/sling/models/impl/CustomInjectorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/CustomInjectorTest.java
@@ -1,28 +1,27 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import javax.inject.Inject;
import java.util.Collections;
-import javax.inject.Inject;
-
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.impl.injector.CustomAnnotation;
import org.apache.sling.models.impl.injector.CustomAnnotationInjector;
@@ -33,6 +32,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
@SuppressWarnings("deprecation")
@RunWith(MockitoJUnitRunner.class)
public class CustomInjectorTest {
@@ -42,7 +44,8 @@ public class CustomInjectorTest {
@Before
public void setup() {
factory = AdapterFactoryTest.createModelAdapterFactory();
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(TestModel.class, CustomAnnotationModel.class);
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ TestModel.class, CustomAnnotationModel.class);
}
@Test
@@ -60,7 +63,8 @@ public class CustomInjectorTest {
factory.bindInjector(new SimpleInjector(), new ServicePropertiesMap(1, 1));
factory.bindInjector(injector, new ServicePropertiesMap(1, 1));
- factory.injectAnnotationProcessorFactories = factory.injectAnnotationProcessorFactories = Collections.<InjectAnnotationProcessorFactory>singletonList(injector);
+ factory.injectAnnotationProcessorFactories = factory.injectAnnotationProcessorFactories =
+ Collections.<InjectAnnotationProcessorFactory>singletonList(injector);
CustomAnnotationModel model = factory.getAdapter(new Object(), CustomAnnotationModel.class);
assertNotNull(model);
@@ -82,5 +86,4 @@ public class CustomInjectorTest {
@Inject
String getCustomString();
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/DefaultInterfaceMethodTest.java b/src/test/java/org/apache/sling/models/impl/DefaultInterfaceMethodTest.java
index 5798c67..01f1db9 100644
--- a/src/test/java/org/apache/sling/models/impl/DefaultInterfaceMethodTest.java
+++ b/src/test/java/org/apache/sling/models/impl/DefaultInterfaceMethodTest.java
@@ -1,21 +1,25 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
+import java.util.Collections;
+
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
@@ -24,8 +28,6 @@ import org.apache.sling.models.testmodels.interfaces.ModelWithDefaultMethods;
import org.junit.Before;
import org.junit.Test;
-import java.util.Collections;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.lenient;
@@ -48,7 +50,7 @@ public class DefaultInterfaceMethodTest {
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(vm);
- ModelWithDefaultMethods model = factory.getAdapter(res,ModelWithDefaultMethods.class);
+ ModelWithDefaultMethods model = factory.getAdapter(res, ModelWithDefaultMethods.class);
assertEquals("the prop", model.getProp());
}
@@ -59,7 +61,7 @@ public class DefaultInterfaceMethodTest {
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(vm);
- ModelWithDefaultMethods model = factory.getAdapter(res,ModelWithDefaultMethods.class);
+ ModelWithDefaultMethods model = factory.getAdapter(res, ModelWithDefaultMethods.class);
assertNull(model.getProp());
}
diff --git a/src/test/java/org/apache/sling/models/impl/DefaultTest.java b/src/test/java/org/apache/sling/models/impl/DefaultTest.java
index 4963853..ccf5f0f 100644
--- a/src/test/java/org/apache/sling/models/impl/DefaultTest.java
+++ b/src/test/java/org/apache/sling/models/impl/DefaultTest.java
@@ -1,29 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.util.Arrays;
import java.util.Collections;
@@ -40,6 +34,14 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class DefaultTest {
@@ -49,7 +51,14 @@ public class DefaultTest {
public void setup() {
factory = AdapterFactoryTest.createModelAdapterFactory();
factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(0, 0));
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(DefaultStringModel.class, PropertyModelWithDefaults.class, DefaultPrimitivesModel.class, DefaultWrappersModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultStringModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel.class);
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ DefaultStringModel.class,
+ PropertyModelWithDefaults.class,
+ DefaultPrimitivesModel.class,
+ DefaultWrappersModel.class,
+ org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel.class,
+ org.apache.sling.models.testmodels.classes.constructorinjection.DefaultStringModel.class,
+ org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel.class);
}
@Test
@@ -78,7 +87,6 @@ public class DefaultTest {
assertEquals("second default", model.getSecond());
}
-
@Test
public void testDefaultPrimitivesField() {
ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());
@@ -90,11 +98,12 @@ public class DefaultTest {
assertNotNull(model);
assertEquals(true, model.getBooleanProperty());
- // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
- assertTrue(Arrays.equals(new boolean[] { true, true }, model.getBooleanArrayProperty()));
+ // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays,
+ // https://github.com/junit-team/junit/issues/86!
+ assertTrue(Arrays.equals(new boolean[] {true, true}, model.getBooleanArrayProperty()));
assertEquals(1L, model.getLongProperty());
- assertArrayEquals(new long[] { 1L, 1L }, model.getLongArrayProperty());
+ assertArrayEquals(new long[] {1L, 1L}, model.getLongArrayProperty());
}
@Test
@@ -108,11 +117,12 @@ public class DefaultTest {
assertNotNull(model);
assertEquals(Boolean.valueOf(true), model.getBooleanWrapperProperty());
- // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
- assertTrue(Arrays.equals(new Boolean[] { Boolean.TRUE, Boolean.TRUE }, model.getBooleanWrapperArrayProperty()));
+ // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays,
+ // https://github.com/junit-team/junit/issues/86!
+ assertTrue(Arrays.equals(new Boolean[] {Boolean.TRUE, Boolean.TRUE}, model.getBooleanWrapperArrayProperty()));
assertEquals(Long.valueOf(1L), model.getLongWrapperProperty());
- assertArrayEquals(new Long[] { Long.valueOf(1L), Long.valueOf(1L) }, model.getLongWrapperArrayProperty());
+ assertArrayEquals(new Long[] {Long.valueOf(1L), Long.valueOf(1L)}, model.getLongWrapperArrayProperty());
}
@Test
@@ -122,8 +132,8 @@ public class DefaultTest {
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(vm);
- org.apache.sling.models.testmodels.classes.constructorinjection.DefaultStringModel model
- = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultStringModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.DefaultStringModel model = factory.getAdapter(
+ res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultStringModel.class);
assertNotNull(model);
assertEquals("firstDefault", model.getFirstProperty());
assertEquals(2, model.getSecondProperty().length);
@@ -136,16 +146,19 @@ public class DefaultTest {
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(vm);
- org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel model
- = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel model =
+ factory.getAdapter(
+ res,
+ org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel.class);
assertNotNull(model);
assertEquals(true, model.getBooleanProperty());
- // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
- assertTrue(Arrays.equals(new boolean[] { true, true }, model.getBooleanArrayProperty()));
+ // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays,
+ // https://github.com/junit-team/junit/issues/86!
+ assertTrue(Arrays.equals(new boolean[] {true, true}, model.getBooleanArrayProperty()));
assertEquals(1L, model.getLongProperty());
- assertArrayEquals(new long[] { 1L, 1L }, model.getLongArrayProperty());
+ assertArrayEquals(new long[] {1L, 1L}, model.getLongArrayProperty());
}
@Test
@@ -155,16 +168,16 @@ public class DefaultTest {
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(vm);
- org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel model
- = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel model = factory.getAdapter(
+ res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel.class);
assertNotNull(model);
assertEquals(Boolean.valueOf(true), model.getBooleanWrapperProperty());
- // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
- assertTrue(Arrays.equals(new Boolean[] { Boolean.TRUE, Boolean.TRUE }, model.getBooleanWrapperArrayProperty()));
+ // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays,
+ // https://github.com/junit-team/junit/issues/86!
+ assertTrue(Arrays.equals(new Boolean[] {Boolean.TRUE, Boolean.TRUE}, model.getBooleanWrapperArrayProperty()));
assertEquals(Long.valueOf(1L), model.getLongWrapperProperty());
- assertArrayEquals(new Long[] { Long.valueOf(1L), Long.valueOf(1L) }, model.getLongWrapperArrayProperty());
+ assertArrayEquals(new Long[] {Long.valueOf(1L), Long.valueOf(1L)}, model.getLongWrapperArrayProperty());
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/ExtraDefaultTests.java b/src/test/java/org/apache/sling/models/impl/ExtraDefaultTests.java
index 03576be..a72ec4c 100644
--- a/src/test/java/org/apache/sling/models/impl/ExtraDefaultTests.java
+++ b/src/test/java/org/apache/sling/models/impl/ExtraDefaultTests.java
@@ -1,24 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
import javax.inject.Inject;
import org.apache.sling.api.resource.Resource;
@@ -30,6 +29,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
@RunWith(MockitoJUnitRunner.class)
public class ExtraDefaultTests {
@@ -41,7 +43,8 @@ public class ExtraDefaultTests {
@Before
public void setup() {
factory = AdapterFactoryTest.createModelAdapterFactory();
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(EmptyDefaultsModel.class, WrongTypeDefaultsModel.class);
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ EmptyDefaultsModel.class, WrongTypeDefaultsModel.class);
}
@Test
@@ -135,7 +138,7 @@ public class ExtraDefaultTests {
@Inject
@Default
private short[] shortArray;
-
+
@Inject
@Default
private Boolean[] booleanWrapperArray;
@@ -215,39 +218,37 @@ public class ExtraDefaultTests {
@Inject
@Default
private String singleString;
-
}
@Model(adaptables = Resource.class)
public static class WrongTypeDefaultsModel {
@Inject
- @Default(intValues = { 1, 1 })
+ @Default(intValues = {1, 1})
private boolean[] booleanArray;
@Inject
- @Default(intValues = { 1, 1 })
+ @Default(intValues = {1, 1})
private double[] doubleArray;
@Inject
- @Default(intValues = { 1, 1 })
+ @Default(intValues = {1, 1})
private float[] floatArray;
@Inject
- @Default(longValues = { 1, 1 })
+ @Default(longValues = {1, 1})
private int[] intArray;
@Inject
- @Default(intValues = { 1, 1 })
+ @Default(intValues = {1, 1})
private long[] longArray;
@Inject
- @Default(intValues = { 1, 1 })
+ @Default(intValues = {1, 1})
private short[] shortArray;
@Inject
- @Default(intValues = { 1, 1 })
+ @Default(intValues = {1, 1})
private String[] stringArray;
-
}
}
diff --git a/src/test/java/org/apache/sling/models/impl/ImplementsExtendsTest.java b/src/test/java/org/apache/sling/models/impl/ImplementsExtendsTest.java
index 3520722..352f464 100644
--- a/src/test/java/org/apache/sling/models/impl/ImplementsExtendsTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ImplementsExtendsTest.java
@@ -1,30 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Dictionary;
@@ -63,6 +56,15 @@ import org.osgi.framework.BundleEvent;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class ImplementsExtendsTest {
@@ -86,30 +88,32 @@ public class ImplementsExtendsTest {
@SuppressWarnings("unchecked")
@Before
public void setup() throws ClassNotFoundException, MalformedURLException {
- when(bundleContext.registerService(anyString(), any(), any(Dictionary.class))).then(new Answer<ServiceRegistration>() {
- @Override
- public ServiceRegistration<?> answer(InvocationOnMock invocation) throws Throwable {
- final Dictionary<String, Object> props = (Dictionary<String, Object>)invocation.getArguments()[2];
- ServiceRegistration reg = mock(ServiceRegistration.class);
- ServiceReference ref = mock(ServiceReference.class);
- when(reg.getReference()).thenReturn(ref);
- when(ref.getProperty(anyString())).thenAnswer(new Answer<Object>() {
+ when(bundleContext.registerService(anyString(), any(), any(Dictionary.class)))
+ .then(new Answer<ServiceRegistration>() {
@Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- String key = (String)invocation.getArguments()[0];
- return props.get(key);
+ public ServiceRegistration<?> answer(InvocationOnMock invocation) throws Throwable {
+ final Dictionary<String, Object> props =
+ (Dictionary<String, Object>) invocation.getArguments()[2];
+ ServiceRegistration reg = mock(ServiceRegistration.class);
+ ServiceReference ref = mock(ServiceReference.class);
+ when(reg.getReference()).thenReturn(ref);
+ when(ref.getProperty(anyString())).thenAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ String key = (String) invocation.getArguments()[0];
+ return props.get(key);
+ }
+ });
+ return reg;
}
});
- return reg;
- }
- });
factory = AdapterFactoryTest.createModelAdapterFactory(bundleContext);
factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(2, 2));
factory.bindImplementationPicker(firstImplementationPicker, firstImplementationPickerProps);
// simulate bundle add for ModelPackageBundleListener
- Dictionary<String, String> headers = new Hashtable<String,String>();
+ Dictionary<String, String> headers = new Hashtable<String, String>();
headers.put(ModelPackageBundleListener.PACKAGE_HEADER, "org.apache.sling.models.testmodels.classes.implextend");
when(bundle.getHeaders()).thenReturn(headers);
@@ -126,7 +130,7 @@ public class ImplementsExtendsTest {
when(bundle.loadClass(anyString())).then(new Answer<Class<?>>() {
@Override
public Class<?> answer(InvocationOnMock invocation) throws ClassNotFoundException {
- String className = (String)invocation.getArguments()[0];
+ String className = (String) invocation.getArguments()[0];
return ImplementsExtendsTest.this.getClass().getClassLoader().loadClass(className);
}
});
@@ -148,7 +152,8 @@ public class ImplementsExtendsTest {
Resource res = getMockResourceWithProps();
try {
factory.getAdapter(res, SampleServiceInterface.class);
- Assert.fail("Getting the model for interface 'SampleServiceInterface' should fail after the accroding adapter factory has been unregistered");
+ Assert.fail(
+ "Getting the model for interface 'SampleServiceInterface' should fail after the accroding adapter factory has been unregistered");
} catch (ModelClassException e) {
}
@@ -187,7 +192,7 @@ public class ImplementsExtendsTest {
* Try to adapt in a case where there is no picker available.
* The case where the class is the adapter still works.
*/
- @Test(expected=ModelClassException.class)
+ @Test(expected = ModelClassException.class)
public void testImplementsNoPickerWithDifferentImplementations() {
factory.unbindImplementationPicker(firstImplementationPicker, firstImplementationPickerProps);
@@ -212,7 +217,7 @@ public class ImplementsExtendsTest {
/**
* Test implementation class with a mapping that is not valid (an interface that is not implemented).
*/
- @Test(expected=ModelClassException.class)
+ @Test(expected = ModelClassException.class)
public void testInvalidImplementsInterfaceModel() {
Resource res = getMockResourceWithProps();
factory.getAdapter(res, InvalidSampleServiceInterface.class);
@@ -242,7 +247,8 @@ public class ImplementsExtendsTest {
*/
@Test
public void testImplementsInterfaceModelWithPickLastImplementationPicker() {
- factory.bindImplementationPicker(new AdapterImplementationsTest.LastImplementationPicker(), new ServicePropertiesMap(3, 1));
+ factory.bindImplementationPicker(
+ new AdapterImplementationsTest.LastImplementationPicker(), new ServicePropertiesMap(3, 1));
Resource res = getMockResourceWithProps();
SampleServiceInterface model = factory.getAdapter(res, SampleServiceInterface.class);
@@ -262,5 +268,4 @@ public class ImplementsExtendsTest {
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
return res;
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java b/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
index 2b96c43..b50d67b 100644
--- a/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
+++ b/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
@@ -1,26 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -53,6 +50,11 @@ import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
@SuppressWarnings("deprecation")
public class InjectorSpecificAnnotationTest {
@@ -82,31 +84,32 @@ public class InjectorSpecificAnnotationTest {
ChildResourceInjector childResourceInjector = new ChildResourceInjector();
RequestAttributeInjector requestAttributeInjector = new RequestAttributeInjector();
- factory.bindInjector(bindingsInjector,
- Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 1L));
- factory.bindInjector(valueMapInjector,
- Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 2L));
- factory.bindInjector(childResourceInjector,
- Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 3L));
- factory.bindInjector(requestAttributeInjector,
- Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 4L));
- factory.bindInjector(osgiInjector, Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 5L));
-
- factory.bindStaticInjectAnnotationProcessorFactory(bindingsInjector,
- Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 1L));
- factory.injectAnnotationProcessorFactories = Collections.<InjectAnnotationProcessorFactory>singletonList(valueMapInjector);
- factory.injectAnnotationProcessorFactories2 = Collections.<InjectAnnotationProcessorFactory2>singletonList(childResourceInjector);
- factory.bindStaticInjectAnnotationProcessorFactory(requestAttributeInjector,
- Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 4L));
- factory.bindStaticInjectAnnotationProcessorFactory(osgiInjector,
- Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 5L));
+ factory.bindInjector(bindingsInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 1L));
+ factory.bindInjector(valueMapInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 2L));
+ factory.bindInjector(childResourceInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 3L));
+ factory.bindInjector(
+ requestAttributeInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 4L));
+ factory.bindInjector(osgiInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 5L));
+
+ factory.bindStaticInjectAnnotationProcessorFactory(
+ bindingsInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 1L));
+ factory.injectAnnotationProcessorFactories =
+ Collections.<InjectAnnotationProcessorFactory>singletonList(valueMapInjector);
+ factory.injectAnnotationProcessorFactories2 =
+ Collections.<InjectAnnotationProcessorFactory2>singletonList(childResourceInjector);
+ factory.bindStaticInjectAnnotationProcessorFactory(
+ requestAttributeInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 4L));
+ factory.bindStaticInjectAnnotationProcessorFactory(
+ osgiInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 5L));
factory.bindViaProvider(new BeanPropertyViaProvider(), null);
SlingBindings bindings = new SlingBindings();
bindings.setLog(log);
Mockito.when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(InjectorSpecificAnnotationModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ InjectorSpecificAnnotationModel.class,
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
}
@Test
@@ -149,12 +152,11 @@ public class InjectorSpecificAnnotationTest {
}
@Test
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
public void testOSGiServiceField() throws InvalidSyntaxException {
ServiceReference ref = mock(ServiceReference.class);
Logger log = mock(Logger.class);
- when(bundleContext.getServiceReferences(Logger.class.getName(), null)).thenReturn(
- new ServiceReference[] { ref });
+ when(bundleContext.getServiceReferences(Logger.class.getName(), null)).thenReturn(new ServiceReference[] {ref});
when(bundleContext.getService(ref)).thenReturn(log);
InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
@@ -207,8 +209,11 @@ public class InjectorSpecificAnnotationTest {
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
when(request.getResource()).thenReturn(res);
- org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model
- = factory.getAdapter(request, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model =
+ factory.getAdapter(
+ request,
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel
+ .class);
assertNotNull("Could not instanciate model", model);
assertEquals("first-value", model.getFirst());
assertEquals("second-value", model.getSecond());
@@ -230,24 +235,29 @@ public class InjectorSpecificAnnotationTest {
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
when(request.getResource()).thenReturn(res);
- org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model
- = factory.getAdapter(request, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model =
+ factory.getAdapter(
+ request,
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel
+ .class);
assertNotNull("Could not instanciate model", model);
assertEquals("first-value", model.getFirst());
assertEquals(logFromValueMap, model.getLog());
}
@Test
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
public void testOSGiServiceConstructor() throws InvalidSyntaxException {
ServiceReference ref = mock(ServiceReference.class);
Logger log = mock(Logger.class);
- when(bundleContext.getServiceReferences(Logger.class.getName(), null)).thenReturn(
- new ServiceReference[] { ref });
+ when(bundleContext.getServiceReferences(Logger.class.getName(), null)).thenReturn(new ServiceReference[] {ref});
when(bundleContext.getService(ref)).thenReturn(log);
- org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model
- = factory.getAdapter(request, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model =
+ factory.getAdapter(
+ request,
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel
+ .class);
assertNotNull("Could not instanciate model", model);
assertEquals(log, model.getService());
}
@@ -259,8 +269,11 @@ public class InjectorSpecificAnnotationTest {
bindings.setSling(helper);
when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
- org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model
- = factory.getAdapter(request, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model =
+ factory.getAdapter(
+ request,
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel
+ .class);
assertNotNull("Could not instanciate model", model);
assertEquals(helper, model.getHelper());
}
@@ -270,8 +283,11 @@ public class InjectorSpecificAnnotationTest {
Object attribute = new Object();
when(request.getAttribute("attribute")).thenReturn(attribute);
- org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model
- = factory.getAdapter(request, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model =
+ factory.getAdapter(
+ request,
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel
+ .class);
assertNotNull("Could not instanciate model", model);
assertEquals(attribute, model.getRequestAttribute());
}
@@ -283,10 +299,12 @@ public class InjectorSpecificAnnotationTest {
when(res.getChild("child1")).thenReturn(child);
when(request.getResource()).thenReturn(res);
- org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model
- = factory.getAdapter(request, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model =
+ factory.getAdapter(
+ request,
+ org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel
+ .class);
assertNotNull("Could not instanciate model", model);
assertEquals(child, model.getChildResource());
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/InterfaceInheritanceTest.java b/src/test/java/org/apache/sling/models/impl/InterfaceInheritanceTest.java
index 66a54b5..f6b0365 100644
--- a/src/test/java/org/apache/sling/models/impl/InterfaceInheritanceTest.java
+++ b/src/test/java/org/apache/sling/models/impl/InterfaceInheritanceTest.java
@@ -1,26 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -37,6 +34,11 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
@SuppressWarnings("deprecation")
@RunWith(MockitoJUnitRunner.class)
public class InterfaceInheritanceTest {
@@ -49,7 +51,8 @@ public class InterfaceInheritanceTest {
ValueMapInjector valueMapInjector = new ValueMapInjector();
factory.bindInjector(valueMapInjector, new ServicePropertiesMap(1, 2));
- factory.injectAnnotationProcessorFactories = Collections.<InjectAnnotationProcessorFactory>singletonList(valueMapInjector);
+ factory.injectAnnotationProcessorFactories =
+ Collections.<InjectAnnotationProcessorFactory>singletonList(valueMapInjector);
factory.adapterImplementations.addClassesAsAdapterAndImplementation(SuperClassModel.class, SubClassModel.class);
}
diff --git a/src/test/java/org/apache/sling/models/impl/InvalidAdaptationsTest.java b/src/test/java/org/apache/sling/models/impl/InvalidAdaptationsTest.java
index eb6e151..fb0deea 100644
--- a/src/test/java/org/apache/sling/models/impl/InvalidAdaptationsTest.java
+++ b/src/test/java/org/apache/sling/models/impl/InvalidAdaptationsTest.java
@@ -1,25 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.mock;
-
import java.util.Collections;
import java.util.Map;
@@ -37,6 +35,10 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+
@RunWith(MockitoJUnitRunner.class)
public class InvalidAdaptationsTest {
private ModelAdapterFactory factory;
@@ -51,7 +53,7 @@ public class InvalidAdaptationsTest {
@Test
public void testNonModelClass() {
- Map<String, Object> emptyMap = Collections.<String, Object> emptyMap();
+ Map<String, Object> emptyMap = Collections.<String, Object>emptyMap();
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(emptyMap));
@@ -61,7 +63,7 @@ public class InvalidAdaptationsTest {
@Test(expected = ModelClassException.class)
public void testNonModelClassException() {
- Map<String, Object> emptyMap = Collections.<String, Object> emptyMap();
+ Map<String, Object> emptyMap = Collections.<String, Object>emptyMap();
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(emptyMap));
@@ -71,7 +73,7 @@ public class InvalidAdaptationsTest {
@Test
public void testWrongAdaptableClass() {
- Map<String, Object> emptyMap = Collections.<String, Object> emptyMap();
+ Map<String, Object> emptyMap = Collections.<String, Object>emptyMap();
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(emptyMap));
@@ -81,7 +83,7 @@ public class InvalidAdaptationsTest {
@Test(expected = InvalidAdaptableException.class)
public void testWrongAdaptableClassException() {
- Map<String, Object> emptyMap = Collections.<String, Object> emptyMap();
+ Map<String, Object> emptyMap = Collections.<String, Object>emptyMap();
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(emptyMap));
@@ -89,11 +91,8 @@ public class InvalidAdaptationsTest {
assertNull(factory.createModel(res, RequestModel.class));
}
- private class NonModel {
- }
+ private class NonModel {}
@Model(adaptables = SlingHttpServletRequest.class)
- private class RequestModel {
- }
-
+ private class RequestModel {}
}
diff --git a/src/test/java/org/apache/sling/models/impl/ModelPackageBundleListenerTest.java b/src/test/java/org/apache/sling/models/impl/ModelPackageBundleListenerTest.java
index 0872409..3f340fc 100644
--- a/src/test/java/org/apache/sling/models/impl/ModelPackageBundleListenerTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ModelPackageBundleListenerTest.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -57,17 +59,20 @@ public class ModelPackageBundleListenerTest {
private static final class HideClassesClassLoader extends OverridingClassLoader {
private final Collection<String> classNamesToHide;
+
public HideClassesClassLoader(ClassLoader parent, String... classNamesToHide) {
super(parent);
this.classNamesToHide = Arrays.asList(classNamesToHide);
- //Exclude Hidden class since its loading via default class loader and throws ClassNotFoundException in line:70
+ // Exclude Hidden class since its loading via default class loader and throws ClassNotFoundException in
+ // line:70
this.excludeClass(Hidden.class.getName());
}
@Override
protected Class<?> loadClassForOverriding(String name) throws ClassNotFoundException {
if (classNamesToHide.contains(name)) {
- throw new ClassNotFoundException("Could not find class " + name + " as it is hidden by this class loader!");
+ throw new ClassNotFoundException(
+ "Could not find class " + name + " as it is hidden by this class loader!");
}
return super.loadClassForOverriding(name);
}
@@ -75,31 +80,39 @@ public class ModelPackageBundleListenerTest {
@Test
public void testAddingBundleWithResolvableModelAnnotation() throws ClassNotFoundException {
- Assert.assertFalse("Model should not yet have been registered but was", adapterImplementations.isModelClass(ChildModel.class));
+ Assert.assertFalse(
+ "Model should not yet have been registered but was",
+ adapterImplementations.isModelClass(ChildModel.class));
ModelPackageBundleListener listener = createListenerForBundleWithClass(ChildModel.class);
listener.addingBundle(mockBundle, new BundleEvent(BundleEvent.STARTED, mockBundle));
- Assert.assertTrue("Model should have been registered but was not", adapterImplementations.isModelClass(ChildModel.class));
+ Assert.assertTrue(
+ "Model should have been registered but was not", adapterImplementations.isModelClass(ChildModel.class));
}
@Test
public void testAddingBundleWithNonResolvableNonModelAnnotation() throws ClassNotFoundException {
ClassLoader classLoader = new HideClassesClassLoader(this.getClass().getClassLoader(), Hidden.class.getName());
- ModelPackageBundleListener listener = createListenerForBundleWithClass(classLoader, SimpleModelWithInvalidSecondAnnotation.class.getName());
+ ModelPackageBundleListener listener =
+ createListenerForBundleWithClass(classLoader, SimpleModelWithInvalidSecondAnnotation.class.getName());
listener.addingBundle(mockBundle, new BundleEvent(BundleEvent.STARTED, mockBundle));
- Assert.assertFalse("Model should not yet have been registered but was", adapterImplementations.isModelClass(SimpleModelWithInvalidSecondAnnotation.class));
+ Assert.assertFalse(
+ "Model should not yet have been registered but was",
+ adapterImplementations.isModelClass(SimpleModelWithInvalidSecondAnnotation.class));
}
- private ModelPackageBundleListener createListenerForBundleWithClass(Class<?> modelClass) throws ClassNotFoundException {
+ private ModelPackageBundleListener createListenerForBundleWithClass(Class<?> modelClass)
+ throws ClassNotFoundException {
return createListenerForBundleWithClass(modelClass.getClassLoader(), modelClass.getName());
}
- private ModelPackageBundleListener createListenerForBundleWithClass(ClassLoader classLoader, String className) throws ClassNotFoundException {
+ private ModelPackageBundleListener createListenerForBundleWithClass(ClassLoader classLoader, String className)
+ throws ClassNotFoundException {
Dictionary<String, String> headers = new Hashtable<>();
headers.put(ModelPackageBundleListener.CLASSES_HEADER, className);
Mockito.when(mockBundle.getHeaders()).thenReturn(headers);
- Mockito.when(mockBundle.loadClass(Mockito.anyString())).thenAnswer(new Answer<Class<?>>(){
+ Mockito.when(mockBundle.loadClass(Mockito.anyString())).thenAnswer(new Answer<Class<?>>() {
@Override
- public Class<?>answer(InvocationOnMock invocation) throws Throwable {
+ public Class<?> answer(InvocationOnMock invocation) throws Throwable {
Object argument = invocation.getArguments()[0];
if (argument.equals(className)) {
return classLoader.loadClass(className);
@@ -108,7 +121,7 @@ public class ModelPackageBundleListenerTest {
}
}
});
- return new ModelPackageBundleListener(mockBundleContext, mockModelAdapterFactory, adapterImplementations, null, null);
+ return new ModelPackageBundleListener(
+ mockBundleContext, mockModelAdapterFactory, adapterImplementations, null, null);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java b/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java
index 64da4c8..2ac3a01 100644
--- a/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java
@@ -1,27 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.when;
-
import javax.inject.Inject;
import org.apache.sling.api.SlingHttpServletRequest;
@@ -38,6 +34,12 @@ import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class MultipleInjectorTest {
@@ -103,7 +105,7 @@ public class MultipleInjectorTest {
assertNull(obj);
}
- @Test(expected=ModelClassException.class)
+ @Test(expected = ModelClassException.class)
public void testInjectorWithInvalidSourceWithException() {
factory.createModel(request, ForTwoInjectorsWithInvalidSource.class);
}
@@ -113,7 +115,6 @@ public class MultipleInjectorTest {
@Inject
private String firstAttribute;
-
}
@Model(adaptables = SlingHttpServletRequest.class)
@@ -122,7 +123,6 @@ public class MultipleInjectorTest {
@Inject
@Source("request-attributes")
private String firstAttribute;
-
}
@Model(adaptables = SlingHttpServletRequest.class)
@@ -131,7 +131,5 @@ public class MultipleInjectorTest {
@Inject
@Source("this-is-an-invalid-source")
private String firstAttribute;
-
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/OSGiInjectionTest.java b/src/test/java/org/apache/sling/models/impl/OSGiInjectionTest.java
index 044b7c6..60f1b16 100644
--- a/src/test/java/org/apache/sling/models/impl/OSGiInjectionTest.java
+++ b/src/test/java/org/apache/sling/models/impl/OSGiInjectionTest.java
@@ -1,33 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
import java.util.Arrays;
import java.util.Dictionary;
@@ -54,6 +44,18 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceReference;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class OSGiInjectionTest {
private ModelAdapterFactory factory;
@@ -75,16 +77,26 @@ public class OSGiInjectionTest {
factory.bindInjector(injectorFactory, new ServicePropertiesMap(1, 1));
bindings.setSling(helper);
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(SimpleOSGiModel.class, ListOSGiModel.class, RequestOSGiModel.class, ArrayOSGiModel.class, SetOSGiModel.class, OptionalListOSGiModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.ListOSGiModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.SimpleOSGiModel.class, CollectionOSGiModel.class, OptionalArrayOSGiModel.class);
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ SimpleOSGiModel.class,
+ ListOSGiModel.class,
+ RequestOSGiModel.class,
+ ArrayOSGiModel.class,
+ SetOSGiModel.class,
+ OptionalListOSGiModel.class,
+ org.apache.sling.models.testmodels.classes.constructorinjection.ListOSGiModel.class,
+ org.apache.sling.models.testmodels.classes.constructorinjection.SimpleOSGiModel.class,
+ CollectionOSGiModel.class,
+ OptionalArrayOSGiModel.class);
}
@Test
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
public void testSimpleOSGiModelField() throws Exception {
ServiceReference ref = mock(ServiceReference.class);
ServiceInterface service = mock(ServiceInterface.class);
- when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null)).thenReturn(
- new ServiceReference[] { ref });
+ when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null))
+ .thenReturn(new ServiceReference[] {ref});
when(bundleContext.getService(ref)).thenReturn(service);
Resource res = mock(Resource.class);
@@ -98,7 +110,7 @@ public class OSGiInjectionTest {
}
@Test
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
public void testListOSGiModelField() throws Exception {
ServiceReference ref1 = mock(ServiceReference.class);
ServiceInterface service1 = mock(ServiceInterface.class);
@@ -107,8 +119,8 @@ public class OSGiInjectionTest {
ServiceInterface service2 = mock(ServiceInterface.class);
when(bundleContext.getService(ref2)).thenReturn(service2);
- when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null)).thenReturn(
- new ServiceReference[] { ref1, ref2 });
+ when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null))
+ .thenReturn(new ServiceReference[] {ref1, ref2});
Resource res = mock(Resource.class);
@@ -123,7 +135,7 @@ public class OSGiInjectionTest {
}
@Test
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
public void testArrayOSGiModelField() throws Exception {
ServiceReference ref1 = mock(ServiceReference.class);
ServiceInterface service1 = mock(ServiceInterface.class);
@@ -132,8 +144,8 @@ public class OSGiInjectionTest {
ServiceInterface service2 = mock(ServiceInterface.class);
when(bundleContext.getService(ref2)).thenReturn(service2);
- when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null)).thenReturn(
- new ServiceReference[] { ref1, ref2 });
+ when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null))
+ .thenReturn(new ServiceReference[] {ref1, ref2});
Resource res = mock(Resource.class);
@@ -173,7 +185,7 @@ public class OSGiInjectionTest {
}
@Test
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
public void testCollectionOSGiModelField() throws Exception {
ServiceReference ref1 = mock(ServiceReference.class);
ServiceInterface service1 = mock(ServiceInterface.class);
@@ -182,8 +194,8 @@ public class OSGiInjectionTest {
ServiceInterface service2 = mock(ServiceInterface.class);
when(bundleContext.getService(ref2)).thenReturn(service2);
- when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null)).thenReturn(
- new ServiceReference[] { ref1, ref2 });
+ when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null))
+ .thenReturn(new ServiceReference[] {ref1, ref2});
Resource res = mock(Resource.class);
@@ -198,7 +210,7 @@ public class OSGiInjectionTest {
}
@Test
- @SuppressWarnings({ "unused", "unchecked", "null" })
+ @SuppressWarnings({"unused", "unchecked", "null"})
public void testSetOSGiModelField() throws Exception {
ServiceReference ref1 = mock(ServiceReference.class);
ServiceInterface service1 = mock(ServiceInterface.class);
@@ -207,8 +219,9 @@ public class OSGiInjectionTest {
ServiceInterface service2 = mock(ServiceInterface.class);
lenient().when(bundleContext.getService(ref2)).thenReturn(service2);
- lenient().when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null)).thenReturn(
- new ServiceReference[] { ref1, ref2 });
+ lenient()
+ .when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null))
+ .thenReturn(new ServiceReference[] {ref1, ref2});
Resource res = mock(Resource.class);
@@ -224,18 +237,18 @@ public class OSGiInjectionTest {
}
@Test
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
public void testSimpleOSGiModelConstructor() throws Exception {
ServiceReference ref = mock(ServiceReference.class);
ServiceInterface service = mock(ServiceInterface.class);
- when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null)).thenReturn(
- new ServiceReference[] { ref });
+ when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null))
+ .thenReturn(new ServiceReference[] {ref});
when(bundleContext.getService(ref)).thenReturn(service);
Resource res = mock(Resource.class);
- org.apache.sling.models.testmodels.classes.constructorinjection.SimpleOSGiModel model
- = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.SimpleOSGiModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.SimpleOSGiModel model = factory.getAdapter(
+ res, org.apache.sling.models.testmodels.classes.constructorinjection.SimpleOSGiModel.class);
assertNotNull(model);
assertNotNull(model.getService());
assertEquals(service, model.getService());
@@ -244,7 +257,7 @@ public class OSGiInjectionTest {
}
@Test
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
public void testListOSGiModelConstructor() throws Exception {
ServiceReference ref1 = mock(ServiceReference.class);
ServiceInterface service1 = mock(ServiceInterface.class);
@@ -253,13 +266,13 @@ public class OSGiInjectionTest {
ServiceInterface service2 = mock(ServiceInterface.class);
when(bundleContext.getService(ref2)).thenReturn(service2);
- when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null)).thenReturn(
- new ServiceReference[] { ref1, ref2 });
+ when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null))
+ .thenReturn(new ServiceReference[] {ref1, ref2});
Resource res = mock(Resource.class);
- org.apache.sling.models.testmodels.classes.constructorinjection.ListOSGiModel model
- = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.ListOSGiModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.ListOSGiModel model = factory.getAdapter(
+ res, org.apache.sling.models.testmodels.classes.constructorinjection.ListOSGiModel.class);
assertNotNull(model);
assertNotNull(model.getServices());
// the order on those is non deterministic as the ServiceReference.compareTo() is always returning 0
@@ -268,5 +281,4 @@ public class OSGiInjectionTest {
verifyNoMoreInteractions(res);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/OptionalObjectsTest.java b/src/test/java/org/apache/sling/models/impl/OptionalObjectsTest.java
index 250714d..6e3a610 100644
--- a/src/test/java/org/apache/sling/models/impl/OptionalObjectsTest.java
+++ b/src/test/java/org/apache/sling/models/impl/OptionalObjectsTest.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -40,6 +42,7 @@ import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
+
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@@ -73,24 +76,23 @@ public class OptionalObjectsTest {
ChildResourceInjector childResourceInjector = new ChildResourceInjector();
RequestAttributeInjector requestAttributeInjector = new RequestAttributeInjector();
- factory.bindInjector(bindingsInjector,
- Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 1L));
- factory.bindInjector(valueMapInjector,
- Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 2L));
- factory.bindInjector(childResourceInjector,
- Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 3L));
- factory.bindInjector(requestAttributeInjector,
- Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 4L));
+ factory.bindInjector(bindingsInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 1L));
+ factory.bindInjector(valueMapInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 2L));
+ factory.bindInjector(childResourceInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 3L));
+ factory.bindInjector(
+ requestAttributeInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 4L));
factory.bindInjector(osgiInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 5L));
- factory.bindStaticInjectAnnotationProcessorFactory(bindingsInjector,
- Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 1L));
- factory.injectAnnotationProcessorFactories = Collections.<InjectAnnotationProcessorFactory>singletonList(valueMapInjector);
- factory.injectAnnotationProcessorFactories2 = Collections.<InjectAnnotationProcessorFactory2>singletonList(childResourceInjector);
- factory.bindStaticInjectAnnotationProcessorFactory(requestAttributeInjector,
- Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 4L));
- factory.bindStaticInjectAnnotationProcessorFactory(osgiInjector,
- Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 5L));
+ factory.bindStaticInjectAnnotationProcessorFactory(
+ bindingsInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 1L));
+ factory.injectAnnotationProcessorFactories =
+ Collections.<InjectAnnotationProcessorFactory>singletonList(valueMapInjector);
+ factory.injectAnnotationProcessorFactories2 =
+ Collections.<InjectAnnotationProcessorFactory2>singletonList(childResourceInjector);
+ factory.bindStaticInjectAnnotationProcessorFactory(
+ requestAttributeInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 4L));
+ factory.bindStaticInjectAnnotationProcessorFactory(
+ osgiInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 5L));
factory.bindViaProvider(new BeanPropertyViaProvider(), null);
SlingBindings bindings = new SlingBindings();
@@ -98,7 +100,6 @@ public class OptionalObjectsTest {
Mockito.when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
factory.adapterImplementations.addClassesAsAdapterAndImplementation(OptionalObjectsModel.class);
-
}
@Test
@@ -118,8 +119,8 @@ public class OptionalObjectsTest {
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(map));
- org.apache.sling.models.testmodels.classes.OptionalObjectsModel model = factory.getAdapter(res,
- OptionalObjectsModel.class);
+ org.apache.sling.models.testmodels.classes.OptionalObjectsModel model =
+ factory.getAdapter(res, OptionalObjectsModel.class);
assertNotNull(model);
assertEquals(Optional.of("foo bar baz"), model.getOptionalString());
@@ -157,10 +158,10 @@ public class OptionalObjectsTest {
public void testFieldInjectionListsAndArrays() {
Map<String, Object> map = new HashMap<>();
- map.put("intList", new Integer[]{1, 2, 9, 8});
- map.put("stringList", new String[]{"hello", "world"});
+ map.put("intList", new Integer[] {1, 2, 9, 8});
+ map.put("stringList", new String[] {"hello", "world"});
map.put("optionalList", Arrays.asList("foo", "bar", "baz"));
- map.put("optionalArray", new String[]{"qux", "quux"});
+ map.put("optionalArray", new String[] {"qux", "quux"});
ValueMap vm = new ValueMapDecorator(map);
Resource res = mock(Resource.class);
@@ -215,8 +216,7 @@ public class OptionalObjectsTest {
public void testFieldInjectionsOSGiService() throws InvalidSyntaxException {
ServiceReference ref = mock(ServiceReference.class);
Logger log = mock(Logger.class);
- when(bundleContext.getServiceReferences(Logger.class.getName(), null)).thenReturn(
- new ServiceReference[]{ref});
+ when(bundleContext.getServiceReferences(Logger.class.getName(), null)).thenReturn(new ServiceReference[] {ref});
when(bundleContext.getService(ref)).thenReturn(log);
OptionalObjectsModel model = factory.getAdapter(request, OptionalObjectsModel.class);
diff --git a/src/test/java/org/apache/sling/models/impl/OptionalPrimitivesTest.java b/src/test/java/org/apache/sling/models/impl/OptionalPrimitivesTest.java
index c98e954..6307793 100644
--- a/src/test/java/org/apache/sling/models/impl/OptionalPrimitivesTest.java
+++ b/src/test/java/org/apache/sling/models/impl/OptionalPrimitivesTest.java
@@ -1,28 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.models.impl.injectors.ChildResourceInjector;
@@ -32,6 +27,13 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
/**
* Validates that @Optional annotations works with primitive values which do not support null
*/
@@ -45,7 +47,10 @@ public class OptionalPrimitivesTest {
factory = AdapterFactoryTest.createModelAdapterFactory();
factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(2, 2));
factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(1, 1));
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(org.apache.sling.models.testmodels.classes.OptionalPrimitivesModel.class, org.apache.sling.models.testmodels.interfaces.OptionalPrimitivesModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.OptionalPrimitivesModel.class);
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ org.apache.sling.models.testmodels.classes.OptionalPrimitivesModel.class,
+ org.apache.sling.models.testmodels.interfaces.OptionalPrimitivesModel.class,
+ org.apache.sling.models.testmodels.classes.constructorinjection.OptionalPrimitivesModel.class);
}
@Test
@@ -55,8 +60,8 @@ public class OptionalPrimitivesTest {
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
- org.apache.sling.models.testmodels.classes.OptionalPrimitivesModel model
- = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.OptionalPrimitivesModel.class);
+ org.apache.sling.models.testmodels.classes.OptionalPrimitivesModel model =
+ factory.getAdapter(res, org.apache.sling.models.testmodels.classes.OptionalPrimitivesModel.class);
assertNotNull(model);
// make sure primitives are initialized with initial value
@@ -78,7 +83,7 @@ public class OptionalPrimitivesTest {
assertNull(model.getDoubleObjectValue());
assertNull(model.getCharObjectValue());
assertNull(model.getBooleanObjectValue());
-}
+ }
@Test
public void testConstructorInjection() {
@@ -87,8 +92,10 @@ public class OptionalPrimitivesTest {
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(vm);
- org.apache.sling.models.testmodels.classes.constructorinjection.OptionalPrimitivesModel model
- = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.OptionalPrimitivesModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.OptionalPrimitivesModel model =
+ factory.getAdapter(
+ res,
+ org.apache.sling.models.testmodels.classes.constructorinjection.OptionalPrimitivesModel.class);
assertNotNull(model);
// make sure primitives are initialized with initial value
@@ -110,7 +117,7 @@ public class OptionalPrimitivesTest {
assertNull(model.getDoubleObjectValue());
assertNull(model.getCharObjectValue());
assertNull(model.getBooleanObjectValue());
-}
+ }
@Test
public void testFieldInjectionInterface() {
@@ -119,8 +126,8 @@ public class OptionalPrimitivesTest {
Resource res = mock(Resource.class);
lenient().when(res.adaptTo(ValueMap.class)).thenReturn(vm);
- org.apache.sling.models.testmodels.interfaces.OptionalPrimitivesModel model
- = factory.getAdapter(res, org.apache.sling.models.testmodels.interfaces.OptionalPrimitivesModel.class);
+ org.apache.sling.models.testmodels.interfaces.OptionalPrimitivesModel model =
+ factory.getAdapter(res, org.apache.sling.models.testmodels.interfaces.OptionalPrimitivesModel.class);
assertNotNull(model);
// make sure primitives are initialized with initial value
@@ -143,5 +150,4 @@ public class OptionalPrimitivesTest {
assertNull(model.getCharObjectValue());
assertNull(model.getBooleanObjectValue());
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/ParameterizedTypeFromRequestAttributeTest.java b/src/test/java/org/apache/sling/models/impl/ParameterizedTypeFromRequestAttributeTest.java
index 6564e7b..377815c 100644
--- a/src/test/java/org/apache/sling/models/impl/ParameterizedTypeFromRequestAttributeTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ParameterizedTypeFromRequestAttributeTest.java
@@ -18,15 +18,11 @@
*/
package org.apache.sling.models.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.when;
+import javax.inject.Inject;
import java.util.Collections;
import java.util.Iterator;
-import javax.inject.Inject;
-
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
@@ -37,6 +33,10 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class ParameterizedTypeFromRequestAttributeTest {
private ModelAdapterFactory factory;
@@ -55,7 +55,7 @@ public class ParameterizedTypeFromRequestAttributeTest {
@Test
public void test() {
- Iterator<Resource> it = Collections.<Resource> emptySet().iterator();
+ Iterator<Resource> it = Collections.<Resource>emptySet().iterator();
when(request.getAttribute("someResources")).thenReturn(it);
TestModel model = factory.getAdapter(request, TestModel.class);
diff --git a/src/test/java/org/apache/sling/models/impl/PostConstructTest.java b/src/test/java/org/apache/sling/models/impl/PostConstructTest.java
index a6eaeb3..e3c7af4 100644
--- a/src/test/java/org/apache/sling/models/impl/PostConstructTest.java
+++ b/src/test/java/org/apache/sling/models/impl/PostConstructTest.java
@@ -1,27 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.factory.PostConstructException;
import org.apache.sling.models.testmodels.classes.FailingPostConstructModel;
@@ -35,6 +31,12 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
@RunWith(MockitoJUnitRunner.class)
public class PostConstructTest {
@@ -47,7 +49,12 @@ public class PostConstructTest {
public void setup() {
factory = AdapterFactoryTest.createModelAdapterFactory();
// no injectors are necessary
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(SubClass.class, SubClassOverriddenPostConstruct.class, FailingPostConstructModel.class, FalsePostConstructModel.class, TruePostConstructModel.class);
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ SubClass.class,
+ SubClassOverriddenPostConstruct.class,
+ FailingPostConstructModel.class,
+ FalsePostConstructModel.class,
+ TruePostConstructModel.class);
}
@Test
@@ -60,8 +67,12 @@ public class PostConstructTest {
@Test
public void testOverriddenPostConstruct() {
SubClassOverriddenPostConstruct sc = factory.getAdapter(resource, SubClassOverriddenPostConstruct.class);
- assertEquals("Post construct not called exactly one time in sub class!", 1, sc.getPostConstructorCalledCounter());
- assertEquals("Post construct was called on super class although overridden in sub class", 0, sc.getPostConstructCalledTimestampInSuper());
+ assertEquals(
+ "Post construct not called exactly one time in sub class!", 1, sc.getPostConstructorCalledCounter());
+ assertEquals(
+ "Post construct was called on super class although overridden in sub class",
+ 0,
+ sc.getPostConstructCalledTimestampInSuper());
}
@Test
@@ -88,7 +99,9 @@ public class PostConstructTest {
}
public void testPostConstructMethodWhichReturnsFalseInternalCreateModel() {
- assertSame(Result.POST_CONSTRUCT_PREVENTED_MODEL_CONSTRUCTION, factory.internalCreateModel(resource, FalsePostConstructModel.class));
+ assertSame(
+ Result.POST_CONSTRUCT_PREVENTED_MODEL_CONSTRUCTION,
+ factory.internalCreateModel(resource, FalsePostConstructModel.class));
}
@Test
diff --git a/src/test/java/org/apache/sling/models/impl/RequestDisposalTest.java b/src/test/java/org/apache/sling/models/impl/RequestDisposalTest.java
index 61e3e0f..e754de6 100644
--- a/src/test/java/org/apache/sling/models/impl/RequestDisposalTest.java
+++ b/src/test/java/org/apache/sling/models/impl/RequestDisposalTest.java
@@ -1,27 +1,26 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.when;
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequestEvent;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Type;
@@ -30,10 +29,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import javax.inject.Inject;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletRequestEvent;
-
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;
@@ -51,6 +46,13 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class RequestDisposalTest {
@Mock
@@ -76,12 +78,16 @@ public class RequestDisposalTest {
doAnswer(new Answer<Void>() {
- @Override
- public Void answer(InvocationOnMock invocation) {
- attributes.put((String) invocation.getArguments()[0], invocation.getArguments()[1]);
- return null;
- }
- }).when(request).setAttribute(any(String.class), any());
+ @Override
+ public Void answer(InvocationOnMock invocation) {
+ attributes.put(
+ (String) invocation.getArguments()[0],
+ invocation.getArguments()[1]);
+ return null;
+ }
+ })
+ .when(request)
+ .setAttribute(any(String.class), any());
when(request.getAttribute(any(String.class))).then(new Answer<Object>() {
@@ -100,7 +106,8 @@ public class RequestDisposalTest {
factory.requestInitialized(new ServletRequestEvent(servletContext, destroyedRequest));
// but adapt from a wrapper of a wrapper of that wrapper
- SlingHttpServletRequest adaptableRequest = new SlingHttpServletRequestWrapper(new SlingHttpServletRequestWrapper(destroyedRequest));
+ SlingHttpServletRequest adaptableRequest =
+ new SlingHttpServletRequestWrapper(new SlingHttpServletRequestWrapper(destroyedRequest));
TestModel model = factory.getAdapter(adaptableRequest, TestModel.class);
assertEquals("teststring", model.testString);
@@ -119,7 +126,8 @@ public class RequestDisposalTest {
factory.requestInitialized(new ServletRequestEvent(servletContext, destroyedRequest));
// but adapt from a wrapper of a wrapper of that wrapper
- SlingHttpServletRequest adaptableRequest = new SlingHttpServletRequestWrapper(new SlingHttpServletRequestWrapper(destroyedRequest));
+ SlingHttpServletRequest adaptableRequest =
+ new SlingHttpServletRequestWrapper(new SlingHttpServletRequestWrapper(destroyedRequest));
TestModel model = factory.getAdapter(adaptableRequest, TestModel.class);
assertEquals("teststring", model.testString);
@@ -140,7 +148,8 @@ public class RequestDisposalTest {
SlingHttpServletRequest destroyedRequest = new SlingHttpServletRequestWrapper(request);
// but adapt from a wrapper of a wrapper of that wrapper
- SlingHttpServletRequest adaptableRequest = new SlingHttpServletRequestWrapper(new SlingHttpServletRequestWrapper(destroyedRequest));
+ SlingHttpServletRequest adaptableRequest =
+ new SlingHttpServletRequestWrapper(new SlingHttpServletRequestWrapper(destroyedRequest));
TestModel model = factory.getAdapter(adaptableRequest, TestModel.class);
assertEquals("teststring", model.testString);
@@ -169,7 +178,6 @@ public class RequestDisposalTest {
@Inject
public String testString;
-
}
private class DisposedInjector implements Injector {
@@ -181,7 +189,12 @@ public class RequestDisposalTest {
@Nullable
@Override
- public Object getValue(@NotNull Object o, String s, @NotNull Type type, @NotNull AnnotatedElement annotatedElement, @NotNull DisposalCallbackRegistry disposalCallbackRegistry) {
+ public Object getValue(
+ @NotNull Object o,
+ String s,
+ @NotNull Type type,
+ @NotNull AnnotatedElement annotatedElement,
+ @NotNull DisposalCallbackRegistry disposalCallbackRegistry) {
TestDisposalCallback callback = new TestDisposalCallback();
callbacks.add(callback);
disposalCallbackRegistry.addDisposalCallback(callback);
@@ -201,6 +214,4 @@ public class RequestDisposalTest {
return disposed;
}
}
-
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/RequestInjectionTest.java b/src/test/java/org/apache/sling/models/impl/RequestInjectionTest.java
index 41923a0..c5f317a 100644
--- a/src/test/java/org/apache/sling/models/impl/RequestInjectionTest.java
+++ b/src/test/java/org/apache/sling/models/impl/RequestInjectionTest.java
@@ -1,27 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.times;
-
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.api.scripting.SlingScriptHelper;
@@ -34,6 +30,12 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.LoggerFactory;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class RequestInjectionTest {
@@ -54,7 +56,9 @@ public class RequestInjectionTest {
factory = AdapterFactoryTest.createModelAdapterFactory();
factory.bindInjector(new BindingsInjector(), new ServicePropertiesMap(1, 1));
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(BindingsModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.BindingsModel.class);
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ BindingsModel.class,
+ org.apache.sling.models.testmodels.classes.constructorinjection.BindingsModel.class);
}
@Test
@@ -68,13 +72,12 @@ public class RequestInjectionTest {
@Test
public void testNamedInjectionConstructor() {
- org.apache.sling.models.testmodels.classes.constructorinjection.BindingsModel model
- = factory.getAdapter(request, org.apache.sling.models.testmodels.classes.constructorinjection.BindingsModel.class);
+ org.apache.sling.models.testmodels.classes.constructorinjection.BindingsModel model = factory.getAdapter(
+ request, org.apache.sling.models.testmodels.classes.constructorinjection.BindingsModel.class);
assertNotNull(model.getSling());
assertEquals(sling, model.getSling());
assertEquals("test", model.getLog().getName());
verify(request, times(1)).getAttribute(SlingBindings.class.getName());
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/RequestWrapperTest.java b/src/test/java/org/apache/sling/models/impl/RequestWrapperTest.java
index 04bef4d..0a1a6ff 100644
--- a/src/test/java/org/apache/sling/models/impl/RequestWrapperTest.java
+++ b/src/test/java/org/apache/sling/models/impl/RequestWrapperTest.java
@@ -1,34 +1,28 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Collections;
-
import javax.script.Bindings;
import javax.script.ScriptEngineFactory;
+import java.util.Collections;
+
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.adapter.AdapterManager;
import org.apache.sling.api.resource.Resource;
@@ -43,6 +37,14 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class RequestWrapperTest {
@@ -69,14 +71,16 @@ public class RequestWrapperTest {
factory = AdapterFactoryTest.createModelAdapterFactory();
factory.bindingsValuesProvidersByContext = bindingsValuesProvidersByContext;
factory.adapterManager = adapterManager;
- when(bindingsValuesProvidersByContext.getBindingsValuesProviders(any(ScriptEngineFactory.class), eq(BindingsValuesProvider.DEFAULT_CONTEXT))).
- thenReturn(Collections.singleton(bindingsValuesProvider));
+ when(bindingsValuesProvidersByContext.getBindingsValuesProviders(
+ any(ScriptEngineFactory.class), eq(BindingsValuesProvider.DEFAULT_CONTEXT)))
+ .thenReturn(Collections.singleton(bindingsValuesProvider));
}
@Test
public void testWrapper() {
Target expected = new Target();
- when(adapterManager.getAdapter(any(SlingHttpServletRequest.class), eq(Target.class))).thenReturn(expected);
+ when(adapterManager.getAdapter(any(SlingHttpServletRequest.class), eq(Target.class)))
+ .thenReturn(expected);
Target actual = factory.getModelFromWrappedRequest(request, resource, Target.class);
assertEquals(expected, actual);
@@ -103,8 +107,5 @@ public class RequestWrapperTest {
};
}
- class Target {
-
- }
-
+ class Target {}
}
diff --git a/src/test/java/org/apache/sling/models/impl/ResourceModelClassesTest.java b/src/test/java/org/apache/sling/models/impl/ResourceModelClassesTest.java
index f802baf..42488c2 100644
--- a/src/test/java/org/apache/sling/models/impl/ResourceModelClassesTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ResourceModelClassesTest.java
@@ -1,32 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-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.lenient;
-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;
import java.util.Collections;
@@ -60,6 +51,17 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
+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.lenient;
+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;
+
@SuppressWarnings("deprecation")
@RunWith(MockitoJUnitRunner.class)
public class ResourceModelClassesTest {
@@ -73,8 +75,10 @@ public class ResourceModelClassesTest {
factory.bindInjector(valueMapInjector, new ServicePropertiesMap(2, 2));
factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(1, 1));
- factory.injectAnnotationProcessorFactories = factory.injectAnnotationProcessorFactories = Collections.<InjectAnnotationProcessorFactory>singletonList(new ValueMapInjector());
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(SimplePropertyModel.class,
+ factory.injectAnnotationProcessorFactories = factory.injectAnnotationProcessorFactories =
+ Collections.<InjectAnnotationProcessorFactory>singletonList(new ValueMapInjector());
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ SimplePropertyModel.class,
ArrayWrappersModel.class,
ResourceModelWithRequiredField.class,
ChildValueMapModel.class,
@@ -94,7 +98,7 @@ public class ResourceModelClassesTest {
map.put("first", "first-value");
map.put("third", "third-value");
map.put("intProperty", new Integer(3));
- map.put("arrayProperty", new String[] { "three", "four" });
+ map.put("arrayProperty", new String[] {"three", "four"});
ValueMap vm = new ValueMapDecorator(map);
Resource res = mock(Resource.class);
@@ -119,7 +123,7 @@ public class ResourceModelClassesTest {
@Test
public void testArrayPrimitivesModel() {
Map<String, Object> map = new HashMap<>();
- map.put("intArray", new int[] { 1, 2, 9, 8 });
+ map.put("intArray", new int[] {1, 2, 9, 8});
map.put("secondIntArray", new Integer[] {1, 2, 9, 8});
ValueMap vm = new ValueMapDecorator(map);
@@ -194,12 +198,12 @@ public class ResourceModelClassesTest {
assertNotNull(model);
assertEquals(Arrays.asList("v1", "v2"), model.getStringList());
- assertEquals(Arrays.asList(1,2,3), model.getIntList());
- assertEquals(Arrays.asList(1L,2L), model.getLongList());
- assertEquals(Arrays.asList(true,false), model.getBooleanList());
- assertEquals(Arrays.asList((short)1), model.getShortList());
- assertEquals(Arrays.asList(1.1f,1.2f), model.getFloatList());
- assertEquals(Arrays.asList(1.1d,1.2d,1.3d), model.getDoubleList());
+ assertEquals(Arrays.asList(1, 2, 3), model.getIntList());
+ assertEquals(Arrays.asList(1L, 2L), model.getLongList());
+ assertEquals(Arrays.asList(true, false), model.getBooleanList());
+ assertEquals(Arrays.asList((short) 1), model.getShortList());
+ assertEquals(Arrays.asList(1.1f, 1.2f), model.getFloatList());
+ assertEquals(Arrays.asList(1.1d, 1.2d, 1.3d), model.getDoubleList());
}
@Test
@@ -213,11 +217,11 @@ public class ResourceModelClassesTest {
CollectionDefaultsModel model = factory.getAdapter(res, CollectionDefaultsModel.class);
assertNotNull(model);
- assertEquals(Arrays.asList(1,2,3), model.getIntCollection());
+ assertEquals(Arrays.asList(1, 2, 3), model.getIntCollection());
assertEquals(Arrays.asList("v1", "v2"), model.getStringCollection());
}
- @SuppressWarnings({ "unused", "null" })
+ @SuppressWarnings({"unused", "null"})
@Test
public void testRequiredPropertyModel() {
Map<String, Object> map = new HashMap<>();
@@ -248,7 +252,9 @@ public class ResourceModelClassesTest {
try {
factory.createModel(res, ResourceModelWithRequiredField.class);
} catch (MissingElementsException e) {
- assertEquals("required", ((Field) e.getMissingElements().iterator().next().getElement()).getName());
+ assertEquals(
+ "required",
+ ((Field) e.getMissingElements().iterator().next().getElement()).getName());
thrown = true;
}
assertTrue(thrown);
@@ -256,7 +262,7 @@ public class ResourceModelClassesTest {
verify(vm).get("required", String.class);
}
- @SuppressWarnings({ "unused", "null" })
+ @SuppressWarnings({"unused", "null"})
@Test
public void testRequiredPropertyMissingModelOptionalStrategy() {
Map<String, Object> map = new HashMap<>();
@@ -266,7 +272,8 @@ public class ResourceModelClassesTest {
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
- ResourceModelWithRequiredFieldOptionalStrategy model = factory.getAdapter(res, ResourceModelWithRequiredFieldOptionalStrategy.class);
+ ResourceModelWithRequiredFieldOptionalStrategy model =
+ factory.getAdapter(res, ResourceModelWithRequiredFieldOptionalStrategy.class);
assertNull(model);
verify(vm).get("optional1", String.class);
@@ -284,7 +291,8 @@ public class ResourceModelClassesTest {
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
- ResourceModelWithRequiredFieldOptionalStrategy model = factory.getAdapter(res, ResourceModelWithRequiredFieldOptionalStrategy.class);
+ ResourceModelWithRequiredFieldOptionalStrategy model =
+ factory.getAdapter(res, ResourceModelWithRequiredFieldOptionalStrategy.class);
assertNotNull(model);
assertEquals("required value", model.getRequired1());
assertEquals("required value", model.getRequired2());
@@ -301,8 +309,10 @@ public class ResourceModelClassesTest {
Resource firstGrandChild = mock(Resource.class);
Resource secondGrandChild = mock(Resource.class);
- when(secondChild.listChildren()).thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator());
- when(emptyChild.listChildren()).thenReturn(Collections.<Resource>emptySet().iterator());
+ when(secondChild.listChildren())
+ .thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator());
+ when(emptyChild.listChildren())
+ .thenReturn(Collections.<Resource>emptySet().iterator());
Resource res = mock(Resource.class);
when(res.getChild("firstChild")).thenReturn(child);
@@ -345,7 +355,8 @@ public class ResourceModelClassesTest {
Object firstGrandChildValue = RandomStringUtils.randomAlphabetic(10);
ValueMap firstGrandChildMap = new ValueMapDecorator(Collections.singletonMap("property", firstGrandChildValue));
Object secondGrandChildValue = RandomStringUtils.randomAlphabetic(10);
- ValueMap secondGrandChildMap = new ValueMapDecorator(Collections.singletonMap("property", secondGrandChildValue));
+ ValueMap secondGrandChildMap =
+ new ValueMapDecorator(Collections.singletonMap("property", secondGrandChildValue));
final Resource firstGrandChild = mock(Resource.class);
lenient().when(firstGrandChild.adaptTo(ValueMap.class)).thenReturn(firstGrandChildMap);
@@ -356,10 +367,14 @@ public class ResourceModelClassesTest {
lenient().when(secondGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel());
Resource secondChild = mock(Resource.class);
- lenient().when(secondChild.listChildren()).thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator());
+ lenient()
+ .when(secondChild.listChildren())
+ .thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator());
Resource emptyChild = mock(Resource.class);
- lenient().when(emptyChild.listChildren()).thenReturn(Collections.<Resource>emptySet().iterator());
+ lenient()
+ .when(emptyChild.listChildren())
+ .thenReturn(Collections.<Resource>emptySet().iterator());
Resource res = mock(Resource.class);
lenient().when(res.getChild("firstChild")).thenReturn(firstChild);
@@ -385,5 +400,4 @@ public class ResourceModelClassesTest {
return factory.getAdapter(invocation.getMock(), ChildModel.class);
}
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/ResourceModelConstructorTest.java b/src/test/java/org/apache/sling/models/impl/ResourceModelConstructorTest.java
index 55164b9..e382bc6 100644
--- a/src/test/java/org/apache/sling/models/impl/ResourceModelConstructorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ResourceModelConstructorTest.java
@@ -1,26 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.mock;
-
import java.util.Arrays;
import java.util.Collections;
@@ -39,6 +36,11 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+
@RunWith(MockitoJUnitRunner.class)
public class ResourceModelConstructorTest {
@@ -64,7 +66,8 @@ public class ResourceModelConstructorTest {
Object firstGrandChildValue = RandomStringUtils.randomAlphabetic(10);
ValueMap firstGrandChildMap = new ValueMapDecorator(Collections.singletonMap("property", firstGrandChildValue));
Object secondGrandChildValue = RandomStringUtils.randomAlphabetic(10);
- ValueMap secondGrandChildMap = new ValueMapDecorator(Collections.singletonMap("property", secondGrandChildValue));
+ ValueMap secondGrandChildMap =
+ new ValueMapDecorator(Collections.singletonMap("property", secondGrandChildValue));
final Resource firstGrandChild = mock(Resource.class);
lenient().when(firstGrandChild.adaptTo(ValueMap.class)).thenReturn(firstGrandChildMap);
@@ -75,10 +78,14 @@ public class ResourceModelConstructorTest {
lenient().when(secondGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel());
Resource secondChild = mock(Resource.class);
- lenient().when(secondChild.listChildren()).thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator());
+ lenient()
+ .when(secondChild.listChildren())
+ .thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator());
Resource emptyChild = mock(Resource.class);
- lenient().when(emptyChild.listChildren()).thenReturn(Collections.<Resource>emptySet().iterator());
+ lenient()
+ .when(emptyChild.listChildren())
+ .thenReturn(Collections.<Resource>emptySet().iterator());
Resource res = mock(Resource.class);
lenient().when(res.getChild("firstChild")).thenReturn(firstChild);
@@ -104,5 +111,4 @@ public class ResourceModelConstructorTest {
return factory.getAdapter(invocation.getMock(), ChildModel.class);
}
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/ResourceModelInterfacesTest.java b/src/test/java/org/apache/sling/models/impl/ResourceModelInterfacesTest.java
index 155aee9..aa5333a 100644
--- a/src/test/java/org/apache/sling/models/impl/ResourceModelInterfacesTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ResourceModelInterfacesTest.java
@@ -1,32 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-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.lenient;
-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;
import java.util.HashMap;
@@ -51,6 +42,17 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
+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.lenient;
+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;
+
@RunWith(MockitoJUnitRunner.class)
public class ResourceModelInterfacesTest {
@@ -61,7 +63,13 @@ public class ResourceModelInterfacesTest {
factory = AdapterFactoryTest.createModelAdapterFactory();
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
@@ -86,7 +94,7 @@ public class ResourceModelInterfacesTest {
}
@Test
- @SuppressWarnings({ "unused", "null" })
+ @SuppressWarnings({"unused", "null"})
public void testRequiredPropertyModel() {
Map<String, Object> map = new HashMap<>();
map.put("first", "first-value");
@@ -142,7 +150,8 @@ public class ResourceModelInterfacesTest {
Object firstGrandChildValue = RandomStringUtils.randomAlphabetic(10);
ValueMap firstGrandChildMap = new ValueMapDecorator(Collections.singletonMap("property", firstGrandChildValue));
Object secondGrandChildValue = RandomStringUtils.randomAlphabetic(10);
- ValueMap secondGrandChildMap = new ValueMapDecorator(Collections.singletonMap("property", secondGrandChildValue));
+ ValueMap secondGrandChildMap =
+ new ValueMapDecorator(Collections.singletonMap("property", secondGrandChildValue));
final Resource firstGrandChild = mock(Resource.class);
lenient().when(firstGrandChild.adaptTo(ValueMap.class)).thenReturn(firstGrandChildMap);
@@ -153,10 +162,14 @@ public class ResourceModelInterfacesTest {
lenient().when(secondGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel());
Resource secondChild = mock(Resource.class);
- lenient().when(secondChild.listChildren()).thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator());
+ lenient()
+ .when(secondChild.listChildren())
+ .thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator());
Resource emptyChild = mock(Resource.class);
- lenient().when(emptyChild.listChildren()).thenReturn(Collections.<Resource>emptySet().iterator());
+ lenient()
+ .when(emptyChild.listChildren())
+ .thenReturn(Collections.<Resource>emptySet().iterator());
Resource res = mock(Resource.class);
lenient().when(res.getChild("firstChild")).thenReturn(firstChild);
@@ -182,5 +195,4 @@ public class ResourceModelInterfacesTest {
return factory.getAdapter(invocation.getMock(), ChildModel.class);
}
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/ResourcePathInjectionTest.java b/src/test/java/org/apache/sling/models/impl/ResourcePathInjectionTest.java
index 73d1d66..2fd93b1 100644
--- a/src/test/java/org/apache/sling/models/impl/ResourcePathInjectionTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ResourcePathInjectionTest.java
@@ -18,14 +18,6 @@
*/
package org.apache.sling.models.impl;
-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.lenient;
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.doReturn;
-
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -48,6 +40,14 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+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.doReturn;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class ResourcePathInjectionTest {
private ModelAdapterFactory factory;
@@ -78,15 +78,15 @@ public class ResourcePathInjectionTest {
Map<String, Object> map = new HashMap<String, Object>();
map.put("propertyContainingAPath", "/some/other/path");
map.put("anotherPropertyContainingAPath", "/some/other/path2");
- String[] paths= new String[2];
- paths[0]="/some/other/path";
- paths[1]="/some/other/path2";
-
- String[] invalidPaths= new String[3];
- invalidPaths[0]="/does/not/exist";
- invalidPaths[1]="/does/not/exist2";
- invalidPaths[2]="/some/other/path";
- map.put("propertyWithSeveralPaths",paths);
+ String[] paths = new String[2];
+ paths[0] = "/some/other/path";
+ paths[1] = "/some/other/path2";
+
+ String[] invalidPaths = new String[3];
+ invalidPaths[0] = "/does/not/exist";
+ invalidPaths[1] = "/does/not/exist2";
+ invalidPaths[2] = "/some/other/path";
+ map.put("propertyWithSeveralPaths", paths);
map.put("propertyWithMissingPaths", invalidPaths);
ValueMap properties = new ValueMapDecorator(map);
@@ -106,9 +106,13 @@ public class ResourcePathInjectionTest {
factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(1, Integer.MAX_VALUE));
factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(2, 2000));
factory.bindInjector(new ResourcePathInjector(), new ServicePropertiesMap(3, 2500));
- factory.bindStaticInjectAnnotationProcessorFactory(new ResourcePathInjector(), new ServicePropertiesMap(3, 2500));
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(ResourcePathModel.class, ResourcePathPartialModel.class,
- ResourcePathAllOptionalModel.class, ResourcePathModelWrapping.class);
+ factory.bindStaticInjectAnnotationProcessorFactory(
+ new ResourcePathInjector(), new ServicePropertiesMap(3, 2500));
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ ResourcePathModel.class,
+ ResourcePathPartialModel.class,
+ ResourcePathAllOptionalModel.class,
+ ResourcePathModelWrapping.class);
}
@Test
@@ -149,24 +153,26 @@ public class ResourcePathInjectionTest {
public void testMultiplePathInjection() {
ResourcePathModel model = factory.getAdapter(adaptableResource, ResourcePathModel.class);
assertNotNull(model);
- List<Resource> resources=model.getMultipleResources();
+ List<Resource> resources = model.getMultipleResources();
assertNotNull(resources);
- assertEquals(2,resources.size());
+ assertEquals(2, resources.size());
assertEquals(byPropertyValueResource, resources.get(0));
assertEquals(byPropertyValueResource2, resources.get(1));
- List<Resource> resourcesFromPathAnnotation= model.getManyFromPath();
+ List<Resource> resourcesFromPathAnnotation = model.getManyFromPath();
assertNotNull(resourcesFromPathAnnotation);
assertEquals(byPathResource, resourcesFromPathAnnotation.get(0));
assertEquals(byPathResource2, resourcesFromPathAnnotation.get(1));
- List<Resource> resourcesFromResourcePathAnnotation= model.getManyFromPath2();
+ List<Resource> resourcesFromResourcePathAnnotation = model.getManyFromPath2();
assertNotNull(resourcesFromResourcePathAnnotation);
assertEquals(byPathResource2, resourcesFromResourcePathAnnotation.get(0));
assertEquals(byPathResource, resourcesFromResourcePathAnnotation.get(1));
assertNotNull(model.getPropertyWithSeveralPaths());
- assertEquals(byPropertyValueResource, model.getPropertyWithSeveralPaths().get(0));
- assertEquals(byPropertyValueResource2, model.getPropertyWithSeveralPaths().get(1));
+ assertEquals(
+ byPropertyValueResource, model.getPropertyWithSeveralPaths().get(0));
+ assertEquals(
+ byPropertyValueResource2, model.getPropertyWithSeveralPaths().get(1));
}
@Test
@@ -193,5 +199,4 @@ public class ResourcePathInjectionTest {
assertTrue(model.getFromPath().length > 0);
assertTrue(model.getMultipleResources().length > 0);
}
-
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/sling/models/impl/SelfDependencyTest.java b/src/test/java/org/apache/sling/models/impl/SelfDependencyTest.java
index 1f0973f..58fc9d7 100644
--- a/src/test/java/org/apache/sling/models/impl/SelfDependencyTest.java
+++ b/src/test/java/org/apache/sling/models/impl/SelfDependencyTest.java
@@ -1,27 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.lenient;
-
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.impl.injectors.SelfInjector;
import org.apache.sling.models.testmodels.classes.DirectCyclicSelfDependencyModel;
@@ -37,6 +33,12 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.lenient;
+
@RunWith(MockitoJUnitRunner.class)
public class SelfDependencyTest {
@@ -58,7 +60,12 @@ public class SelfDependencyTest {
factory = AdapterFactoryTest.createModelAdapterFactory();
factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(1, 1));
- factory.adapterImplementations.addClassesAsAdapterAndImplementation(SelfDependencyModelA.class, SelfDependencyModelB.class, DirectCyclicSelfDependencyModel.class, IndirectCyclicSelfDependencyModelA.class, IndirectCyclicSelfDependencyModelB.class);
+ factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+ SelfDependencyModelA.class,
+ SelfDependencyModelB.class,
+ DirectCyclicSelfDependencyModel.class,
+ IndirectCyclicSelfDependencyModelA.class,
+ IndirectCyclicSelfDependencyModelB.class);
}
@Test
@@ -78,9 +85,8 @@ public class SelfDependencyTest {
@Test
public void testInddirectCyclicSelfDependency() {
- IndirectCyclicSelfDependencyModelA object = factory.getAdapter(request,
- IndirectCyclicSelfDependencyModelA.class);
+ IndirectCyclicSelfDependencyModelA object =
+ factory.getAdapter(request, IndirectCyclicSelfDependencyModelA.class);
assertNull(object);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/ServicePropertiesMap.java b/src/test/java/org/apache/sling/models/impl/ServicePropertiesMap.java
index d424e5c..2cfa998 100644
--- a/src/test/java/org/apache/sling/models/impl/ServicePropertiesMap.java
+++ b/src/test/java/org/apache/sling/models/impl/ServicePropertiesMap.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -22,11 +24,10 @@ import org.osgi.framework.Constants;
@SuppressWarnings("serial")
public class ServicePropertiesMap extends HashMap<String, Object> {
-
+
public ServicePropertiesMap(long serviceId, int serviceRanking) {
super();
put(Constants.SERVICE_ID, serviceId);
put(Constants.SERVICE_RANKING, serviceRanking);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/StaticInjectionAPFLoadOrderTest.java b/src/test/java/org/apache/sling/models/impl/StaticInjectionAPFLoadOrderTest.java
index 24bcb63..71090ac 100644
--- a/src/test/java/org/apache/sling/models/impl/StaticInjectionAPFLoadOrderTest.java
+++ b/src/test/java/org/apache/sling/models/impl/StaticInjectionAPFLoadOrderTest.java
@@ -18,10 +18,6 @@
*/
package org.apache.sling.models.impl;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.adapter.AdapterManager;
import org.apache.sling.api.resource.ResourceResolver;
@@ -39,17 +35,22 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
/**
* Test load order behavior of StaticInjectionAnnotationProcesssorFactory instances (SLING-5010).
*/
@RunWith(MockitoJUnitRunner.class)
public class StaticInjectionAPFLoadOrderTest {
-
+
@Rule
public OsgiContext context = new OsgiContext();
-
+
@Mock
private SlingHttpServletRequest request;
+
@Mock
private ResourceResolver resourceResolver;
@@ -58,14 +59,14 @@ public class StaticInjectionAPFLoadOrderTest {
@Mock
private AdapterManager adapterManager;
-
+
private ModelAdapterFactory factory;
-
+
@Before
public void setUp() {
registerServices();
}
-
+
/**
* Registration order: 1. ModelFactory, 2. custom injector, 3. model
*/
@@ -75,24 +76,24 @@ public class StaticInjectionAPFLoadOrderTest {
registerCustomInjector();
registerModel();
-
+
// this should not throw an exception because resourceResovler is marked as optional
assertFalse(createModel().hasResourceResolver());
}
-
+
/**
* Registration order: 1. ModelFactory, 2. custom injector, 3. model
*/
@Test
public void testFactory_Injector_Model_WithResourceResolver() {
when(request.getResourceResolver()).thenReturn(resourceResolver);
-
+
registerCustomInjector();
registerModel();
-
+
assertTrue(createModel().hasResourceResolver());
}
-
+
/**
* Registration order: 1. ModelFactory, 2. model, 3. custom injector
*/
@@ -102,24 +103,24 @@ public class StaticInjectionAPFLoadOrderTest {
registerModel();
registerCustomInjector();
-
+
// this should not throw an exception because resourceResovler is marked as optional
assertFalse(createModel().hasResourceResolver());
}
-
+
/**
* Registration order: 1. ModelFactory, 2. model, 3. custom injector
*/
@Test
public void testFactory_Model_Injector_WithResourceResolver() {
when(request.getResourceResolver()).thenReturn(resourceResolver);
-
+
registerModel();
registerCustomInjector();
-
+
assertTrue(createModel().hasResourceResolver());
}
-
+
private void registerServices() {
context.registerService(BindingsValuesProvidersByContext.class, bindingsValuesProvidersByContext);
context.registerService(AdapterManager.class, adapterManager);
@@ -137,18 +138,15 @@ public class StaticInjectionAPFLoadOrderTest {
private TestModel createModel() {
return factory.createModel(request, TestModel.class);
}
-
-
+
@Model(adaptables = SlingHttpServletRequest.class)
public static class TestModel {
-
+
@SlingObject(injectionStrategy = InjectionStrategy.OPTIONAL)
private ResourceResolver resourceResolver;
-
+
public boolean hasResourceResolver() {
return resourceResolver != null;
}
-
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/ViaTest.java b/src/test/java/org/apache/sling/models/impl/ViaTest.java
index e72a6b5..d02aee9 100644
--- a/src/test/java/org/apache/sling/models/impl/ViaTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ViaTest.java
@@ -1,25 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.when;
-
import java.util.Collections;
import org.apache.commons.lang3.RandomStringUtils;
@@ -38,6 +36,10 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class ViaTest {
@@ -67,7 +69,7 @@ public class ViaTest {
@Test
public void testProjectionToResource() {
String value = RandomStringUtils.randomAlphanumeric(10);
- ValueMap map = new ValueMapDecorator(Collections.<String, Object> singletonMap("firstProperty", value));
+ ValueMap map = new ValueMapDecorator(Collections.<String, Object>singletonMap("firstProperty", value));
when(resource.adaptTo(ValueMap.class)).thenReturn(map);
ViaModel model = factory.getAdapter(request, ViaModel.class);
@@ -78,11 +80,10 @@ public class ViaTest {
@Test
public void testProjectionToChildResource() {
String value = RandomStringUtils.randomAlphanumeric(10);
- ValueMap map = new ValueMapDecorator(Collections.<String, Object> singletonMap("firstProperty", value));
+ ValueMap map = new ValueMapDecorator(Collections.<String, Object>singletonMap("firstProperty", value));
when(childResource.adaptTo(ValueMap.class)).thenReturn(map);
ChildResourceViaModel model = factory.getAdapter(resource, ChildResourceViaModel.class);
assertNotNull(model);
assertEquals(value, model.getFirstProperty());
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/implpicker/FirstImplementationPickerTest.java b/src/test/java/org/apache/sling/models/impl/implpicker/FirstImplementationPickerTest.java
index 1bc8cfb..6cdf3db 100644
--- a/src/test/java/org/apache/sling/models/impl/implpicker/FirstImplementationPickerTest.java
+++ b/src/test/java/org/apache/sling/models/impl/implpicker/FirstImplementationPickerTest.java
@@ -18,13 +18,13 @@
*/
package org.apache.sling.models.impl.implpicker;
-import static org.junit.Assert.assertEquals;
-
import org.apache.sling.models.impl.FirstImplementationPicker;
import org.apache.sling.models.spi.ImplementationPicker;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class FirstImplementationPickerTest {
private static final Class<?> SAMPLE_ADAPTER = Comparable.class;
@@ -39,14 +39,13 @@ public class FirstImplementationPickerTest {
@Test
public void testPickOneImplementation() {
- Class<?>[] implementations = new Class<?>[] { String.class };
+ Class<?>[] implementations = new Class<?>[] {String.class};
assertEquals(String.class, underTest.pick(SAMPLE_ADAPTER, implementations, SAMPLE_ADAPTABLE));
}
@Test
public void testPickMultipleImplementations() {
- Class<?>[] implementations = new Class<?>[] { Integer.class, Long.class, String.class };
+ Class<?>[] implementations = new Class<?>[] {Integer.class, Long.class, String.class};
assertEquals(Integer.class, underTest.pick(SAMPLE_ADAPTER, implementations, SAMPLE_ADAPTABLE));
}
-
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotation.java b/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotation.java
index a2c9c55..e821a8f 100644
--- a/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotation.java
+++ b/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotation.java
@@ -1,32 +1,32 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.injector;
-import static java.lang.annotation.ElementType.*;
-import static java.lang.annotation.RetentionPolicy.*;
-
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
-@Target({ METHOD, FIELD })
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+@Target({METHOD, FIELD})
@Retention(RUNTIME)
@InjectAnnotation
-public @interface CustomAnnotation {
-
-}
+public @interface CustomAnnotation {}
diff --git a/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotationInjector.java b/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotationInjector.java
index 84c61ae..8adf0ef 100644
--- a/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotationInjector.java
+++ b/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotationInjector.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.injector;
@@ -35,7 +37,11 @@ public class CustomAnnotationInjector implements Injector, InjectAnnotationProce
}
@Override
- public Object getValue(@NotNull Object adaptable, String name, @NotNull Type declaredType, @NotNull AnnotatedElement element,
+ public Object getValue(
+ @NotNull Object adaptable,
+ String name,
+ @NotNull Type declaredType,
+ @NotNull AnnotatedElement element,
@NotNull DisposalCallbackRegistry callbackRegistry) {
if (name.equals("customString")) {
return "custom value";
@@ -65,5 +71,4 @@ public class CustomAnnotationInjector implements Injector, InjectAnnotationProce
return "default value";
}
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/injector/SimpleInjector.java b/src/test/java/org/apache/sling/models/impl/injector/SimpleInjector.java
index 3b97ae9..6c4e19c 100644
--- a/src/test/java/org/apache/sling/models/impl/injector/SimpleInjector.java
+++ b/src/test/java/org/apache/sling/models/impl/injector/SimpleInjector.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.injector;
@@ -31,7 +33,11 @@ public class SimpleInjector implements Injector {
}
@Override
- public Object getValue(@NotNull Object adaptable, String name, @NotNull Type declaredType, @NotNull AnnotatedElement element,
+ public Object getValue(
+ @NotNull Object adaptable,
+ String name,
+ @NotNull Type declaredType,
+ @NotNull AnnotatedElement element,
@NotNull DisposalCallbackRegistry callbackRegistry) {
if (name.equals("testString") && declaredType.equals(String.class)) {
return "test string";
@@ -39,5 +45,4 @@ public class SimpleInjector implements Injector {
return null;
}
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/injectors/BindingsInjectorTest.java b/src/test/java/org/apache/sling/models/impl/injectors/BindingsInjectorTest.java
index b499079..f20d5a0 100644
--- a/src/test/java/org/apache/sling/models/impl/injectors/BindingsInjectorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/injectors/BindingsInjectorTest.java
@@ -18,13 +18,10 @@
*/
package org.apache.sling.models.impl.injectors;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import javax.servlet.ServletRequest;
import java.lang.reflect.AnnotatedElement;
-import javax.servlet.ServletRequest;
-
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.models.spi.DisposalCallbackRegistry;
@@ -34,6 +31,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
@RunWith(MockitoJUnitRunner.class)
public class BindingsInjectorTest {
@@ -41,10 +41,13 @@ public class BindingsInjectorTest {
@Mock
private ServletRequest request;
+
@Mock
private SlingBindings bindings;
+
@Mock
private AnnotatedElement element;
+
@Mock
private DisposalCallbackRegistry registry;
@@ -93,5 +96,4 @@ public class BindingsInjectorTest {
Object result = injector.getValue(request, STRING_PARAM, String.class, element, registry);
assertNull(result);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/injectors/RequestAttributeInjectorTest.java b/src/test/java/org/apache/sling/models/impl/injectors/RequestAttributeInjectorTest.java
index a3ae8dc..1683e80 100644
--- a/src/test/java/org/apache/sling/models/impl/injectors/RequestAttributeInjectorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/injectors/RequestAttributeInjectorTest.java
@@ -18,13 +18,10 @@
*/
package org.apache.sling.models.impl.injectors;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import javax.servlet.ServletRequest;
import java.lang.reflect.AnnotatedElement;
-import javax.servlet.ServletRequest;
-
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.spi.DisposalCallbackRegistry;
import org.junit.Before;
@@ -33,25 +30,30 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
@RunWith(MockitoJUnitRunner.class)
public class RequestAttributeInjectorTest {
private RequestAttributeInjector injector = new RequestAttributeInjector();
-
+
@Mock
private ServletRequest request;
+
@Mock
private AnnotatedElement element;
+
@Mock
private DisposalCallbackRegistry registry;
-
+
private static final String STRING_PARAM = "param1";
private static final String INTEGER_PARAM = "param2";
private static final String CLASS_PARAM = "param3";
private static final String STRING_VALUE = "myValue";
private static final int INTEGER_VALUE = 42;
private static final ResourceResolver CLASS_INSTANCE = mock(ResourceResolver.class);
-
+
@Before
public void setUp() {
when(request.getAttribute(STRING_PARAM)).thenReturn(STRING_VALUE);
diff --git a/src/test/java/org/apache/sling/models/impl/injectors/ResourceResolverInjectorTest.java b/src/test/java/org/apache/sling/models/impl/injectors/ResourceResolverInjectorTest.java
index f8776ce..142c1a0 100644
--- a/src/test/java/org/apache/sling/models/impl/injectors/ResourceResolverInjectorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/injectors/ResourceResolverInjectorTest.java
@@ -18,9 +18,6 @@
*/
package org.apache.sling.models.impl.injectors;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
import java.lang.reflect.AnnotatedElement;
import org.apache.sling.api.SlingHttpServletRequest;
@@ -33,6 +30,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
/**
* This was a unit test for the ResourceResolverInjector which is now removed
* because it is obsolete due to the SlingObjectInjector.
@@ -43,9 +43,10 @@ import org.mockito.junit.MockitoJUnitRunner;
public class ResourceResolverInjectorTest {
private SlingObjectInjector injector = new SlingObjectInjector();
-
+
@Mock
private AnnotatedElement element;
+
@Mock
private DisposalCallbackRegistry registry;
@@ -76,5 +77,4 @@ public class ResourceResolverInjectorTest {
Object result = injector.getValue(response, "resourceResolver", ResourceResolver.class, element, registry);
assertNull(result);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java b/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java
index 02a790d..023a63c 100644
--- a/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java
@@ -18,16 +18,11 @@
*/
package org.apache.sling.models.impl.injectors;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.when;
+import javax.servlet.http.HttpServletRequest;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
-import javax.servlet.http.HttpServletRequest;
-
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
@@ -42,6 +37,11 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class SelfInjectorTest {
@@ -65,45 +65,104 @@ public class SelfInjectorTest {
@Before
public void setup() {
lenient().when(modelAnnotation.defaultInjectionStrategy()).thenReturn(DefaultInjectionStrategy.REQUIRED);
- firstConstructorParameter = new ConstructorParameter(new Annotation[0], Object.class, Object.class, true, 0,
- new StaticInjectAnnotationProcessorFactory[0], null);
- secondConstructorParameter = new ConstructorParameter(new Annotation[0], Object.class, Object.class, true, 1,
- new StaticInjectAnnotationProcessorFactory[0], null);
+ firstConstructorParameter = new ConstructorParameter(
+ new Annotation[0],
+ Object.class,
+ Object.class,
+ true,
+ 0,
+ new StaticInjectAnnotationProcessorFactory[0],
+ null);
+ secondConstructorParameter = new ConstructorParameter(
+ new Annotation[0],
+ Object.class,
+ Object.class,
+ true,
+ 1,
+ new StaticInjectAnnotationProcessorFactory[0],
+ null);
}
@Test
public void testMatchingClass() {
- assertSame(request, injector.getValue(request, "notRelevant", SlingHttpServletRequest.class, firstConstructorParameter.getAnnotatedElement(), registry));
- assertNull(injector.getValue(request, "notRelevant", SlingHttpServletRequest.class, secondConstructorParameter.getAnnotatedElement(), registry));
- assertNull(injector.getValue(request, "notRelevant", SlingHttpServletRequest.class, annotatedElement, registry));
+ assertSame(
+ request,
+ injector.getValue(
+ request,
+ "notRelevant",
+ SlingHttpServletRequest.class,
+ firstConstructorParameter.getAnnotatedElement(),
+ registry));
+ assertNull(injector.getValue(
+ request,
+ "notRelevant",
+ SlingHttpServletRequest.class,
+ secondConstructorParameter.getAnnotatedElement(),
+ registry));
+ assertNull(
+ injector.getValue(request, "notRelevant", SlingHttpServletRequest.class, annotatedElement, registry));
}
@Test
public void testMatchingSubClass() {
- assertSame(request, injector.getValue(request, "notRelevant", HttpServletRequest.class, firstConstructorParameter.getAnnotatedElement(), registry));
- assertNull(injector.getValue(request, "notRelevant", HttpServletRequest.class, secondConstructorParameter.getAnnotatedElement(), registry));
+ assertSame(
+ request,
+ injector.getValue(
+ request,
+ "notRelevant",
+ HttpServletRequest.class,
+ firstConstructorParameter.getAnnotatedElement(),
+ registry));
+ assertNull(injector.getValue(
+ request,
+ "notRelevant",
+ HttpServletRequest.class,
+ secondConstructorParameter.getAnnotatedElement(),
+ registry));
assertNull(injector.getValue(request, "notRelevant", HttpServletRequest.class, annotatedElement, registry));
}
@Test
public void testNotMatchingClass() {
- assertNull(injector.getValue(request, "notRelevant", ResourceResolver.class, firstConstructorParameter.getAnnotatedElement(), registry));
- assertNull(injector.getValue(request, "notRelevant", ResourceResolver.class, secondConstructorParameter.getAnnotatedElement(), registry));
+ assertNull(injector.getValue(
+ request,
+ "notRelevant",
+ ResourceResolver.class,
+ firstConstructorParameter.getAnnotatedElement(),
+ registry));
+ assertNull(injector.getValue(
+ request,
+ "notRelevant",
+ ResourceResolver.class,
+ secondConstructorParameter.getAnnotatedElement(),
+ registry));
assertNull(injector.getValue(request, "notRelevant", ResourceResolver.class, annotatedElement, registry));
}
@Test
public void testWithNullName() {
- assertSame(request, injector.getValue(request, null, SlingHttpServletRequest.class, firstConstructorParameter.getAnnotatedElement(), registry));
- assertNull(injector.getValue(request, null, SlingHttpServletRequest.class, secondConstructorParameter.getAnnotatedElement(), registry));
+ assertSame(
+ request,
+ injector.getValue(
+ request,
+ null,
+ SlingHttpServletRequest.class,
+ firstConstructorParameter.getAnnotatedElement(),
+ registry));
+ assertNull(injector.getValue(
+ request,
+ null,
+ SlingHttpServletRequest.class,
+ secondConstructorParameter.getAnnotatedElement(),
+ registry));
assertNull(injector.getValue(request, null, SlingHttpServletRequest.class, annotatedElement, registry));
}
@Test
public void testMatchingClassWithSelfAnnotation() {
when(annotatedElement.isAnnotationPresent(Self.class)).thenReturn(true);
- Object result = injector
- .getValue(request, "notRelevant", SlingHttpServletRequest.class, annotatedElement, registry);
+ Object result =
+ injector.getValue(request, "notRelevant", SlingHttpServletRequest.class, annotatedElement, registry);
assertSame(request, result);
}
@@ -113,5 +172,4 @@ public class SelfInjectorTest {
Object result = injector.getValue(request, "notRelevant", ResourceResolver.class, annotatedElement, registry);
assertSame(request, result);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorRequestTest.java b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorRequestTest.java
index 93aab11..589f5c3 100644
--- a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorRequestTest.java
+++ b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorRequestTest.java
@@ -18,14 +18,11 @@
*/
package org.apache.sling.models.impl.injectors;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
-import java.lang.reflect.AnnotatedElement;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.AnnotatedElement;
+
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
@@ -40,6 +37,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
@RunWith(MockitoJUnitRunner.class)
public class SlingObjectInjectorRequestTest {
@@ -47,16 +47,22 @@ public class SlingObjectInjectorRequestTest {
@Mock
private AnnotatedElement annotatedElement;
+
@Mock
private SlingHttpServletRequest request;
+
@Mock
private SlingHttpServletResponse response;
+
@Mock
private SlingScriptHelper scriptHelper;
+
@Mock
private ResourceResolver resourceResolver;
+
@Mock
private Resource resource;
+
@Mock
private DisposalCallbackRegistry registry;
@@ -72,7 +78,8 @@ public class SlingObjectInjectorRequestTest {
@Test
public void testResourceResolver() {
- Object result = this.injector.getValue(this.request, null, ResourceResolver.class, this.annotatedElement, registry);
+ Object result =
+ this.injector.getValue(this.request, null, ResourceResolver.class, this.annotatedElement, registry);
assertSame(this.resourceResolver, result);
}
@@ -88,8 +95,8 @@ public class SlingObjectInjectorRequestTest {
@Test
public void testRequest() {
- Object result = this.injector.getValue(this.request, null, SlingHttpServletRequest.class,
- this.annotatedElement, registry);
+ Object result = this.injector.getValue(
+ this.request, null, SlingHttpServletRequest.class, this.annotatedElement, registry);
assertSame(this.request, result);
result = this.injector.getValue(this.request, null, HttpServletRequest.class, this.annotatedElement, registry);
@@ -98,8 +105,8 @@ public class SlingObjectInjectorRequestTest {
@Test
public void testResponse() {
- Object result = this.injector.getValue(this.request, null, SlingHttpServletResponse.class,
- this.annotatedElement, registry);
+ Object result = this.injector.getValue(
+ this.request, null, SlingHttpServletResponse.class, this.annotatedElement, registry);
assertSame(this.response, result);
result = this.injector.getValue(this.request, null, HttpServletResponse.class, this.annotatedElement, registry);
@@ -108,8 +115,8 @@ public class SlingObjectInjectorRequestTest {
@Test
public void testScriptHelper() {
- Object result = this.injector
- .getValue(this.request, null, SlingScriptHelper.class, this.annotatedElement, registry);
+ Object result =
+ this.injector.getValue(this.request, null, SlingScriptHelper.class, this.annotatedElement, registry);
assertSame(this.scriptHelper, result);
}
@@ -118,5 +125,4 @@ public class SlingObjectInjectorRequestTest {
Object result = this.injector.getValue(this, null, SlingScriptHelper.class, this.annotatedElement, registry);
assertNull(result);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceResolverTest.java b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceResolverTest.java
index d2379a8..4176150 100644
--- a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceResolverTest.java
@@ -18,9 +18,6 @@
*/
package org.apache.sling.models.impl.injectors;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-
import java.lang.reflect.AnnotatedElement;
import org.apache.sling.api.SlingHttpServletResponse;
@@ -33,6 +30,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
@RunWith(MockitoJUnitRunner.class)
public class SlingObjectInjectorResourceResolverTest {
@@ -40,43 +40,45 @@ public class SlingObjectInjectorResourceResolverTest {
@Mock
private AnnotatedElement annotatedElement;
+
@Mock
private ResourceResolver resourceResolver;
+
@Mock
private DisposalCallbackRegistry registry;
@Test
public void testResourceResolver() {
- Object result = this.injector.getValue(this.resourceResolver, null, ResourceResolver.class,
- this.annotatedElement, registry);
+ Object result = this.injector.getValue(
+ this.resourceResolver, null, ResourceResolver.class, this.annotatedElement, registry);
assertSame(this.resourceResolver, result);
}
@Test
public void testResource() {
- Object result = this.injector
- .getValue(this.resourceResolver, null, Resource.class, this.annotatedElement, registry);
+ Object result =
+ this.injector.getValue(this.resourceResolver, null, Resource.class, this.annotatedElement, registry);
assertNull(result);
}
@Test
public void testRequest() {
- Object result = this.injector.getValue(this.resourceResolver, null, SlingHttpServletResponse.class,
- this.annotatedElement, registry);
+ Object result = this.injector.getValue(
+ this.resourceResolver, null, SlingHttpServletResponse.class, this.annotatedElement, registry);
assertNull(result);
}
@Test
public void testResponse() {
- Object result = this.injector.getValue(this.resourceResolver, null, SlingHttpServletResponse.class,
- this.annotatedElement, registry);
+ Object result = this.injector.getValue(
+ this.resourceResolver, null, SlingHttpServletResponse.class, this.annotatedElement, registry);
assertNull(result);
}
@Test
public void testScriptHelper() {
- Object result = this.injector.getValue(this.resourceResolver, null, SlingScriptHelper.class,
- this.annotatedElement, registry);
+ Object result = this.injector.getValue(
+ this.resourceResolver, null, SlingScriptHelper.class, this.annotatedElement, registry);
assertNull(result);
}
@@ -85,5 +87,4 @@ public class SlingObjectInjectorResourceResolverTest {
Object result = this.injector.getValue(this, null, SlingScriptHelper.class, this.annotatedElement, registry);
assertNull(result);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceTest.java b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceTest.java
index 62ac700..a4af146 100644
--- a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceTest.java
+++ b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceTest.java
@@ -18,10 +18,6 @@
*/
package org.apache.sling.models.impl.injectors;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.mockito.Mockito.when;
-
import java.lang.reflect.AnnotatedElement;
import org.apache.sling.api.SlingHttpServletResponse;
@@ -36,6 +32,10 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class SlingObjectInjectorResourceTest {
@@ -60,8 +60,8 @@ public class SlingObjectInjectorResourceTest {
@Test
public void testResourceResolver() {
- Object result = this.injector
- .getValue(this.resource, null, ResourceResolver.class, this.annotatedElement, registry);
+ Object result =
+ this.injector.getValue(this.resource, null, ResourceResolver.class, this.annotatedElement, registry);
assertSame(this.resourceResolver, result);
}
@@ -77,22 +77,22 @@ public class SlingObjectInjectorResourceTest {
@Test
public void testRequest() {
- Object result = this.injector.getValue(this.resource, null, SlingHttpServletResponse.class,
- this.annotatedElement, registry);
+ Object result = this.injector.getValue(
+ this.resource, null, SlingHttpServletResponse.class, this.annotatedElement, registry);
assertNull(result);
}
@Test
public void testResponse() {
- Object result = this.injector.getValue(this.resource, null, SlingHttpServletResponse.class,
- this.annotatedElement, registry);
+ Object result = this.injector.getValue(
+ this.resource, null, SlingHttpServletResponse.class, this.annotatedElement, registry);
assertNull(result);
}
@Test
public void testScriptHelper() {
- Object result = this.injector.getValue(this.resource, null, SlingScriptHelper.class, this.annotatedElement,
- registry);
+ Object result =
+ this.injector.getValue(this.resource, null, SlingScriptHelper.class, this.annotatedElement, registry);
assertNull(result);
}
@@ -101,5 +101,4 @@ public class SlingObjectInjectorResourceTest {
Object result = this.injector.getValue(this, null, SlingScriptHelper.class, this.annotatedElement, registry);
assertNull(result);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/injectors/ValueMapInjectorTest.java b/src/test/java/org/apache/sling/models/impl/injectors/ValueMapInjectorTest.java
index 4b46789..8f58a21 100644
--- a/src/test/java/org/apache/sling/models/impl/injectors/ValueMapInjectorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/injectors/ValueMapInjectorTest.java
@@ -18,9 +18,6 @@
*/
package org.apache.sling.models.impl.injectors;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
import java.lang.reflect.AnnotatedElement;
import org.apache.sling.api.resource.Resource;
@@ -33,6 +30,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
@RunWith(MockitoJUnitRunner.class)
public class ValueMapInjectorTest {
@@ -40,8 +40,10 @@ public class ValueMapInjectorTest {
@Mock
private ValueMap valueMap;
+
@Mock
private AnnotatedElement element;
+
@Mock
private DisposalCallbackRegistry registry;
@@ -88,5 +90,4 @@ public class ValueMapInjectorTest {
Object result = injector.getValue(mock(ResourceResolver.class), STRING_PARAM, String.class, element, registry);
assertNull(result);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/via/ChildResourceViaProviderTest.java b/src/test/java/org/apache/sling/models/impl/via/ChildResourceViaProviderTest.java
index 0271c0b..3939a8e 100644
--- a/src/test/java/org/apache/sling/models/impl/via/ChildResourceViaProviderTest.java
+++ b/src/test/java/org/apache/sling/models/impl/via/ChildResourceViaProviderTest.java
@@ -1,23 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.via;
-import static org.mockito.Mockito.when;
-
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.junit.Assert;
@@ -27,6 +27,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class ChildResourceViaProviderTest {
@@ -59,5 +61,4 @@ public class ChildResourceViaProviderTest {
Resource adaptableResource = ((SlingHttpServletRequest) adaptable).getResource();
Assert.assertEquals(adaptableResource, childResource);
}
-
}
diff --git a/src/test/java/org/apache/sling/models/impl/via/OriginalResourceTypeViaProviderTest.java b/src/test/java/org/apache/sling/models/impl/via/OriginalResourceTypeViaProviderTest.java
index a793b0c..fd0beda 100644
--- a/src/test/java/org/apache/sling/models/impl/via/OriginalResourceTypeViaProviderTest.java
+++ b/src/test/java/org/apache/sling/models/impl/via/OriginalResourceTypeViaProviderTest.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.via;
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/ArrayOSGiModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/ArrayOSGiModel.java
index 3e31a97..7e26c30 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/ArrayOSGiModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/ArrayOSGiModel.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
@@ -24,12 +26,11 @@ import org.apache.sling.models.testmodels.interfaces.ServiceInterface;
@Model(adaptables = Resource.class)
public class ArrayOSGiModel {
-
+
@Inject
private ServiceInterface[] services;
-
+
public ServiceInterface[] getServices() {
return services;
}
-
}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/ArrayPrimitivesModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/ArrayPrimitivesModel.java
index d89384f..e611cc0 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/ArrayPrimitivesModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/ArrayPrimitivesModel.java
@@ -1,26 +1,28 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
+import javax.inject.Inject;
+
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
-import javax.inject.Inject;
-
@Model(adaptables = Resource.class)
public class ArrayPrimitivesModel {
@@ -37,4 +39,4 @@ public class ArrayPrimitivesModel {
public int[] getSecondIntArray() {
return secondIntArray;
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/ArrayWrappersModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/ArrayWrappersModel.java
index e691e06..fc5ced5 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/ArrayWrappersModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/ArrayWrappersModel.java
@@ -1,26 +1,28 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
+import javax.inject.Inject;
+
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
-import javax.inject.Inject;
-
@Model(adaptables = Resource.class)
public class ArrayWrappersModel {
@@ -37,4 +39,4 @@ public class ArrayWrappersModel {
public Integer[] getSecondIntArray() {
return secondIntArray;
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/BindingsModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/BindingsModel.java
index 81f1a65..03767ff 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/BindingsModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/BindingsModel.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
@@ -24,16 +26,16 @@ import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.models.annotations.Model;
import org.slf4j.Logger;
-@Model(adaptables=SlingHttpServletRequest.class)
+@Model(adaptables = SlingHttpServletRequest.class)
public class BindingsModel {
-
+
@Inject
@Named("sling")
private SlingScriptHelper sling;
@Inject
private Logger log;
-
+
public SlingScriptHelper getSling() {
return sling;
}
@@ -41,5 +43,4 @@ public class BindingsModel {
public Logger getLog() {
return log;
}
-
}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/CachedModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/CachedModel.java
index 2a10933..466dcb9 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/CachedModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/CachedModel.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
@@ -22,7 +24,9 @@ import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
-@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}, cache = true)
+@Model(
+ adaptables = {SlingHttpServletRequest.class, Resource.class},
+ cache = true)
public class CachedModel {
@Inject
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithAdapterTypes12.java b/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithAdapterTypes12.java
index fbcef3f..9226ab2 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithAdapterTypes12.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithAdapterTypes12.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
@@ -22,11 +24,7 @@ import org.apache.sling.models.testmodels.interfaces.AdapterType1;
import org.apache.sling.models.testmodels.interfaces.AdapterType2;
@Model(
- adaptables = SlingHttpServletRequest.class,
- adapters = { AdapterType1.class, AdapterType2.class },
- cache = true
-)
-public class CachedModelWithAdapterTypes12 implements AdapterType1, AdapterType2 {
-
-
-}
+ adaptables = SlingHttpServletRequest.class,
+ adapters = {AdapterType1.class, AdapterType2.class},
+ cache = true)
+public class CachedModelWithAdapterTypes12 implements AdapterType1, AdapterType2 {}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithAdapterTypes23.java b/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithAdapterTypes23.java
index 365c73a..e4409ba 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithAdapterTypes23.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithAdapterTypes23.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
@@ -22,11 +24,7 @@ import org.apache.sling.models.testmodels.interfaces.AdapterType2;
import org.apache.sling.models.testmodels.interfaces.AdapterType3;
@Model(
- adaptables = SlingHttpServletRequest.class,
- adapters = { AdapterType2.class, AdapterType3.class },
- cache = true
-)
-public class CachedModelWithAdapterTypes23 implements AdapterType2, AdapterType3 {
-
-
-}
+ adaptables = SlingHttpServletRequest.class,
+ adapters = {AdapterType2.class, AdapterType3.class},
+ cache = true)
+public class CachedModelWithAdapterTypes23 implements AdapterType2, AdapterType3 {}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithSelfReference.java b/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithSelfReference.java
index 2ca8755..9e370f3 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithSelfReference.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/CachedModelWithSelfReference.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
@@ -31,4 +33,4 @@ public class CachedModelWithSelfReference {
// Add a big array of longs to the class, to make it take fewer iterations to fill the heap
public long[] longs = new long[numberOfLongs];
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/ChildModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/ChildModel.java
index 071e37f..35b62ea 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/ChildModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/ChildModel.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
@@ -26,7 +28,7 @@ public class ChildModel {
@Inject
private String property;
-
+
public String getProperty() {
return property;
}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/ChildResourceModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/ChildResourceModel.java
index c69242f..018891e 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/ChildResourceModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/ChildResourceModel.java
@@ -1,26 +1,28 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
-import java.util.List;
-
import javax.inject.Inject;
import javax.inject.Named;
+import java.util.List;
+
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
@@ -30,10 +32,12 @@ public class ChildResourceModel {
@Inject
private Resource firstChild;
- @Inject @Named("secondChild")
+ @Inject
+ @Named("secondChild")
private List<Resource> grandChildren;
- @Inject @Named("emptyChild")
+ @Inject
+ @Named("emptyChild")
private List<Resource> emptyGrandChildren;
public Resource getFirstChild() {
@@ -47,5 +51,4 @@ public class ChildResourceModel {
public List<Resource> getEmptyGrandChildren() {
return emptyGrandChildren;
}
-
}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/ChildResourceViaModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/ChildResourceViaModel.java
index 345e9aa..a1a10fa 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/ChildResourceViaModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/ChildResourceViaModel.java
@@ -1,28 +1,30 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
+import javax.inject.Inject;
+
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.via.ChildResource;
-import javax.inject.Inject;
-
@Model(adaptables = Resource.class)
public class ChildResourceViaModel {
@@ -33,5 +35,4 @@ public class ChildResourceViaModel {
public String getFirstProperty() {
return firstProperty;
}
-
}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/ChildValueMapModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/ChildValueMapModel.java
index 01d1aea..1c96355 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/ChildValueMapModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/ChildValueMapModel.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
@@ -27,9 +29,8 @@ public class ChildValueMapModel {
@Inject
private ValueMap firstChild;
-
+
public ValueMap getFirstChild() {
return firstChild;
}
-
}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/CollectionDefaultsModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/CollectionDefaultsModel.java
index 666f1c1..6dd1991 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/CollectionDefaultsModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/CollectionDefaultsModel.java
@@ -1,25 +1,27 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
-import java.util.Collection;
-
import javax.inject.Inject;
+import java.util.Collection;
+
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Default;
import org.apache.sling.models.annotations.Model;
@@ -28,11 +30,11 @@ import org.apache.sling.models.annotations.Model;
public class CollectionDefaultsModel {
@Inject
- @Default(intValues = {1,2,3})
+ @Default(intValues = {1, 2, 3})
private Collection<Integer> intList;
@Inject
- @Default(values = {"v1","v2"})
+ @Default(values = {"v1", "v2"})
private Collection<String> stringList;
public Collection<Integer> getIntCollection() {
@@ -42,5 +44,4 @@ public class CollectionDefaultsModel {
public Collection<String> getStringCollection() {
return stringList;
}
-
}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/CollectionOSGiModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/CollectionOSGiModel.java
index 115b5e4..2ac2a2e 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/CollectionOSGiModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/CollectionOSGiModel.java
@@ -1,37 +1,38 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
-import java.util.Collection;
-
import javax.inject.Inject;
+import java.util.Collection;
+
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.testmodels.interfaces.ServiceInterface;
@Model(adaptables = Resource.class)
public class CollectionOSGiModel {
-
+
@Inject
private Collection<ServiceInterface> services;
-
+
public Collection<ServiceInterface> getServices() {
return services;
}
-
}
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/ConstructorWithExceptionModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/ConstructorWithExceptionModel.java
index 72be3cc..2555740 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/ConstructorWithExceptionModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/ConstructorWithExceptionModel.java
@@ -1,25 +1,27 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.testmodels.classes;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
-@Model(adaptables=Resource.class)
+@Model(adaptables = Resource.class)
public class ConstructorWithExceptionModel {
public ConstructorWithExceptionModel() {
throw new RuntimeException("Exception thrown in constructor");
diff --git a/src/test/java/org/apache/sling/models/testmodels/classes/DefaultPrimitivesModel.java b/src/test/java/org/apache/sling/models/testmodels/classes/DefaultPrimitivesModel.java
index d9b41cd..08660a6 100644
--- a/src/test/java/org/apache/sling/models/testmodels/classes/DefaultPrimitivesModel.java
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/DefaultPrimitivesModel.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
... 4026 lines suppressed ...