You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/04/19 09:50:46 UTC
svn commit: r395159 - in
/incubator/harmony/enhanced/classlib/trunk/modules/beans/src:
main/java/java/beans/beancontext/ test/java/java/beans/beancontext/
Author: mloenko
Date: Wed Apr 19 00:50:45 2006
New Revision: 395159
URL: http://svn.apache.org/viewcvs?rev=395159&view=rev
Log:
fixes for HARMONY-373
beans: Harmony does not throw NullPointerException in several cases while RI does.
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextServicesSupport.java
incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java
incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/java/beans/beancontext/BeanContextServicesSupportTest.java
incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/java/beans/beancontext/BeanContextSupportTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextServicesSupport.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextServicesSupport.java?rev=395159&r1=395158&r2=395159&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextServicesSupport.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextServicesSupport.java Wed Apr 19 00:50:45 2006
@@ -503,6 +503,9 @@
* @com.intel.drl.spec_ref
*/
public synchronized boolean hasService(Class serviceClass) {
+ if (serviceClass == null) {
+ throw new NullPointerException("The service class is null");
+ }
synchronized(BeanContext.globalHierarchyLock) {
synchronized(this.services) {
@@ -595,10 +598,12 @@
public void removeBeanContextServicesListener(
BeanContextServicesListener bcsl) {
- if (bcsl != null) {
- synchronized(this.bcsListeners) {
- this.bcsListeners.remove(bcsl);
- }
+ if (bcsl == null) {
+ throw new NullPointerException("The listener is null");
+ }
+
+ synchronized(this.bcsListeners) {
+ this.bcsListeners.remove(bcsl);
}
}
@@ -649,6 +654,9 @@
* @com.intel.drl.spec_ref
*/
public void serviceAvailable(BeanContextServiceAvailableEvent bcssae) {
+ if (bcssae == null) {
+ throw new NullPointerException("The event is null");
+ }
for (Iterator it = this.bcsListeners.iterator(); it.hasNext(); ) {
BeanContextServicesListener l =
@@ -662,6 +670,9 @@
* @com.intel.drl.spec_ref
*/
public void serviceRevoked(BeanContextServiceRevokedEvent bcssre) {
+ if (bcssre == null) {
+ throw new NullPointerException("The event is null");
+ }
for (Iterator it = this.bcsListeners.iterator(); it.hasNext(); ) {
BeanContextServicesListener l =
Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java?rev=395159&r1=395158&r2=395159&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java Wed Apr 19 00:50:45 2006
@@ -777,7 +777,12 @@
// The resource name should not be null
if(name == null) {
- throw new IllegalArgumentException("Resource name can not be null");
+ throw new NullPointerException("Resource name can not be null");
+ }
+
+ // The child should not be null
+ if(bcc == null) {
+ throw new NullPointerException("The child can not be null");
}
// Load resource using the same ClassLoader as BeanContextChild specified
@@ -802,7 +807,12 @@
// The resource name should not be null
if(name == null) {
- throw new IllegalArgumentException("Resource name can not be null");
+ throw new NullPointerException("Resource name can not be null");
+ }
+
+ // The child should not be null
+ if(bcc == null) {
+ throw new NullPointerException("The child can not be null");
}
// Load resource using the same ClassLoader as BeanContextChild specified
@@ -1290,6 +1300,9 @@
public void vetoableChange(PropertyChangeEvent pce)
throws PropertyVetoException {
+ if (pce == null) {
+ throw new NullPointerException("The event is null");
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/java/beans/beancontext/BeanContextServicesSupportTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/java/beans/beancontext/BeanContextServicesSupportTest.java?rev=395159&r1=395158&r2=395159&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/java/beans/beancontext/BeanContextServicesSupportTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/java/beans/beancontext/BeanContextServicesSupportTest.java Wed Apr 19 00:50:45 2006
@@ -1,330 +1,378 @@
-/*
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed 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
- *
- * 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.
- */
-
-/**
- * @author Sergey A. Krivenko
- * @version $Revision: 1.5.2.2 $
- */
-package java.beans.beancontext;
-
-import java.beans.beancontext.BeanContextServices;
-import java.beans.beancontext.BeanContextServicesSupport;
-import java.beans.beancontext.BeanContextServiceProvider;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test class for java.beans.beancontext.BeanContextServicesSupport.<p>
- *
- * @author Sergey A. Krivenko
- * @version $Revision: 1.5.2.2 $
- */
-
-public class BeanContextServicesSupportTest extends TestCase {
-
- /** STANDARD BEGINNING **/
-
- /**
- * No arguments constructor to enable serialization.<p>
- */
- public BeanContextServicesSupportTest() {
- super();
- }
-
- /**
- * Constructs this test case with the given name.<p>
- *
- * @param name - The name for this test case.<p>
- */
- public BeanContextServicesSupportTest(String name) {
- super(name);
- }
-
- /** TEST CONSTRUCTORS **/
-
- /**
- * Test constructor with BeanContextServices, Locale, boolean,
- * boolean parameters.<p>
- *
- * @see BeanContextServicesSupport#BeanContextServicesSupport(
- * BeanContextServices, Locale, boolean, boolean)
- */
- public void testConstructorBeanContextServicesLocalebooleanboolean() {
- try {
- BeanContextServicesSupport sup =
- new BeanContextServicesSupport(null, null, true, true);
- }
- catch (Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test constructor with BeanContextServices, Locale, boolean parameters
- *
- * @see BeanContextServicesSupport#BeanContextServicesSupport(
- * BeanContextServices, Locale, boolean)
- */
- public void testConstructorBeanContextServicesLocaleboolean() {
- try {
- BeanContextServicesSupport sup =
- new BeanContextServicesSupport(null, null, true);
- }
- catch (Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test constructor with BeanContextServices, Locale parameters.<p>
- *
- * @see BeanContextServicesSupport#BeanContextServicesSupport(
- * BeanContextServices, Locale)
- */
- public void testConstructorBeanContextServicesLocale() {
- try {
- BeanContextServicesSupport sup =
- new BeanContextServicesSupport(null, null);
- }
- catch (Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test constructor with BeanContextServices parameter.<p>
- *
- * @see BeanContextServicesSupport#BeanContextServicesSupport(
- * BeanContextServices)
- */
- public void testConstructorBeanContextServices() {
- try {
- BeanContextServicesSupport sup =
- new BeanContextServicesSupport(null);
- }
- catch (Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /** * Test constructor with no parameters.<p>
- *
- * @see BeanContextServicesSupport#BeanContextServicesSupport()
- */
- public void testConstructor() {
- try {
- BeanContextServicesSupport sup = new BeanContextServicesSupport();
- }
- catch (Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /** TEST METHODS **/
-
- /**
- * Test method createBCSChild() with Object, Object parameters.<p>
- */
- public void testCreateBCSChildObjectObject() {
- try {
-
- // Just call the method
- BeanContextServicesSupport sup = new BeanContextServicesSupport();
- sup.createBCSChild(new Object(), new Object());
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method addService() with Class, BeanContextServiceProvider, boolean parameters.<p>
- */
- public void testAddServiceClassBeanContextServiceProviderboolean() {
- try {
-
- // Instantiate services and add service
- BeanContextServicesSupport sup = new BeanContextServicesSupport();
- sup.addService(Object.class, getProvider(), true);
-
- if (sup.services.size() != 1) {
- fail("One service should be registered");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method revokeService() with Class, BeanContextServiceProvider, boolean parameters.<p>
- */
- public void testRevokeServiceClassBeanContextServiceProviderboolean() {
- try {
-
- // Instantiate services, add and remove service
- BeanContextServicesSupport sup = new BeanContextServicesSupport();
- BeanContextServiceProvider pr = getProvider();
- sup.addService(Object.class, pr, true);
- sup.revokeService(Object.class, pr, true);
-
- if (sup.services.size() != 0) {
- fail("No service should be registered");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method addService() with Class, BeanContextServiceProvider parameters.<p>
- */
- public void testAddServiceClassBeanContextServiceProvider() {
- try {
-
- // Instantiate services and add service
- BeanContextServicesSupport sup = new BeanContextServicesSupport();
- sup.addService(Object.class, getProvider());
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method hasService() with Class parameter.<p>
- */
- public void testHasServiceClass() {
- try {
-
- // Instantiate services and add service
- BeanContextServicesSupport sup = new BeanContextServicesSupport();
- Class cl = new Object().getClass();
- sup.addService(cl, getProvider(), true);
-
- if (!sup.hasService(cl)) {
- fail("Service not found");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method getBeanContextServicesPeer() with no parameters.<p>
- */
- public void testGetBeanContextServicesPeer() {
- try {
-
- // Instantiate services
- BeanContextServicesSupport sup = new BeanContextServicesSupport();
-
- if (!sup.getBeanContextServicesPeer().equals(sup)) {
- fail("The objects are not equal");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method releaseBeanContextResources() with no parameters.<p>
- */
- public void testReleaseBeanContextResources() {
- try {
-
- // Instantiate services
- BeanContextServicesSupport sup = new BeanContextServicesSupport();
- sup.releaseBeanContextResources();
-
- if (sup.proxy != null) {
- fail("The resources are not released");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method initializeBeanContextResources() with no parameters.<p>
- */
- public void testInitializeBeanContextResources() {
- try {
-
- // Instantiate services
- BeanContextServicesSupport sup = new BeanContextServicesSupport();
- sup.initializeBeanContextResources();
-
- //if (sup.proxy == null) {
- //fail("The resources are not initialized");
- //}
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /** UTILITY METHODS **/
-
- /**
- * Fake implementation of provider
- */
- private BeanContextServiceProvider getProvider() {
-
- return new BeanContextServiceProvider() {
-
- public java.util.Iterator getCurrentServiceSelectors(BeanContextServices bcs,
- Class serviceClass) {
-
- return bcs.getCurrentServiceSelectors(serviceClass);
- }
-
- public Object getService(BeanContextServices bcs, Object requestor,
- Class serviceClass, Object serviceSelector) {
-
- return null;
- }
-
- public void releaseService(BeanContextServices bcs, Object requestor,
- Object service) {
- }
- };
- }
-
- /** STANDARD ENDING **/
-
- /**
- * Start testing from the command line.<p>
- */
- public static Test suite() {
- return new TestSuite(BeanContextServicesSupportTest.class);
- }
-
- /**
- * Start testing from the command line.<p>
- *
- * @param args - Command line parameters.<p>
- */
- public static void main(String args[]) {
- junit.textui.TestRunner.run(suite());
- }
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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
+ *
+ * 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.
+ */
+
+/**
+ * @author Sergey A. Krivenko
+ * @version $Revision: 1.5.2.2 $
+ */
+package java.beans.beancontext;
+
+import java.beans.beancontext.BeanContextServices;
+import java.beans.beancontext.BeanContextServicesSupport;
+import java.beans.beancontext.BeanContextServiceProvider;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test class for java.beans.beancontext.BeanContextServicesSupport.<p>
+ *
+ * @author Sergey A. Krivenko
+ * @version $Revision: 1.5.2.2 $
+ */
+
+public class BeanContextServicesSupportTest extends TestCase {
+
+ /** STANDARD BEGINNING **/
+
+ /**
+ * No arguments constructor to enable serialization.<p>
+ */
+ public BeanContextServicesSupportTest() {
+ super();
+ }
+
+ /**
+ * Constructs this test case with the given name.<p>
+ *
+ * @param name - The name for this test case.<p>
+ */
+ public BeanContextServicesSupportTest(String name) {
+ super(name);
+ }
+
+ /** TEST CONSTRUCTORS **/
+
+ /**
+ * Test constructor with BeanContextServices, Locale, boolean,
+ * boolean parameters.<p>
+ *
+ * @see BeanContextServicesSupport#BeanContextServicesSupport(
+ * BeanContextServices, Locale, boolean, boolean)
+ */
+ public void testConstructorBeanContextServicesLocalebooleanboolean() {
+ try {
+ BeanContextServicesSupport sup =
+ new BeanContextServicesSupport(null, null, true, true);
+ }
+ catch (Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test constructor with BeanContextServices, Locale, boolean parameters
+ *
+ * @see BeanContextServicesSupport#BeanContextServicesSupport(
+ * BeanContextServices, Locale, boolean)
+ */
+ public void testConstructorBeanContextServicesLocaleboolean() {
+ try {
+ BeanContextServicesSupport sup =
+ new BeanContextServicesSupport(null, null, true);
+ }
+ catch (Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test constructor with BeanContextServices, Locale parameters.<p>
+ *
+ * @see BeanContextServicesSupport#BeanContextServicesSupport(
+ * BeanContextServices, Locale)
+ */
+ public void testConstructorBeanContextServicesLocale() {
+ try {
+ BeanContextServicesSupport sup =
+ new BeanContextServicesSupport(null, null);
+ }
+ catch (Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test constructor with BeanContextServices parameter.<p>
+ *
+ * @see BeanContextServicesSupport#BeanContextServicesSupport(
+ * BeanContextServices)
+ */
+ public void testConstructorBeanContextServices() {
+ try {
+ BeanContextServicesSupport sup =
+ new BeanContextServicesSupport(null);
+ }
+ catch (Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /** * Test constructor with no parameters.<p>
+ *
+ * @see BeanContextServicesSupport#BeanContextServicesSupport()
+ */
+ public void testConstructor() {
+ try {
+ BeanContextServicesSupport sup = new BeanContextServicesSupport();
+ }
+ catch (Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /** TEST METHODS **/
+
+ /**
+ * Test method createBCSChild() with Object, Object parameters.<p>
+ */
+ public void testCreateBCSChildObjectObject() {
+ try {
+
+ // Just call the method
+ BeanContextServicesSupport sup = new BeanContextServicesSupport();
+ sup.createBCSChild(new Object(), new Object());
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method addService() with Class, BeanContextServiceProvider, boolean parameters.<p>
+ */
+ public void testAddServiceClassBeanContextServiceProviderboolean() {
+ try {
+
+ // Instantiate services and add service
+ BeanContextServicesSupport sup = new BeanContextServicesSupport();
+ sup.addService(Object.class, getProvider(), true);
+
+ if (sup.services.size() != 1) {
+ fail("One service should be registered");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method revokeService() with Class, BeanContextServiceProvider, boolean parameters.<p>
+ */
+ public void testRevokeServiceClassBeanContextServiceProviderboolean() {
+ try {
+
+ // Instantiate services, add and remove service
+ BeanContextServicesSupport sup = new BeanContextServicesSupport();
+ BeanContextServiceProvider pr = getProvider();
+ sup.addService(Object.class, pr, true);
+ sup.revokeService(Object.class, pr, true);
+
+ if (sup.services.size() != 0) {
+ fail("No service should be registered");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method addService() with Class, BeanContextServiceProvider parameters.<p>
+ */
+ public void testAddServiceClassBeanContextServiceProvider() {
+ try {
+
+ // Instantiate services and add service
+ BeanContextServicesSupport sup = new BeanContextServicesSupport();
+ sup.addService(Object.class, getProvider());
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method hasService() with Class parameter.<p>
+ */
+ public void testHasServiceClass() {
+ try {
+
+ // Instantiate services and add service
+ BeanContextServicesSupport sup = new BeanContextServicesSupport();
+ Class cl = new Object().getClass();
+ sup.addService(cl, getProvider(), true);
+
+ if (!sup.hasService(cl)) {
+ fail("Service not found");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method getBeanContextServicesPeer() with no parameters.<p>
+ */
+ public void testGetBeanContextServicesPeer() {
+ try {
+
+ // Instantiate services
+ BeanContextServicesSupport sup = new BeanContextServicesSupport();
+
+ if (!sup.getBeanContextServicesPeer().equals(sup)) {
+ fail("The objects are not equal");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method releaseBeanContextResources() with no parameters.<p>
+ */
+ public void testReleaseBeanContextResources() {
+ try {
+
+ // Instantiate services
+ BeanContextServicesSupport sup = new BeanContextServicesSupport();
+ sup.releaseBeanContextResources();
+
+ if (sup.proxy != null) {
+ fail("The resources are not released");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method initializeBeanContextResources() with no parameters.<p>
+ */
+ public void testInitializeBeanContextResources() {
+ try {
+
+ // Instantiate services
+ BeanContextServicesSupport sup = new BeanContextServicesSupport();
+ sup.initializeBeanContextResources();
+
+ //if (sup.proxy == null) {
+ //fail("The resources are not initialized");
+ //}
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method hasService() with Class=null parameter.<p>
+ */
+ public void test_hasServiceLjava_lang_Class() {
+ BeanContextServicesSupport obj = new BeanContextServicesSupport();
+ try {
+ obj.hasService(null);
+ fail("NullPointerException expected");
+ } catch (NullPointerException t) {
+ }
+ }
+
+ /**
+ * Test method removeBeanContextServicesListener() with BeanContextServicesListener=null parameter.<p>
+ */
+ public void test_removeBeanContextServicesListenerLjava_beans_beancontext_BeanContextServicesListener() {
+ BeanContextServicesSupport obj = new BeanContextServicesSupport();
+ try {
+ obj.removeBeanContextServicesListener(null);
+ fail("NullPointerException expected");
+ } catch (NullPointerException t) {
+ }
+ }
+
+ /**
+ * Test method serviceAvailable() with BeanContextServiceAvailableEvent=null parameter.<p>
+ */
+ public void test_serviceAvailableLjava_beans_beancontext_BeanContextServiceAvailableEvent() {
+ BeanContextServicesSupport obj = new BeanContextServicesSupport();
+ try {
+ obj.serviceAvailable(null);
+ fail("NullPointerException expected");
+ } catch (NullPointerException t) {
+ }
+ }
+
+ /**
+ * Test method serviceRevoked() with BeanContextServiceRevokedEvent=null parameter.<p>
+ */
+ public void test_serviceRevokedLjava_beans_beancontext_BeanContextServiceRevokedEvent() {
+ BeanContextServicesSupport obj = new BeanContextServicesSupport();
+ try {
+ obj.serviceRevoked(null);
+ fail("NullPointerException expected");
+ } catch (NullPointerException t) {
+ }
+ }
+
+ /** UTILITY METHODS **/
+
+ /**
+ * Fake implementation of provider
+ */
+ private BeanContextServiceProvider getProvider() {
+
+ return new BeanContextServiceProvider() {
+
+ public java.util.Iterator getCurrentServiceSelectors(BeanContextServices bcs,
+ Class serviceClass) {
+
+ return bcs.getCurrentServiceSelectors(serviceClass);
+ }
+
+ public Object getService(BeanContextServices bcs, Object requestor,
+ Class serviceClass, Object serviceSelector) {
+
+ return null;
+ }
+
+ public void releaseService(BeanContextServices bcs, Object requestor,
+ Object service) {
+ }
+ };
+ }
+
+ /** STANDARD ENDING **/
+
+ /**
+ * Start testing from the command line.<p>
+ */
+ public static Test suite() {
+ return new TestSuite(BeanContextServicesSupportTest.class);
+ }
+
+ /**
+ * Start testing from the command line.<p>
+ *
+ * @param args - Command line parameters.<p>
+ */
+ public static void main(String args[]) {
+ junit.textui.TestRunner.run(suite());
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/java/beans/beancontext/BeanContextSupportTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/java/beans/beancontext/BeanContextSupportTest.java?rev=395159&r1=395158&r2=395159&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/java/beans/beancontext/BeanContextSupportTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/java/beans/beancontext/BeanContextSupportTest.java Wed Apr 19 00:50:45 2006
@@ -1,706 +1,773 @@
-/*
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed 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
- *
- * 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.
- */
-
-/**
- * @author Sergey A. Krivenko
- * @version $Revision: 1.4.4.2 $
- */
-package java.beans.beancontext;
-
-import java.beans.beancontext.BeanContextSupport;
-import java.beans.beancontext.BeanContextMembershipEvent;
-import java.beans.beancontext.BeanContextMembershipListener;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test class for java.beans.beancontext.BeanContextSupport.<p>
- *
- * @author Sergey A. Krivenko
- * @version $Revision: 1.4.4.2 $
- */
-
-public class BeanContextSupportTest extends TestCase {
-
- /** STANDARD BEGINNING **/
-
- /**
- * No arguments constructor to enable serialization.<p>
- */
- public BeanContextSupportTest() {
- super();
- }
-
- /**
- * Constructs this test case with the given name.<p>
- *
- * @param name - The name for this test case.<p>
- */
- public BeanContextSupportTest(String name) {
- super(name);
- }
-
- /** TEST CONSTRUCTORS **/
-
- /** * Test constructor with BeanContext, Locale, boolean, boolean parameters.<p>
- *
- * @see BeanContextSupport#BeanContextSupport(BeanContext, Locale, boolean, boolean)
- */
- public void testConstructorBeanContextLocalebooleanboolean() {
- try {
- BeanContextSupport sup = new BeanContextSupport(null, null, true, true);
- }
- catch (Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /** * Test constructor with BeanContext, Locale, boolean parameters.<p>
- *
- * @see BeanContextSupport#BeanContextSupport(BeanContext, Locale, boolean)
- */
- public void testConstructorBeanContextLocaleboolean() {
- try {
- BeanContextSupport sup = new BeanContextSupport(null, null, true);
- }
- catch (Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /** * Test constructor with BeanContext, Locale parameters.<p>
- *
- * @see BeanContextSupport#BeanContextSupport(BeanContext, Locale)
- */
- public void testConstructorBeanContextLocale() {
- try {
- BeanContextSupport sup = new BeanContextSupport(null, null);
- }
- catch (Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /** * Test constructor with BeanContext parameter.<p>
- *
- * @see BeanContextSupport#BeanContextSupport(BeanContext)
- */
- public void testConstructorBeanContext() {
- try {
- BeanContextSupport sup = new BeanContextSupport(null);
- }
- catch (Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /** * Test constructor with no parameters.<p>
- *
- * @see BeanContextSupport#BeanContextSupport()
- */
- public void testConstructor() {
- try {
- BeanContextSupport sup = new BeanContextSupport();
- }
- catch (Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /** TEST METHODS **/
-
- /**
- * Test method createBCSChild() with Object, Object parameters.<p>
- */
- public void testCreateBCSChildObjectObject() {
- try {
- BeanContextSupport sup = new BeanContextSupport();
- sup.createBCSChild(new BeanContextSupport(), new BeanContextSupport());
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method setLocale() with Locale parameter.<p>
- */
- public void testSetLocaleLocale() {
- try {
- BeanContextSupport sup = new BeanContextSupport();
- sup.setLocale(null);
-
- if (!sup.getLocale().equals(java.util.Locale.getDefault())) {
- fail("BeanContext should have default locale");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method bcsChildren() with no parameters.<p>
- */
- public void testBcsChildren() {
- try {
- BeanContextSupport sup = new BeanContextSupport();
- sup.add(new BeanContextChildSupport());
-
- for (java.util.Iterator it = sup.bcsChildren(); it.hasNext(); ) {
- Object next = it.next();
-
- if (!(next instanceof BeanContextSupport.BCSChild)) {
- fail("Children must be instances of " +
- "BeanContextSupport.BCSChild class " +
- "but at least one of them: " + next.getClass());
- }
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method retainAll() with Collection parameter.<p>
- */
- public void testRetainAllCollection() {
- try {
-
- /*// Create an instance and add one child
- BeanContextSupport sup = new BeanContextSupport();
- BeanContextChildSupport ch = new BeanContextChildSupport();
- sup.add(ch);
-
- // Create collection with an instance of the child that was added
- java.util.Collection col = new java.util.ArrayList();
- col.add(ch);
-
- // Remove all children that are not in the collection
- // The collection must remain unchanged
- if (sup.retainAll(col)) {
- fail("False should be returned");
- }
-
- // Just one child must be present
- if (sup.size() != 1) {
- fail("The size of the collection must be 1");
- }
-
- // Add a new child in the collection and remove the old one
- col.clear();
- col.add(new Object());
-
- // Remove all children that are not in the collection
- // The collection must have 0 elements after that
- if (!sup.retainAll(col)) {
- fail("True should be returned");
- }
-
- // No children must be present
- if (sup.size() != 0) {
- fail("The size of the collection must be 0");
- }*/
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method removeAll() with Collection parameter.<p>
- */
- public void testRemoveAllCollection() {
- try {
-
- /*// Create an instance and add one child
- BeanContextSupport sup = new BeanContextSupport();
- BeanContextChildSupport ch = new BeanContextChildSupport();
- sup.add(ch);
-
- // Create collection with an instance of an arbitrary child
- java.util.Collection col = new java.util.ArrayList();
- col.add(new Object());
-
- // Remove all children that are in the collection
- // The collection should not change after that
- if (sup.removeAll(col)) {
- fail("False should be returned");
- }
-
- // Add a child that is a member of the BeanContext
- col.add(ch);
-
- // Remove all children that are in the collection
- // The collection should change after that
- if (!sup.removeAll(col)) {
- fail("True should be returned");
- }
-
- // No children must be present
- if (sup.size() != 0) {
- fail("The size of the collection must be 0 but is " + sup.size());
- }*/
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method containsAll() with Collection parameter.<p>
- */
- public void testContainsAllCollection() {
- try {
-
- /*// Create an instance and add two children
- BeanContextSupport sup = new BeanContextSupport();
- BeanContextChildSupport ch = new BeanContextChildSupport();
- Object obj = new Object();
- sup.add(ch);
- sup.add(obj);
-
- // Create collection with BCS children that just were added
- java.util.Collection col = new java.util.ArrayList();
-
- for (java.util.Iterator it = sup.bcsChildren(); it.hasNext(); ) {
- col.add(it.next());
- }
-
- // Two collections have the same elements
- if (!sup.containsAll(col)) {
- fail("True should be returned");
- }
-
- sup.remove(obj);
-
- // Now they are different
- if (sup.containsAll(col)) {
- fail("False should be returned");
- }*/
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method addAll() with Collection parameter.<p>
- */
- public void testAddAllCollection() {
- try {
-
- /*// Create an instance and add two children
- BeanContextSupport sup = new BeanContextSupport();
-
- // Create collection with two elements
- java.util.Collection col = new java.util.ArrayList();
- col.add(new BeanContextChildSupport());
- col.add(new Object());
-
- // Place two children into the BeanContext
- if (!sup.addAll(col)) {
- fail("True should be returned");
- }
-
- // Two children must be present
- if (sup.size() != 2) {
- fail("The size of the collection must be 2 but is " + sup.size());
- }*/
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method remove() with Object, boolean parameters.<p>
- */
- public void testRemoveObjectboolean() {
- try {
-
- // Create an instance and add one child
- BeanContextSupport sup = new BeanContextSupport();
- BeanContextChildSupport ch = new BeanContextChildSupport();
- sup.add(ch);
-
- // Remove unexisting child
- if (sup.remove(new Object(), true)) {
- fail("False should be returned");
- }
-
- // Remove it
- if (!sup.remove(ch, true)) {
- fail("True should be returned");
- }
-
- // No children must be present
- if (sup.size() != 0) {
- fail("The size of the collection must be 0 but is " + sup.size());
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method remove() with Object parameter.<p>
- */
- public void testRemoveObject() {
- try {
-
- // Create an instance and add one child
- BeanContextSupport sup = new BeanContextSupport();
- BeanContextChildSupport ch = new BeanContextChildSupport();
- sup.add(ch);
-
- // Remove unexisting child
- if (sup.remove(new Object())) {
- fail("False should be returned");
- }
-
- // Remove it
- if (!sup.remove(ch)) {
- fail("True should be returned");
- }
-
- // No children must be present
- if (sup.size() != 0) {
- fail("The size of the collection must be 0 but is " + sup.size());
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method containsKey() with Object parameter.<p>
- */
- public void testContainsKeyObject() {
- try {
-
- // Create an instance and add a child
- BeanContextSupport sup = new BeanContextSupport();
- BeanContextChildSupport ch = new BeanContextChildSupport();
- sup.add(ch);
-
- // We should find the child now
- if (!sup.containsKey(ch)) {
- fail("True should be returned");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method contains() with Object parameter.<p>
- */
- public void testContainsObject() {
- try {
-
- // Create an instance and add a child
- BeanContextSupport sup = new BeanContextSupport();
- BeanContextChildSupport ch = new BeanContextChildSupport();
- sup.add(ch);
-
- BeanContextSupport.BCSChild bcs =
- (BeanContextSupport.BCSChild) sup.bcsChildren().next();
-
- // We should find the child now
- if (!sup.contains(bcs)) {
- // fail("True should be returned");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method add() with Object parameter.<p>
- */
- public void testAddObject() {
- try {
-
- // Create an instance and add a child
- BeanContextSupport sup = new BeanContextSupport();
- sup.add(new Object());
-
- // Just one child must be present
- if (sup.size() != 1) {
- fail("The size of the collection must be 1 but is " + sup.size());
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method toArray() with no parameters.<p>
- */
- public void testToArray() {
- try {
-
- // Create an instance and add two children
- BeanContextSupport sup = new BeanContextSupport();
- sup.add("obj1");
- sup.add("obj2");
-
- // Convert to array
- Object[] array = sup.toArray();
-
- // Check length
- if (array.length != 2) {
- fail("The size of the collection must be 2 but is " + array.length);
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method copyChildren() with no parameters.<p>
- */
- public void testCopyChildren() {
- try {
-
- // Create an instance and add two children
- BeanContextSupport sup = new BeanContextSupport();
- sup.add("obj1");
- sup.add("obj2");
-
- // Convert to array
- Object[] array = sup.copyChildren();
-
- // Check length
- if (array.length != 2) {
- fail("The size of the collection must be 2 but is " + array.length);
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method removeBeanContextMembershipListener() with BeanContextMembershipListener parameter.<p>
- */
- public void testRemoveBeanContextMembershipListenerBeanContextMembershipListener() {
- try {
-
- // Create BeanContext and BeanContextMembershipListener instances
- BeanContextSupport sup = new BeanContextSupport();
- BeanContextMembershipListener l = getBeanContextMembershipListener();
- sup.addBeanContextMembershipListener(l);
- sup.removeBeanContextMembershipListener(l);
-
- // Check if it's there
- if (sup.bcmListeners.contains(l)) {
- fail("Listener should not be present");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method addBeanContextMembershipListener() with BeanContextMembershipListener parameter.<p>
- */
- public void testAddBeanContextMembershipListenerBeanContextMembershipListener() {
- try {
-
- // Create BeanContext and BeanContextMembershipListener instances
- BeanContextSupport sup = new BeanContextSupport();
- BeanContextMembershipListener l = getBeanContextMembershipListener();
- sup.addBeanContextMembershipListener(l);
-
- // Check if it's there
- if (!sup.bcmListeners.contains(l)) {
- fail("Listener should be present");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method getBeanContextPeer() with no parameters.<p>
- */
- public void testGetBeanContextPeer() {
- try {
-
- // Create BeanContext instance
- BeanContextSupport sup = new BeanContextSupport();
-
- // The peer and this context should be equal
- if (!sup.getBeanContextPeer().equals(sup)) {
- fail("The peer and the BeanContext should be equal");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method vetoableChange() with PropertyChangeEvent parameter.<p>
- */
- public void testVetoableChangePropertyChangeEvent() {
- try {
-
- /** @todo: not implemented yet in the class **/
- // Create BeanContext instance
- BeanContextSupport sup = new BeanContextSupport();
- //sup.vetoableChange(null);
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method propertyChange() with PropertyChangeEvent parameter.<p>
- */
- public void testPropertyChangePropertyChangeEvent() {
- try {
-
- /** @todo: not implemented yet in the class **/
- // Create BeanContext instance
- BeanContextSupport sup = new BeanContextSupport();
- //sup.propertyChange(null);
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method isEmpty() with no parameters.<p>
- */
- public void testIsEmpty() {
- try {
-
- // Create BeanContext instance
- BeanContextSupport sup = new BeanContextSupport();
-
- if (!sup.isEmpty()) {
- fail("The collection of children should be empty");
- }
-
- sup.add(new Object());
-
- if (sup.isEmpty()) {
- fail("The collection of children should not be empty");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method clear() with no parameters.<p>
- */
- public void testClear() {
- try {
-
- /*// Create BeanContext instance
- BeanContextSupport sup = new BeanContextSupport();
-
- // Add a child and then clear
- sup.add(new Object());
- sup.clear();
-
- if (!sup.isEmpty()) {
- fail("The collection of children should be empty");
- }*/
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /**
- * Test method size() with no parameters.<p>
- */
- public void testSize() {
- try {
-
- // Create BeanContext instance
- BeanContextSupport sup = new BeanContextSupport();
-
- if (sup.size() != 0) {
- fail("The size of the collection should be equal to 0");
- }
-
- sup.add(new Object());
-
- if (sup.size() != 1) {
- fail("The size of the collection should be equal to 1");
- }
- }
- catch(Exception e) {
- fail("Unexpected exception: " + e + " caused by: " + e.getCause());
- }
- }
-
- /** UTILITY METHODS **/
-
- /**
- * Create BeanContextMembershipListener instance
- */
- private BeanContextMembershipListener getBeanContextMembershipListener() {
- return new BeanContextMembershipListener() {
-
- public void childrenAdded(BeanContextMembershipEvent bcme) {
- ;
- }
-
- public void childrenRemoved(BeanContextMembershipEvent bcme) {
- ;
- }
- };
- }
-
- /** STANDARD ENDING **/
-
- /**
- * Start testing from the command line.<p>
- */
- public static Test suite() {
- return new TestSuite(BeanContextSupportTest.class);
- }
-
- /**
- * Start testing from the command line.<p>
- *
- * @param args - Command line parameters.<p>
- */
- public static void main(String args[]) {
- junit.textui.TestRunner.run(suite());
- }
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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
+ *
+ * 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.
+ */
+
+/**
+ * @author Sergey A. Krivenko
+ * @version $Revision: 1.4.4.2 $
+ */
+package java.beans.beancontext;
+
+import java.beans.beancontext.BeanContextSupport;
+import java.beans.beancontext.BeanContextMembershipEvent;
+import java.beans.beancontext.BeanContextMembershipListener;
+import java.beans.PropertyVetoException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test class for java.beans.beancontext.BeanContextSupport.<p>
+ *
+ * @author Sergey A. Krivenko
+ * @version $Revision: 1.4.4.2 $
+ */
+
+public class BeanContextSupportTest extends TestCase {
+
+ /** STANDARD BEGINNING **/
+
+ /**
+ * No arguments constructor to enable serialization.<p>
+ */
+ public BeanContextSupportTest() {
+ super();
+ }
+
+ /**
+ * Constructs this test case with the given name.<p>
+ *
+ * @param name - The name for this test case.<p>
+ */
+ public BeanContextSupportTest(String name) {
+ super(name);
+ }
+
+ /** TEST CONSTRUCTORS **/
+
+ /** * Test constructor with BeanContext, Locale, boolean, boolean parameters.<p>
+ *
+ * @see BeanContextSupport#BeanContextSupport(BeanContext, Locale, boolean, boolean)
+ */
+ public void testConstructorBeanContextLocalebooleanboolean() {
+ try {
+ BeanContextSupport sup = new BeanContextSupport(null, null, true, true);
+ }
+ catch (Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /** * Test constructor with BeanContext, Locale, boolean parameters.<p>
+ *
+ * @see BeanContextSupport#BeanContextSupport(BeanContext, Locale, boolean)
+ */
+ public void testConstructorBeanContextLocaleboolean() {
+ try {
+ BeanContextSupport sup = new BeanContextSupport(null, null, true);
+ }
+ catch (Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /** * Test constructor with BeanContext, Locale parameters.<p>
+ *
+ * @see BeanContextSupport#BeanContextSupport(BeanContext, Locale)
+ */
+ public void testConstructorBeanContextLocale() {
+ try {
+ BeanContextSupport sup = new BeanContextSupport(null, null);
+ }
+ catch (Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /** * Test constructor with BeanContext parameter.<p>
+ *
+ * @see BeanContextSupport#BeanContextSupport(BeanContext)
+ */
+ public void testConstructorBeanContext() {
+ try {
+ BeanContextSupport sup = new BeanContextSupport(null);
+ }
+ catch (Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /** * Test constructor with no parameters.<p>
+ *
+ * @see BeanContextSupport#BeanContextSupport()
+ */
+ public void testConstructor() {
+ try {
+ BeanContextSupport sup = new BeanContextSupport();
+ }
+ catch (Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /** TEST METHODS **/
+
+ /**
+ * Test method createBCSChild() with Object, Object parameters.<p>
+ */
+ public void testCreateBCSChildObjectObject() {
+ try {
+ BeanContextSupport sup = new BeanContextSupport();
+ sup.createBCSChild(new BeanContextSupport(), new BeanContextSupport());
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method setLocale() with Locale parameter.<p>
+ */
+ public void testSetLocaleLocale() {
+ try {
+ BeanContextSupport sup = new BeanContextSupport();
+ sup.setLocale(null);
+
+ if (!sup.getLocale().equals(java.util.Locale.getDefault())) {
+ fail("BeanContext should have default locale");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method bcsChildren() with no parameters.<p>
+ */
+ public void testBcsChildren() {
+ try {
+ BeanContextSupport sup = new BeanContextSupport();
+ sup.add(new BeanContextChildSupport());
+
+ for (java.util.Iterator it = sup.bcsChildren(); it.hasNext(); ) {
+ Object next = it.next();
+
+ if (!(next instanceof BeanContextSupport.BCSChild)) {
+ fail("Children must be instances of " +
+ "BeanContextSupport.BCSChild class " +
+ "but at least one of them: " + next.getClass());
+ }
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method retainAll() with Collection parameter.<p>
+ */
+ public void testRetainAllCollection() {
+ try {
+
+ /*// Create an instance and add one child
+ BeanContextSupport sup = new BeanContextSupport();
+ BeanContextChildSupport ch = new BeanContextChildSupport();
+ sup.add(ch);
+
+ // Create collection with an instance of the child that was added
+ java.util.Collection col = new java.util.ArrayList();
+ col.add(ch);
+
+ // Remove all children that are not in the collection
+ // The collection must remain unchanged
+ if (sup.retainAll(col)) {
+ fail("False should be returned");
+ }
+
+ // Just one child must be present
+ if (sup.size() != 1) {
+ fail("The size of the collection must be 1");
+ }
+
+ // Add a new child in the collection and remove the old one
+ col.clear();
+ col.add(new Object());
+
+ // Remove all children that are not in the collection
+ // The collection must have 0 elements after that
+ if (!sup.retainAll(col)) {
+ fail("True should be returned");
+ }
+
+ // No children must be present
+ if (sup.size() != 0) {
+ fail("The size of the collection must be 0");
+ }*/
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method removeAll() with Collection parameter.<p>
+ */
+ public void testRemoveAllCollection() {
+ try {
+
+ /*// Create an instance and add one child
+ BeanContextSupport sup = new BeanContextSupport();
+ BeanContextChildSupport ch = new BeanContextChildSupport();
+ sup.add(ch);
+
+ // Create collection with an instance of an arbitrary child
+ java.util.Collection col = new java.util.ArrayList();
+ col.add(new Object());
+
+ // Remove all children that are in the collection
+ // The collection should not change after that
+ if (sup.removeAll(col)) {
+ fail("False should be returned");
+ }
+
+ // Add a child that is a member of the BeanContext
+ col.add(ch);
+
+ // Remove all children that are in the collection
+ // The collection should change after that
+ if (!sup.removeAll(col)) {
+ fail("True should be returned");
+ }
+
+ // No children must be present
+ if (sup.size() != 0) {
+ fail("The size of the collection must be 0 but is " + sup.size());
+ }*/
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method containsAll() with Collection parameter.<p>
+ */
+ public void testContainsAllCollection() {
+ try {
+
+ /*// Create an instance and add two children
+ BeanContextSupport sup = new BeanContextSupport();
+ BeanContextChildSupport ch = new BeanContextChildSupport();
+ Object obj = new Object();
+ sup.add(ch);
+ sup.add(obj);
+
+ // Create collection with BCS children that just were added
+ java.util.Collection col = new java.util.ArrayList();
+
+ for (java.util.Iterator it = sup.bcsChildren(); it.hasNext(); ) {
+ col.add(it.next());
+ }
+
+ // Two collections have the same elements
+ if (!sup.containsAll(col)) {
+ fail("True should be returned");
+ }
+
+ sup.remove(obj);
+
+ // Now they are different
+ if (sup.containsAll(col)) {
+ fail("False should be returned");
+ }*/
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method addAll() with Collection parameter.<p>
+ */
+ public void testAddAllCollection() {
+ try {
+
+ /*// Create an instance and add two children
+ BeanContextSupport sup = new BeanContextSupport();
+
+ // Create collection with two elements
+ java.util.Collection col = new java.util.ArrayList();
+ col.add(new BeanContextChildSupport());
+ col.add(new Object());
+
+ // Place two children into the BeanContext
+ if (!sup.addAll(col)) {
+ fail("True should be returned");
+ }
+
+ // Two children must be present
+ if (sup.size() != 2) {
+ fail("The size of the collection must be 2 but is " + sup.size());
+ }*/
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method remove() with Object, boolean parameters.<p>
+ */
+ public void testRemoveObjectboolean() {
+ try {
+
+ // Create an instance and add one child
+ BeanContextSupport sup = new BeanContextSupport();
+ BeanContextChildSupport ch = new BeanContextChildSupport();
+ sup.add(ch);
+
+ // Remove unexisting child
+ if (sup.remove(new Object(), true)) {
+ fail("False should be returned");
+ }
+
+ // Remove it
+ if (!sup.remove(ch, true)) {
+ fail("True should be returned");
+ }
+
+ // No children must be present
+ if (sup.size() != 0) {
+ fail("The size of the collection must be 0 but is " + sup.size());
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method remove() with Object parameter.<p>
+ */
+ public void testRemoveObject() {
+ try {
+
+ // Create an instance and add one child
+ BeanContextSupport sup = new BeanContextSupport();
+ BeanContextChildSupport ch = new BeanContextChildSupport();
+ sup.add(ch);
+
+ // Remove unexisting child
+ if (sup.remove(new Object())) {
+ fail("False should be returned");
+ }
+
+ // Remove it
+ if (!sup.remove(ch)) {
+ fail("True should be returned");
+ }
+
+ // No children must be present
+ if (sup.size() != 0) {
+ fail("The size of the collection must be 0 but is " + sup.size());
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method containsKey() with Object parameter.<p>
+ */
+ public void testContainsKeyObject() {
+ try {
+
+ // Create an instance and add a child
+ BeanContextSupport sup = new BeanContextSupport();
+ BeanContextChildSupport ch = new BeanContextChildSupport();
+ sup.add(ch);
+
+ // We should find the child now
+ if (!sup.containsKey(ch)) {
+ fail("True should be returned");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method contains() with Object parameter.<p>
+ */
+ public void testContainsObject() {
+ try {
+
+ // Create an instance and add a child
+ BeanContextSupport sup = new BeanContextSupport();
+ BeanContextChildSupport ch = new BeanContextChildSupport();
+ sup.add(ch);
+
+ BeanContextSupport.BCSChild bcs =
+ (BeanContextSupport.BCSChild) sup.bcsChildren().next();
+
+ // We should find the child now
+ if (!sup.contains(bcs)) {
+ // fail("True should be returned");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method add() with Object parameter.<p>
+ */
+ public void testAddObject() {
+ try {
+
+ // Create an instance and add a child
+ BeanContextSupport sup = new BeanContextSupport();
+ sup.add(new Object());
+
+ // Just one child must be present
+ if (sup.size() != 1) {
+ fail("The size of the collection must be 1 but is " + sup.size());
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method toArray() with no parameters.<p>
+ */
+ public void testToArray() {
+ try {
+
+ // Create an instance and add two children
+ BeanContextSupport sup = new BeanContextSupport();
+ sup.add("obj1");
+ sup.add("obj2");
+
+ // Convert to array
+ Object[] array = sup.toArray();
+
+ // Check length
+ if (array.length != 2) {
+ fail("The size of the collection must be 2 but is " + array.length);
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method copyChildren() with no parameters.<p>
+ */
+ public void testCopyChildren() {
+ try {
+
+ // Create an instance and add two children
+ BeanContextSupport sup = new BeanContextSupport();
+ sup.add("obj1");
+ sup.add("obj2");
+
+ // Convert to array
+ Object[] array = sup.copyChildren();
+
+ // Check length
+ if (array.length != 2) {
+ fail("The size of the collection must be 2 but is " + array.length);
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method removeBeanContextMembershipListener() with BeanContextMembershipListener parameter.<p>
+ */
+ public void testRemoveBeanContextMembershipListenerBeanContextMembershipListener() {
+ try {
+
+ // Create BeanContext and BeanContextMembershipListener instances
+ BeanContextSupport sup = new BeanContextSupport();
+ BeanContextMembershipListener l = getBeanContextMembershipListener();
+ sup.addBeanContextMembershipListener(l);
+ sup.removeBeanContextMembershipListener(l);
+
+ // Check if it's there
+ if (sup.bcmListeners.contains(l)) {
+ fail("Listener should not be present");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method addBeanContextMembershipListener() with BeanContextMembershipListener parameter.<p>
+ */
+ public void testAddBeanContextMembershipListenerBeanContextMembershipListener() {
+ try {
+
+ // Create BeanContext and BeanContextMembershipListener instances
+ BeanContextSupport sup = new BeanContextSupport();
+ BeanContextMembershipListener l = getBeanContextMembershipListener();
+ sup.addBeanContextMembershipListener(l);
+
+ // Check if it's there
+ if (!sup.bcmListeners.contains(l)) {
+ fail("Listener should be present");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method getBeanContextPeer() with no parameters.<p>
+ */
+ public void testGetBeanContextPeer() {
+ try {
+
+ // Create BeanContext instance
+ BeanContextSupport sup = new BeanContextSupport();
+
+ // The peer and this context should be equal
+ if (!sup.getBeanContextPeer().equals(sup)) {
+ fail("The peer and the BeanContext should be equal");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method vetoableChange() with PropertyChangeEvent parameter.<p>
+ */
+ public void testVetoableChangePropertyChangeEvent() {
+ try {
+
+ /** @todo: not implemented yet in the class **/
+ // Create BeanContext instance
+ BeanContextSupport sup = new BeanContextSupport();
+ //sup.vetoableChange(null);
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method propertyChange() with PropertyChangeEvent parameter.<p>
+ */
+ public void testPropertyChangePropertyChangeEvent() {
+ try {
+
+ /** @todo: not implemented yet in the class **/
+ // Create BeanContext instance
+ BeanContextSupport sup = new BeanContextSupport();
+ //sup.propertyChange(null);
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method isEmpty() with no parameters.<p>
+ */
+ public void testIsEmpty() {
+ try {
+
+ // Create BeanContext instance
+ BeanContextSupport sup = new BeanContextSupport();
+
+ if (!sup.isEmpty()) {
+ fail("The collection of children should be empty");
+ }
+
+ sup.add(new Object());
+
+ if (sup.isEmpty()) {
+ fail("The collection of children should not be empty");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method clear() with no parameters.<p>
+ */
+ public void testClear() {
+ try {
+
+ /*// Create BeanContext instance
+ BeanContextSupport sup = new BeanContextSupport();
+
+ // Add a child and then clear
+ sup.add(new Object());
+ sup.clear();
+
+ if (!sup.isEmpty()) {
+ fail("The collection of children should be empty");
+ }*/
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method size() with no parameters.<p>
+ */
+ public void testSize() {
+ try {
+
+ // Create BeanContext instance
+ BeanContextSupport sup = new BeanContextSupport();
+
+ if (sup.size() != 0) {
+ fail("The size of the collection should be equal to 0");
+ }
+
+ sup.add(new Object());
+
+ if (sup.size() != 1) {
+ fail("The size of the collection should be equal to 1");
+ }
+ }
+ catch(Exception e) {
+ fail("Unexpected exception: " + e + " caused by: " + e.getCause());
+ }
+ }
+
+ /**
+ * Test method getResourceAsStream() with String, BeanContextChild=null parameters.<p>
+ */
+ public void test_getResourceAsStreamLlava_lang_StringLjava_beans_beancontext_BeanContextChild() {
+ BeanContextSupport obj = new BeanContextSupport();
+ try {
+ obj.getResourceAsStream(new String(), null);
+ fail("NullPointerException expected");
+ } catch (NullPointerException t) {
+ }
+ }
+
+ /**
+ * Test method getResourceAsStream() with String=null, BeanContextChild=null parameters.<p>
+ */
+ public void test_getResourceAsStreamLlava_lang_StringLjava_beans_beancontext_BeanContextChild2() {
+ BeanContextSupport obj = new BeanContextSupport();
+ try {
+ obj.getResourceAsStream(null, null);
+ fail("NullPointerException expected");
+ } catch (IllegalArgumentException t) {
+ fail("NullPointerException expected");
+ } catch (NullPointerException t) {
+ }
+ }
+
+ /**
+ * Test method vetoableChange() with PropertyChangeEvent=null parameter.<p>
+ */
+ public void test_vetoableChangeLjava_beans_PropertyChangeEvent() {
+ BeanContextSupport obj = new BeanContextSupport();
+ try {
+ obj.vetoableChange(null);
+ fail("NullPointerException expected");
+ } catch (PropertyVetoException p) {
+ fail("NullPointerException expected");
+ } catch (NullPointerException t) {
+ }
+ }
+
+ /**
+ * Test method getResource() with String!=null, BeanContextChild=null parameters.<p>
+ */
+ public void test_getResourceLjava_lang_StringLjava_beans_beancontext_BeanContextChild() {
+ BeanContextSupport obj = new BeanContextSupport();
+ try {
+ obj.getResource("", null);
+ fail("NullPointerException expected");
+ } catch (NullPointerException t) {
+ }
+ }
+
+ /**
+ * Test method getResource() with String=null, BeanContextChild=null parameters.<p>
+ */
+ public void test_getResourceLjava_lang_StringLjava_beans_beancontext_BeanContextChild2() {
+ BeanContextSupport obj = new BeanContextSupport();
+ try {
+ obj.getResource(null, null);
+ fail("NullPointerException expected");
+ } catch (IllegalArgumentException t) {
+ fail("NullPointerException expected");
+ } catch (NullPointerException t) {
+ }
+ }
+
+ /** UTILITY METHODS **/
+
+ /**
+ * Create BeanContextMembershipListener instance
+ */
+ private BeanContextMembershipListener getBeanContextMembershipListener() {
+ return new BeanContextMembershipListener() {
+
+ public void childrenAdded(BeanContextMembershipEvent bcme) {
+ ;
+ }
+
+ public void childrenRemoved(BeanContextMembershipEvent bcme) {
+ ;
+ }
+ };
+ }
+
+ /** STANDARD ENDING **/
+
+ /**
+ * Start testing from the command line.<p>
+ */
+ public static Test suite() {
+ return new TestSuite(BeanContextSupportTest.class);
+ }
+
+ /**
+ * Start testing from the command line.<p>
+ *
+ * @param args - Command line parameters.<p>
+ */
+ public static void main(String args[]) {
+ junit.textui.TestRunner.run(suite());
+ }
}