sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1732052 - in /sling/trunk/bundles/extensions/models/impl/src: main/java/org/apache/sling/models/impl/ModelAdapterFactory.java test/java/org/apache/sling/models/impl/MultipleInjectorTest.java
Date Wed, 24 Feb 2016 10:03:48 GMT
Author: sseifert
Date: Wed Feb 24 10:03:48 2016
New Revision: 1732052

URL: http://svn.apache.org/viewvc?rev=1732052&view=rev
Log:
SLING-5555 Make error message more explicit when a @Source annotation contains an invalid
source identifier

Modified:
    sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
    sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java

Modified: sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java?rev=1732052&r1=1732051&r2=1732052&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
(original)
+++ sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
Wed Feb 24 10:03:48 2016
@@ -420,6 +420,9 @@ public class ModelAdapterFactory impleme
             }
             else {
                 injectorsToProcess = injectors.get(source);
+                if (injectorsToProcess == null) {
+                    throw new IllegalArgumentException("No Sling Models Injector registered
for source '" + source + "'.");
+                }
             }
             
             // find the right injector

Modified: sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java?rev=1732052&r1=1732051&r2=1732052&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java
(original)
+++ sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java
Wed Feb 24 10:03:48 2016
@@ -16,10 +16,11 @@
  */
 package org.apache.sling.models.impl;
 
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.when;
 
-import java.lang.reflect.AnnotatedElement;
 import java.util.Hashtable;
 
 import javax.inject.Inject;
@@ -28,9 +29,9 @@ import org.apache.sling.api.SlingHttpSer
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.models.annotations.Model;
 import org.apache.sling.models.annotations.Source;
+import org.apache.sling.models.factory.ModelClassException;
 import org.apache.sling.models.impl.injectors.BindingsInjector;
 import org.apache.sling.models.impl.injectors.RequestAttributeInjector;
-import org.apache.sling.models.spi.DisposalCallbackRegistry;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -77,7 +78,8 @@ public class MultipleInjectorTest {
         factory.bindStaticInjectAnnotationProcessorFactory(bindingsInjector, new ServicePropertiesMap(1,
1));
 
         when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
-        factory.adapterImplementations.addClassesAsAdapterAndImplementation(ForTwoInjectorsWithSource.class,
ForTwoInjectors.class);
+        factory.adapterImplementations.addClassesAsAdapterAndImplementation(
+                ForTwoInjectorsWithSource.class, ForTwoInjectors.class, ForTwoInjectorsWithInvalidSource.class);
     }
 
     @Test
@@ -108,6 +110,17 @@ public class MultipleInjectorTest {
         assertEquals(obj.firstAttribute, attributeValue);
     }
 
+    @Test
+    public void testInjectorWithInvalidSource() {
+        ForTwoInjectorsWithInvalidSource obj = factory.getAdapter(request, ForTwoInjectorsWithInvalidSource.class);
+        assertNull(obj);
+    }
+
+    @Test(expected=ModelClassException.class)
+    public void testInjectorWithInvalidSourceWithException() {
+        factory.createModel(request, ForTwoInjectorsWithInvalidSource.class);
+    }
+
     @Model(adaptables = SlingHttpServletRequest.class)
     public static class ForTwoInjectors {
 
@@ -124,5 +137,14 @@ public class MultipleInjectorTest {
         private String firstAttribute;
 
     }
+
+    @Model(adaptables = SlingHttpServletRequest.class)
+    public static class ForTwoInjectorsWithInvalidSource {
+
+        @Inject
+        @Source("this-is-an-invalid-source")
+        private String firstAttribute;
+
+    }
 
 }



Mime
View raw message