SLING-5029 - clarify ModelFactory.canCreateFromAdaptable to always return false in...
authorKonrad Windszus <kwin@apache.org>
Fri, 8 Jan 2016 17:25:00 +0000 (17:25 +0000)
committerKonrad Windszus <kwin@apache.org>
Fri, 8 Jan 2016 17:25:00 +0000 (17:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723767 13f79535-47bb-0310-9956-ffa450edef68

22 files changed:
src/main/java/org/apache/sling/models/impl/AdapterImplementations.java
src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
src/test/java/org/apache/sling/models/impl/ConstructorTest.java
src/test/java/org/apache/sling/models/impl/CustomInjectorTest.java
src/test/java/org/apache/sling/models/impl/DefaultTest.java
src/test/java/org/apache/sling/models/impl/ExtraDefaultTests.java
src/test/java/org/apache/sling/models/impl/ImplementsExtendsTest.java
src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
src/test/java/org/apache/sling/models/impl/InvalidAdaptationsTest.java
src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java
src/test/java/org/apache/sling/models/impl/OSGiInjectionTest.java
src/test/java/org/apache/sling/models/impl/OptionalPrimitivesTest.java
src/test/java/org/apache/sling/models/impl/ParameterizedTypeFromRequestAttributeTest.java
src/test/java/org/apache/sling/models/impl/PostConstructTest.java
src/test/java/org/apache/sling/models/impl/RequestInjectionTest.java
src/test/java/org/apache/sling/models/impl/ResourceModelClassesTest.java
src/test/java/org/apache/sling/models/impl/ResourceModelConstructorTest.java
src/test/java/org/apache/sling/models/impl/ResourceModelInterfacesTest.java
src/test/java/org/apache/sling/models/impl/ResourcePathInjectionTest.java
src/test/java/org/apache/sling/models/impl/SelfDependencyTest.java
src/test/java/org/apache/sling/models/impl/ViaTest.java

index ac8843e..36ca013 100644 (file)
@@ -84,6 +84,16 @@ final class AdapterImplementations {
         }
     }
     
