incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r881343 - in /sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling: adapter/internal/ commons/testing/osgi/
Date Tue, 17 Nov 2009 15:50:31 GMT
Author: cziegeler
Date: Tue Nov 17 15:50:30 2009
New Revision: 881343

URL: http://svn.apache.org/viewvc?rev=881343&view=rev
Log:
SLING-1166 : Remove duplicates of mock object classes.

Removed:
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/adapter/internal/MockBundleContext.java
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/adapter/internal/MockComponentContext.java
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/adapter/internal/MockServiceReference.java
Modified:
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/adapter/internal/AdapterManagerTestHelper.java
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/osgi/MockComponentContext.java

Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/adapter/internal/AdapterManagerTestHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/adapter/internal/AdapterManagerTestHelper.java?rev=881343&r1=881342&r2=881343&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/adapter/internal/AdapterManagerTestHelper.java
(original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/adapter/internal/AdapterManagerTestHelper.java
Tue Nov 17 15:50:30 2009
@@ -23,6 +23,8 @@
 
 import org.apache.sling.api.adapter.AdapterFactory;
 import org.apache.sling.commons.testing.osgi.MockBundle;
+import org.apache.sling.commons.testing.osgi.MockComponentContext;
+import org.apache.sling.commons.testing.osgi.MockServiceReference;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
@@ -32,29 +34,29 @@
  * Sets up an {@link AdapterManagerImpl} in a junit testing environment. This
  * class is in the same package as the {@link AdapterManagerImpl} in order to
  * access the protected activate method.
- * 
+ *
  */
 public class AdapterManagerTestHelper {
-    
+
     private static AdapterManagerImpl adapterMgr;
-    
+
     private static MockComponentContext mockContext;
-    
+
     private static List<ServiceReference> registeredFactories = new ArrayList<ServiceReference>();
 
     private static void initAdapterManager() {
         if (adapterMgr == null) {
             adapterMgr = new AdapterManagerImpl();
-    
-            mockContext = new MockComponentContext();
+
+            mockContext = new MockComponentContext(new MockBundle(14));
             adapterMgr.activate(mockContext);
         }
     }
-    
+
     public static void registerAdapterFactory(AdapterFactory adapterFactory,
             String[] adaptableClasses, String[] adapterClasses) {
         initAdapterManager();
-        
+
         Bundle bundle = new MockBundle(1L);
         MockServiceReference ref = new MockServiceReference(bundle);
         mockContext.addService(ref, adapterFactory);
@@ -62,7 +64,7 @@
         ref.setProperty(AdapterFactory.ADAPTABLE_CLASSES, adaptableClasses);
         ref.setProperty(AdapterFactory.ADAPTER_CLASSES, adapterClasses);
         adapterMgr.bindAdapterFactory(ref);
-        
+
         registeredFactories.add(ref);
     }
 

Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/osgi/MockComponentContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/osgi/MockComponentContext.java?rev=881343&r1=881342&r2=881343&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/osgi/MockComponentContext.java
(original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/osgi/MockComponentContext.java
Tue Nov 17 15:50:30 2009
@@ -19,6 +19,8 @@
 package org.apache.sling.commons.testing.osgi;
 
 import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.servlet.Servlet;
@@ -37,11 +39,22 @@
 
     private Servlet servlet;
 
+    private Map<ServiceReference, Object> services = new HashMap<ServiceReference,
Object>();
+
+    public MockComponentContext(MockBundle bundle) {
+        mockBundleContext = new MockBundleContext(bundle);
+    }
+
     public MockComponentContext(MockBundle bundle, Servlet servlet) {
         mockBundleContext = new MockBundleContext(bundle);
         this.servlet = servlet;
     }
 
+    public void addService(ServiceReference reference, Object service) {
+        services.put(reference, service);
+    }
+
+
     public void setProperty(Object key, Object value) {
         // noinspection unchecked
         this.properties.put(key, value);
@@ -59,7 +72,7 @@
             return this.servlet;
         }
 
-        return null;
+        return services.get(reference);
     }
 
     public BundleContext getBundleContext() {



Mime
View raw message