#22 provide a class factory support

open
nobody
5
2005-11-17
2005-11-17
Anonymous
No

Hi,

I use the 1.4 version.

Some of my tests fail because the setter should receive
an instance of a class where the is no default
constructor such as java.sql.Date.
I suppose that this is the same for Integer, Double...
As a result I canot use the library for a lot of my
classes.

I suggest to implement the following change
- create an interface ObjectFactory with a single
method <<Object getInstance(final Class clazz)>>
- create a class DefaultObjectFactory impleting the
interface for the most common classes
(java.sql.Date...). If the class is not one of the
supported one, return a null or throw some exception.
- define an abstract factory (pattern) support to let
the user override the default factory (using some -D
property on the command line or in a properties file or
some method) by providing a class name
- provide a method to retrieve the default factory and
the current factory (or to change it)
- as a user I can now define my own factory which
replaces yours or it does its job and call yours for
the classes it does not support)
- in the method breaking below call the abstract
factory to create an instance of the class
- update your tests so they don't break if a null is
returned for the instance of the class

These changes will really help the library to be a lot
more useful.

Thanks
Olivier

INFO: Unable to obtain instance of java.sql.Date.
java.lang.InstantiationException: java.sql.Date
at java.lang.Class.newInstance0(Class.java:293)
at java.lang.Class.newInstance(Class.java:261)
at
jbeantester.framework.JBeanTester.getParamToUse(JBeanTester.java:153)
at
jbeantester.framework.JBeanTester.testJBeanProperties(JBeanTester.java:303)
at
jbeantester.junit.BaseTestCase.testJBeanProperties(BaseTestCase.java:91)
at
pwgsc.reo.common.data.UserNotificationDataTest.testGetterSetter(UserNotificationDataTest.java:93)

Discussion