+    /** Add implementation mapping for the given model class (implementation is the model class itself).
+     * Only used for testing purposes. Use {@link #add(Class, Class)} in case you want to register a different implementation.
+     * @param modelClasses the model classes to register
+     */
+    protected void addClassesAsAdapterAndImplementation(Class<?>... modelClasses) {
+        for (Class<?> modelClass : modelClasses) {
+            add(modelClass, modelClass);
+        }
+    }
+    
     /**
      * Add implementation mapping for the given adapter type.
      * @param adapterType Adapter type
index 983fc26..37d870b 100644 (file)
@@ -208,16 +208,17 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     }
 
     private boolean internalCanCreateFromAdaptable(Object adaptable, Class<?> requestedType) throws ModelClassException {
-        ModelClass<?> modelClass = getImplementationTypeForAdapterType(requestedType, adaptable);
-        if (!modelClass.hasModelAnnotation()) {
-            throw new ModelClassException(String.format("Model class '%s' does not have a model annotation", modelClass.getType()));
-        }
-
-        Class<?>[] declaredAdaptable = modelClass.getModelAnnotation().adaptables();
-        for (Class<?> clazz : declaredAdaptable) {
-            if (clazz.isInstance(adaptable)) {
-                return true;
+        try {
+            ModelClass<?> modelClass = getImplementationTypeForAdapterType(requestedType, adaptable);
+            Class<?>[] declaredAdaptable = modelClass.getModelAnnotation().adaptables();
+            for (Class<?> clazz : declaredAdaptable) {
+                if (clazz.isInstance(adaptable)) {
+                    return true;
+                }
             }
+        } 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);
+            return false;
         }
         return false;
     }
@@ -225,8 +226,13 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     @Override
     @Deprecated
     public boolean isModelClass(@Nonnull Object adaptable, @Nonnull Class<?> requestedType) {
-        ModelClass<?> type = getImplementationTypeForAdapterType(requestedType, adaptable);
-        return type.hasModelAnnotation();
+        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);
+            return false;
+        }
+        return true;
     }
 
     @Override
@@ -238,7 +244,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
      * 
      * @param requestedType the adapter type
      * @param adaptable the adaptable
-     * @return the implementation type to use for the desired model type
+     * @return the implementation type to use for the desired model type or null if there is none registered
      * @see <a
      *      href="http://sling.apache.org/documentation/bundles/models.html#specifying-an-alternate-adapter-class-since-sling-models-110">Specifying
      *      an Alternate Adapter Class</a>
@@ -246,14 +252,14 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     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
         ModelClass<ModelType> modelClass = this.adapterImplementations.lookup(requestedType, adaptable);
         if (modelClass != null) {
             log.debug("Using implementation type {} for requested adapter type {}", modelClass, requestedType);
             return modelClass;
         }
-        // normally this code path is not executed, because all types are cached in adapterImplementations
-        // it is still useful for unit testing
-        return new ModelClass<ModelType>(requestedType, this.adapterImplementations.getStaticInjectAnnotationProcessorFactories());
+        // throw exception here
+        throw new ModelClassException("Could not yet find an adapter factory for the model " + requestedType + " from adaptable " + adaptable.getClass());
     }
 
     @SuppressWarnings("unchecked")
index 711c96f..5e432df 100644 (file)
@@ -33,6 +33,7 @@ import org.apache.sling.models.factory.ModelClassException;
 import org.apache.sling.models.factory.MissingElementsException;
 import org.apache.sling.models.impl.injectors.SelfInjector;
 import org.apache.sling.models.impl.injectors.ValueMapInjector;
+import org.apache.sling.models.testmodels.classes.BindingsModel;
 import org.apache.sling.models.testmodels.classes.ConstructorWithExceptionModel;
 import org.apache.sling.models.testmodels.classes.DefaultStringModel;
 import org.apache.sling.models.testmodels.classes.InvalidModelWithMissingAnnotation;
@@ -71,6 +72,8 @@ public class AdapterFactoryTest {
         factory.activate(componentCtx);
         factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(0, 0));
         factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(1, 1));
+        
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(DefaultStringModel.class, ConstructorWithExceptionModel.class, NestedModel.class, NestedModelWithInvalidAdaptable.class, NestedModelWithInvalidAdaptable2.class, ResourceModelWithRequiredField.class) ;
     }
 
     @Test
@@ -86,9 +89,9 @@ public class AdapterFactoryTest {
         Assert.assertFalse(factory.canCreateFromAdaptable(request, DefaultStringModel.class));
     }
 
-    @Test(expected = ModelClassException.class)
+    @Test
     public void testCanCreateFromAdaptableWithInvalidModel() {
-        factory.canCreateFromAdaptable(resource, InvalidModelWithMissingAnnotation.class);
+        Assert.assertFalse(factory.canCreateFromAdaptable(resource, InvalidModelWithMissingAnnotation.class));
     }
 
     @Test(expected = ModelClassException.class)
index 953fb78..549c18d 100644 (file)
@@ -70,6 +70,7 @@ public class ConstructorTest {
         factory.activate(componentCtx);
         factory.bindInjector(new RequestAttributeInjector(), new ServicePropertiesMap(1, 1));
         factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(2, 2));
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(WithOneConstructorModel.class, WithThreeConstructorsModel.class, WithTwoConstructorsModel.class, SuperclassConstructorModel.class, InvalidConstructorModel.class, WithThreeConstructorsOneInjectModel.class, NoNameModel.class);
     }
 
     @Test
index 6179eb1..5ea8d06 100644 (file)
@@ -53,6 +53,7 @@ public class CustomInjectorTest {
 
         factory = new ModelAdapterFactory();
         factory.activate(componentCtx);
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(TestModel.class, CustomAnnotationModel.class);
     }
 
     @Test
index 03f50e8..dc3abf5 100644 (file)
  */
 package org.apache.sling.models.impl;
 
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+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.mock;
+import static org.mockito.Mockito.when;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -58,6 +62,7 @@ public class DefaultTest {
         factory = new ModelAdapterFactory();
         factory.activate(componentCtx);
         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);
     }
 
     @Test
