You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Giovanni Azua <gi...@imc.nl> on 2008/02/29 10:19:31 UTC
question on copyProperties usage
hi all,
I have not been able to have the following test case pass under 1.7 and 1.8.
Here the list of trial-errors:
- Assigning to myMap property names starting upper case does not provide
any error as I would expect it should i.e. IllegalArgumentException
"Malformed property names provided in Map"
- Assigning proper property names i.e. "propertyA" I consistently get
InvokationTargetException
TIA,
regards,
Giovanni
//------------------------------------------------------------------------
public void
testCopyProperties()
throws Exception
{
@SuppressWarnings("unused")
class SomeBean
{
//----------------------------------------------------------------
public final double
getPropertyA()
{
return thePropertyA;
}
//----------------------------------------------------------------
public final void
setPropertyA(double aPropertyA)
{
thePropertyA = aPropertyA;
}
//----------------------------------------------------------------
public final double
getPropertyB()
{
return thePropertyB;
}
//----------------------------------------------------------------
public final void
setPropertyB(double aPropertyB)
{
thePropertyB = aPropertyB;
}
//----------------------------------------------------------------
/** (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String
toString()
{
return "(" + getPropertyA() + ", " + getPropertyB() + ")";
}
//----------------------------------------------------------------
// members
//----------------------------------------------------------------
private double thePropertyA;
private double thePropertyB;
}
Object myBean = new SomeBean();
String myExpected = "(1.0, 1.0)";
Map<String, Object> myMap = new HashMap<String, Object>();
myMap.put("propertyA", 1.0);
myMap.put("propertyB", 1.0);
BeanUtilsBean.getInstance().copyProperties(myBean, myMap);
assertEquals("copyProperties method did not work as expected.",
myExpected, myBean.toString());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: question on copyProperties usage
Posted by Giovanni Azua <gi...@imc.nl>.
Many thanks Niall.
Making the Bean public solves the problem, but shouldn't it work that
way too?
regards,
Giovanni
Niall Pemberton wrote:
> Try making SomeBean a public class
>
> Niall
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: question on copyProperties usage
Posted by Niall Pemberton <ni...@gmail.com>.
On Fri, Feb 29, 2008 at 9:19 AM, Giovanni Azua <gi...@imc.nl> wrote:
> hi all,
>
> I have not been able to have the following test case pass under 1.7 and 1.8.
>
> Here the list of trial-errors:
> - Assigning to myMap property names starting upper case does not provide
> any error as I would expect it should i.e. IllegalArgumentException
> "Malformed property names provided in Map"
>
> - Assigning proper property names i.e. "propertyA" I consistently get
> InvokationTargetException
Try making SomeBean a public class
Niall
> TIA,
> regards,
> Giovanni
>
> //------------------------------------------------------------------------
> public void
> testCopyProperties()
> throws Exception
> {
> @SuppressWarnings("unused")
> class SomeBean
> {
> //----------------------------------------------------------------
> public final double
> getPropertyA()
> {
> return thePropertyA;
> }
>
> //----------------------------------------------------------------
> public final void
> setPropertyA(double aPropertyA)
> {
> thePropertyA = aPropertyA;
> }
>
> //----------------------------------------------------------------
> public final double
> getPropertyB()
> {
> return thePropertyB;
> }
>
> //----------------------------------------------------------------
> public final void
> setPropertyB(double aPropertyB)
> {
> thePropertyB = aPropertyB;
> }
>
> //----------------------------------------------------------------
> /** (non-Javadoc)
> * @see java.lang.Object#toString()
> */
> @Override
> public String
> toString()
> {
> return "(" + getPropertyA() + ", " + getPropertyB() + ")";
> }
>
> //----------------------------------------------------------------
> // members
> //----------------------------------------------------------------
> private double thePropertyA;
> private double thePropertyB;
> }
>
> Object myBean = new SomeBean();
>
> String myExpected = "(1.0, 1.0)";
>
> Map<String, Object> myMap = new HashMap<String, Object>();
> myMap.put("propertyA", 1.0);
> myMap.put("propertyB", 1.0);
>
> BeanUtilsBean.getInstance().copyProperties(myBean, myMap);
>
> assertEquals("copyProperties method did not work as expected.",
> myExpected, myBean.toString());
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org