harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r553714 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/beancontext/BeanContextServicesSupport.java test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextServicesSupportTest.java
Date Fri, 06 Jul 2007 03:21:22 GMT
Author: leoli
Date: Thu Jul  5 20:21:21 2007
New Revision: 553714

URL: http://svn.apache.org/viewvc?view=rev&rev=553714
Log:
Apply patch for HARMONY-4344([classlib][beans] BeanContextServicesSupport.serviceAvailable
will add duplicate service class).

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextServicesSupport.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextServicesSupportTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextServicesSupport.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextServicesSupport.java?view=diff&rev=553714&r1=553713&r2=553714
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextServicesSupport.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextServicesSupport.java
Thu Jul  5 20:21:21 2007
@@ -919,6 +919,9 @@
         if (null == event) {
             throw new NullPointerException(Messages.getString("beans.1C")); //$NON-NLS-1$
         }
+        if(services.containsKey(event.serviceClass)) {
+        	return;
+        }
         fireServiceAdded(event);
         Object childs[] = copyChildren();
         for (int i = 0; i < childs.length; i++) {
@@ -937,6 +940,9 @@
     public void serviceRevoked(BeanContextServiceRevokedEvent event) {
         if (null == event) {
             throw new NullPointerException(Messages.getString("beans.1C")); //$NON-NLS-1$
+        }
+        if(services.containsKey(event.serviceClass)) {
+        	return;
         }
         fireServiceRevoked(event);
         Object childs[] = copyChildren();

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextServicesSupportTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextServicesSupportTest.java?view=diff&rev=553714&r1=553713&r2=553714
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextServicesSupportTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextServicesSupportTest.java
Thu Jul  5 20:21:21 2007
@@ -1312,7 +1312,93 @@
                 (BeanContextServicesSupport) SerializationTester
                         .getDeserilizedObject(support));
     }
+    
+
+    static int serviceRevoked = 0;
+
+	static int serviceAvailable = 0;
+
+	private static class MyListener implements BeanContextServicesListener {
+
+		public void serviceRevoked(BeanContextServiceRevokedEvent event) {
+			serviceRevoked++;
+		}
+
+		public void serviceAvailable(BeanContextServiceAvailableEvent event) {
+			serviceAvailable++;
+		}
+
+	}
+
+	private static class MySupport extends BeanContextServicesSupport {
+
+		public void serviceRevoked(BeanContextServiceRevokedEvent event) {
+			serviceRevoked++;
+		}
+		
+		public void serviceAvailable(BeanContextServiceAvailableEvent event) {
+			serviceAvailable++;
+		}
+	}
+
+	private static class MyProvider implements BeanContextServiceProvider {
+
+		public void releaseService(BeanContextServices s, Object requestor,
+				Object service) {
+		}
+
+		public Iterator getCurrentServiceSelectors(BeanContextServices s,
+				Class serviceClass) {
+
+			return null;
+		}
+
+		public Object getService(BeanContextServices s, Object requestor,
+				Class serviceClass, Object serviceSelector) {
 
+			return null;
+
+		}
+
+	}
+
+	public void test_serviceRevoked_LBeanContextServiceRevokedEvent() {
+		BeanContextServicesSupport support = new BeanContextServicesSupport();
+
+		support.add(new MySupport());
+		support.addBeanContextServicesListener(new MyListener());
+		Class c = Object.class;
+
+		support.addService(c, new MyProvider());
+
+		BeanContextServiceRevokedEvent revokeEvent = new BeanContextServiceRevokedEvent(
+				support, c, false);
+
+		support.serviceRevoked(revokeEvent);
+        assertEquals(0, serviceRevoked);
+        assertEquals(2, serviceAvailable);
+        
+	}
+
+	public void test_serviceAvailable_LBeanContextServiceRevokedEvent() {
+		BeanContextServicesSupport support = new BeanContextServicesSupport();
+
+		support.add(new MySupport());
+		support.addBeanContextServicesListener(new MyListener());
+		Class c = Object.class;
+
+		support.addService(c, new MyProvider());
+
+		BeanContextServiceAvailableEvent availableEvent = new BeanContextServiceAvailableEvent(
+				support, c);
+	    support.serviceAvailable(availableEvent);
+        assertEquals(0, serviceRevoked);
+        assertEquals(2, serviceAvailable);
+        
+	}
+	
+    
+	
      public void testSerialization_Compatibility() throws Exception {
          BeanContextServicesSupport support = new BeanContextServicesSupport(
                  null, Locale.ITALY, true, true);
@@ -1427,5 +1513,15 @@
         public void releaseService(BeanContextServices arg0, Object arg1,
                 Object arg2) {
         }
+    }
+    
+    /*
+     * @see TestCase#setUp()
+     */
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        serviceRevoked = 0;
+        serviceAvailable = 0;
     }
 }



Mime
View raw message