index e2fadd8..eff1d51 100644 (file)
@@ -55,6 +55,7 @@ public class ExtraDefaultTests {
 
         factory = new ModelAdapterFactory();
         factory.activate(componentCtx);
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(EmptyDefaultsModel.class, WrongTypeDefaultsModel.class);
     }
 
     @Test
index f120770..0107320 100644 (file)
@@ -36,9 +36,12 @@ import java.util.Hashtable;
 import java.util.Map;
 import java.util.Vector;
 
+import javax.jws.WebParam.Mode;
+
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.wrappers.ValueMapDecorator;
+import org.apache.sling.models.factory.ModelClassException;
 import org.apache.sling.models.impl.injectors.ValueMapInjector;
 import org.apache.sling.models.spi.ImplementationPicker;
 import org.apache.sling.models.testmodels.classes.implextend.EvenSimplerPropertyModel;
@@ -50,6 +53,7 @@ import org.apache.sling.models.testmodels.classes.implextend.InvalidSampleServic
 import org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface;
 import org.apache.sling.models.testmodels.classes.implextend.SimplePropertyModel;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -153,8 +157,12 @@ public class ImplementsExtendsTest {
         
         // make sure adaption is not longer possible: implementation class mapping is removed
         Resource res = getMockResourceWithProps();
-        SampleServiceInterface model = factory.getAdapter(res, SampleServiceInterface.class);
-        assertNull(model);
+        try {
+            SampleServiceInterface model = factory.getAdapter(res, SampleServiceInterface.class);
+            Assert.fail("Getting the model for interface 'SampleServiceInterface' should fail after the accroding adapter factory has been unregistered");
+        } catch (ModelClassException e) {
+            
+        }
     }
 
     /**
@@ -172,24 +180,31 @@ public class ImplementsExtendsTest {
 
     /**
      * Try to adapt in a case where there is no picker available.
-     * This causes the extend adaptation to fail, but the case where the
-     * class is the adapter still works.
+     * This causes the extend adaptation to fail.
      */
     @Test
