commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r1507564 - in /commons/proper/proxy/branches/version-2.0-work/core/src: main/java/org/apache/commons/proxy2/provider/BeanProvider.java test/java/org/apache/commons/proxy2/provider/TestBeanProvider.java
Date Sat, 27 Jul 2013 02:46:34 GMT
Author: jcarman
Date: Sat Jul 27 02:46:33 2013
New Revision: 1507564

URL: http://svn.apache.org/r1507564
Log:
Simplifying BeanProvider.

Modified:
    commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/provider/BeanProvider.java
    commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/provider/TestBeanProvider.java

Modified: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/provider/BeanProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/provider/BeanProvider.java?rev=1507564&r1=1507563&r2=1507564&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/provider/BeanProvider.java
(original)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/provider/BeanProvider.java
Sat Jul 27 02:46:33 2013
@@ -17,6 +17,8 @@
 
 package org.apache.commons.proxy2.provider;
 
+import org.apache.commons.lang3.SerializationUtils;
+import org.apache.commons.lang3.Validate;
 import org.apache.commons.proxy2.ObjectProvider;
 import org.apache.commons.proxy2.exception.ObjectProviderException;
 
@@ -37,18 +39,11 @@ public class BeanProvider<T> implements 
 // Fields
 //**********************************************************************************************************************
 
-    private Class<? extends T> beanClass;
+    private final Class<? extends T> beanClass;
 
-  //**********************************************************************************************************************
- // Constructors
- //**********************************************************************************************************************
-
-    /**
-     * Create a new BeanProvider instance.
-     */
-    public BeanProvider()
-    {
-    }
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
 
     /**
      * Constructs a provider which instantiates objects of the specified bean class.
@@ -57,12 +52,13 @@ public class BeanProvider<T> implements 
      */
     public BeanProvider( Class<? extends T> beanClass )
     {
+        Validate.notNull(beanClass, "Bean class cannot be null.");
         this.beanClass = beanClass;
     }
 
-  //**********************************************************************************************************************
- // ObjectProvider Implementation
- //**********************************************************************************************************************
+//**********************************************************************************************************************
+// ObjectProvider Implementation
+//**********************************************************************************************************************
 
     /**
      * {@inheritDoc}
@@ -71,10 +67,6 @@ public class BeanProvider<T> implements 
     {
         try
         {
-            if( beanClass == null )
-            {
-                throw new ObjectProviderException("No bean class provided.");
-            }
             return beanClass.newInstance();
         }
         catch( InstantiationException e )
@@ -87,16 +79,4 @@ public class BeanProvider<T> implements 
                     e);
         }
     }
-
-  //**********************************************************************************************************************
- // Getter/Setter Methods
- //**********************************************************************************************************************
-
-    /**
-     * Set the beanClass.
-     * @param beanClass the Class<T> to set
-     */
-    public void setBeanClass(Class<? extends T> beanClass) {
-        this.beanClass = beanClass;
-    }
 }

Modified: commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/provider/TestBeanProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/provider/TestBeanProvider.java?rev=1507564&r1=1507563&r2=1507564&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/provider/TestBeanProvider.java
(original)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/provider/TestBeanProvider.java
Sat Jul 27 02:46:33 2013
@@ -30,8 +30,7 @@ public class TestBeanProvider extends Ab
     {
         try
         {
-            final BeanProvider<Number> p = new BeanProvider<Number>();
-            p.setBeanClass(Number.class);
+            final BeanProvider<Number> p = new BeanProvider<Number>(Number.class);
             p.getObject();
             fail();
         }
@@ -61,11 +60,11 @@ public class TestBeanProvider extends Ab
     {
         try
         {
-            final BeanProvider<Object> p = new BeanProvider<Object>();
+            final BeanProvider<Object> p = new BeanProvider<Object>(null);
             p.getObject();
-            fail();
+            fail("Should throw NullPointerException.");
         }
-        catch( ObjectProviderException e )
+        catch( NullPointerException e )
         {
         }
     }



Mime
View raw message