-    @SuppressWarnings("deprecation")
-    public void testImplementsNoPicker() {
+    public void testImplementsNoPickerWithAdapterEqualsImplementation() {
         factory.unbindImplementationPicker(firstImplementationPicker, firstImplementationPickerProps);
 
         Resource res = getMockResourceWithProps();
-        SampleServiceInterface model = factory.getAdapter(res, SampleServiceInterface.class);
-        assertNull(model);
-        assertFalse(factory.isModelClass(res, SampleServiceInterface.class));
-
-        model = factory.getAdapter(res, ImplementsInterfacePropertyModel.class);
+        
+        SampleServiceInterface model = factory.getAdapter(res, ImplementsInterfacePropertyModel.class);
         assertNotNull(model);
         assertEquals("first-value|null|third-value", model.getAllProperties());
         assertTrue(factory.canCreateFromAdaptable(res, ImplementsInterfacePropertyModel.class));
     }
+    
+    /**
+     * 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)
+    public void testImplementsNoPickerWithDifferentImplementations() {
+        factory.unbindImplementationPicker(firstImplementationPicker, firstImplementationPickerProps);
+
+        Resource res = getMockResourceWithProps();
+        factory.getAdapter(res, SampleServiceInterface.class);
+    }
 
     /**
      * Ensure that the implementation class itself cannot be adapted to if it is not part of the "adapter" property in the annotation.
@@ -208,13 +223,10 @@ public class ImplementsExtendsTest {
     /**
      * Test implementation class with a mapping that is not valid (an interface that is not implemented).
      */
-    @Test
-    @SuppressWarnings("deprecation")
+    @Test(expected=ModelClassException.class)
     public void testInvalidImplementsInterfaceModel() {
         Resource res = getMockResourceWithProps();
-        InvalidSampleServiceInterface model = factory.getAdapter(res, InvalidSampleServiceInterface.class);
-        assertNull(model);
-        assertFalse(factory.isModelClass(res, InvalidSampleServiceInterface.class));
+        factory.getAdapter(res, InvalidSampleServiceInterface.class);
     }
 
     /**
@@ -224,6 +236,7 @@ public class ImplementsExtendsTest {
     public void testExtendsClassModel() {
         Resource res = getMockResourceWithProps();
 
+        // this is not having a model annotation nor does implement an interface/extend a class with a model annotation
         SimplePropertyModel model = factory.getAdapter(res, SimplePropertyModel.class);
         assertNotNull(model);
         assertEquals("!first-value|null|third-value!", model.getAllProperties());
index 362a5c7..7ac8213 100644 (file)
@@ -110,6 +110,7 @@ public class InjectorSpecificAnnotationTest {
         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);
     }
 
     @Test
index 50a8cf8..8cc9c41 100644 (file)
@@ -60,6 +60,7 @@ public class InvalidAdaptationsTest {
         factory.activate(componentCtx);
         factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(1, 1));
         factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(2, 0));
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(NonModel.class, RequestModel.class);
     }
 
     @Test
index a7e81a1..5936176 100644 (file)
@@ -71,11 +71,13 @@ public class MultipleInjectorTest {
 
         factory = new ModelAdapterFactory();
         factory.activate(componentCtx);
+        // binding injector should be asked first as it has a lower service ranking!
         factory.bindInjector(bindingsInjector, new ServicePropertiesMap(1, 1));
         factory.bindInjector(attributesInjector, new ServicePropertiesMap(2, 2));
         factory.bindStaticInjectAnnotationProcessorFactory(bindingsInjector, new ServicePropertiesMap(1, 1));
 
         when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(ForTwoInjectorsWithSource.class, ForTwoInjectors.class);
     }
 
     @Test
@@ -90,9 +92,6 @@ public class MultipleInjectorTest {
 
         assertNotNull(obj);
         assertEquals(obj.firstAttribute, bindingsValue);
-
-        verify(bindingsInjector).createAnnotationProcessor(any(AnnotatedElement.class));
-        verify(bindingsInjector).getValue(eq(request), eq("firstAttribute"), eq(String.class), any(AnnotatedElement.class), any(DisposalCallbackRegistry.class));
     }
 
     @Test
@@ -107,10 +106,6 @@ public class MultipleInjectorTest {
 
         assertNotNull(obj);
         assertEquals(obj.firstAttribute, attributeValue);
-
-        verify(bindingsInjector).getName();
-        verify(bindingsInjector).createAnnotationProcessor(any(AnnotatedElement.class));
-        verifyNoMoreInteractions(bindingsInjector);
     }
 
     @Model(adaptables = SlingHttpServletRequest.class)
index af5a632..c0c8da4 100644 (file)
@@ -75,6 +75,7 @@ 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);
     }
 
     @Test
index 06ef24f..264c2e4 100644 (file)
@@ -28,6 +28,7 @@ import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.models.impl.injectors.ChildResourceInjector;
 import org.apache.sling.models.impl.injectors.ValueMapInjector;
+import org.apache.sling.models.testmodels.classes.constructorinjection.OptionalPrimitivesModel;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -59,6 +60,7 @@ public class OptionalPrimitivesTest {
         factory.activate(componentCtx);
         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);
     }
 
     @Test
index 3c9240a..c35a712 100644 (file)
@@ -62,6 +62,7 @@ public class ParameterizedTypeFromRequestAttributeTest {
 
         RequestAttributeInjector injector = new RequestAttributeInjector();
         factory.bindInjector(injector, new ServicePropertiesMap(1, 1));
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(TestModel.class);
     }
 
     @Test
index f55fa22..80f56d3 100644 (file)
@@ -56,6 +56,7 @@ public class PostConstructTest {
         when(componentCtx.getProperties()).thenReturn(new Hashtable<String, Object>());
         factory.activate(componentCtx);
         // no injectors are necessary
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(SubClass.class, SubClassOverriddenPostConstruct.class, FailingPostConstuctModel.class);
     }
 
     @Test
index 180b948..23b8e35 100644 (file)
@@ -16,8 +16,9 @@
  */
 package org.apache.sling.models.impl;
 
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
 
 import java.util.Hashtable;
 
@@ -63,6 +64,8 @@ public class RequestInjectionTest {
         factory = new ModelAdapterFactory();
         factory.activate(componentCtx);
         factory.bindInjector(new BindingsInjector(), new ServicePropertiesMap(1, 1));
+        
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(BindingsModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.BindingsModel.class);
     }
 
     @Test
index 6d004ed..22439f5 100644 (file)
@@ -78,6 +78,7 @@ public class ResourceModelClassesTest {
         
         factory.bindInjectAnnotationProcessorFactory(valueMapInjector,
                 Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 2L));
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(SimplePropertyModel.class, ArrayWrappersModel.class, ResourceModelWithRequiredField.class, ChildValueMapModel.class, ArrayPrimitivesModel.class, ChildResourceModel.class, ResourceModelWithRequiredFieldOptionalStrategy.class, ParentModel.class, ChildModel.class, ListModel.class);
     }
 
     @Test
index cc553b8..d1d661f 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.commons.lang.RandomStringUtils;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.wrappers.ValueMapDecorator;
+import org.apache.sling.models.impl.ParameterizedTypeFromRequestAttributeTest.TestModel;
 import org.apache.sling.models.impl.injectors.ChildResourceInjector;
 import org.apache.sling.models.impl.injectors.ValueMapInjector;
 import org.apache.sling.models.testmodels.classes.ChildModel;
@@ -61,6 +62,7 @@ public class ResourceModelConstructorTest {
         factory.activate(componentCtx);
         factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(2, 2));
         factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(1, 1));
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(ParentModel.class, ChildModel.class);
     }
 
     @Test
index 2e278e1..c980785 100644 (file)
@@ -67,6 +67,7 @@ public class ResourceModelInterfacesTest {
         factory.activate(componentCtx);
         factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(2, 2));
         factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(1, 1));
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(SimplePropertyModel.class, ResourceModelWithRequiredField.class, ChildResourceModel.class, ChildValueMapModel.class, ParentModel.class, ChildModel.class); 
     }
 
     @Test
index 09ccdd1..6a3e6ab 100644 (file)
@@ -112,6 +112,7 @@ public class ResourcePathInjectionTest {
         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);
     }
 
     @Test
index ea1f8b6..2fc8b99 100644 (file)
@@ -28,6 +28,7 @@ import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.models.impl.injectors.SelfInjector;
 import org.apache.sling.models.testmodels.classes.DirectCyclicSelfDependencyModel;
 import org.apache.sling.models.testmodels.classes.IndirectCyclicSelfDependencyModelA;
+import org.apache.sling.models.testmodels.classes.IndirectCyclicSelfDependencyModelB;
 import org.apache.sling.models.testmodels.classes.SelfDependencyModelA;
 import org.apache.sling.models.testmodels.classes.SelfDependencyModelB;
 import org.junit.Before;
@@ -71,6 +72,7 @@ public class SelfDependencyTest {
         factory = new ModelAdapterFactory();
         factory.activate(componentCtx);
         factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(1, 1));
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(SelfDependencyModelA.class, SelfDependencyModelB.class, DirectCyclicSelfDependencyModel.class, IndirectCyclicSelfDependencyModelA.class, IndirectCyclicSelfDependencyModelB.class);
     }
 
     @Test
index a1c9af4..51118ac 100644 (file)
@@ -63,6 +63,7 @@ public class ViaTest {
         factory = new ModelAdapterFactory();
         factory.activate(componentCtx);
         factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(1, 1));
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(ViaModel.class);
     }
 
     @Test