You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2010/02/10 23:10:46 UTC

svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Author: doogie
Date: Wed Feb 10 22:10:44 2010
New Revision: 908676

URL: http://svn.apache.org/viewvc?rev=908676&view=rev
Log:
Full code coverage on the unit tests.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java?rev=908676&r1=908675&r2=908676&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java Wed Feb 10 22:10:44 2010
@@ -47,7 +47,7 @@
         assertTrue(Debug.verboseOn());
 
         Debug.set(Debug.VERBOSE, false);
-        assertTrue(!Debug.verboseOn());
+        assertFalse(Debug.verboseOn());
 
         Debug.set(Debug.INFO, true);
         assertTrue(Debug.infoOn());
@@ -102,11 +102,15 @@
         assertTrue("overlaps range", range1.overlaps(overlapTest));
         assertTrue("overlaps range", range2.overlaps(overlapTest));
         assertFalse("does not overlap range", range1.overlaps(range2));
+        IllegalArgumentException caught = null;
         try {
             @SuppressWarnings("unused")
             ComparableRange<java.util.Date> range3 = new ComparableRange<java.util.Date>(new java.util.Date(), new java.sql.Timestamp(System.currentTimeMillis()));
-            fail("mismatched classes");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            caught = e;
+        } finally {
+            assertNotNull("expected exception", caught);
+        }
     }
 
     public void testFlexibleStringExpander() {
@@ -155,60 +159,46 @@
         assertTrue("UEL auto-vivify List " + fse.expandString(testMap), compare.equals(fse.expandString(testMap)));
     }
 
-    public void testDateTimeConverters() {
+    public void testDateTimeConverters() throws Exception {
         // Source class = java.util.Date
         java.util.Date utilDate = new java.util.Date();
         long dateMillis = utilDate.getTime();
         Converter<java.util.Date, Long> dateToLong = new DateTimeConverters.DateToLong();
-        try {
+        {
             Long target = dateToLong.convert(utilDate);
             assertEquals("DateToLong", dateMillis, target.longValue());
-        } catch (ConversionException e) {
-            fail(e.getMessage());
         }
         Converter<java.util.Date, java.sql.Date> dateToSqlDate = new DateTimeConverters.DateToSqlDate();
-        try {
+        {
             java.sql.Date target = dateToSqlDate.convert(utilDate);
             assertEquals("DateToSqlDate", dateMillis, target.getTime());
-        } catch (ConversionException e) {
-            fail(e.getMessage());
         }
         Converter<java.util.Date, String> dateToString = new DateTimeConverters.DateToString();
-        try {
+        {
             String target = dateToString.convert(utilDate);
             assertEquals("DateToString", utilDate.toString(), target);
-        } catch (ConversionException e) {
-            fail(e.getMessage());
         }
         Converter<java.util.Date, java.sql.Timestamp> dateToTimestamp = new DateTimeConverters.DateToTimestamp();
-        try {
+        {
             java.sql.Timestamp timestamp = dateToTimestamp.convert(utilDate);
             assertEquals("DateToTimestamp", dateMillis, timestamp.getTime());
-        } catch (ConversionException e) {
-            fail(e.getMessage());
         }
         // Source class = java.sql.Date
         java.sql.Date sqlDate = new java.sql.Date(System.currentTimeMillis());
         Converter<java.sql.Date, java.util.Date> sqlDateToDate = new DateTimeConverters.SqlDateToDate();
-        try {
+        {
             java.util.Date target = sqlDateToDate.convert(sqlDate);
             assertEquals("SqlDateToDate", sqlDate.getTime(), target.getTime());
-        } catch (ConversionException e) {
-            fail(e.getMessage());
         }
         Converter<java.sql.Date, String> sqlDateToString = new DateTimeConverters.SqlDateToString();
-        try {
+        {
             String target = sqlDateToString.convert(sqlDate);
             assertEquals("SqlDateToString", sqlDate.toString(), target);
-        } catch (ConversionException e) {
-            fail(e.getMessage());
         }
         Converter<java.sql.Date, java.sql.Timestamp> sqlDateToTimestamp = new DateTimeConverters.SqlDateToTimestamp();
-        try {
+        {
             java.sql.Timestamp target = sqlDateToTimestamp.convert(sqlDate);
             assertEquals("SqlDateToTimestamp", sqlDate.getTime(), target.getTime());
-        } catch (ConversionException e) {
-            fail(e.getMessage());
         }
     }
 



Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Posted by Adam Heath <do...@brainfood.com>.
Matthieu Bollot wrote:
> Hi dev,
> I've got some problems since yesterday, may be it is related to this
> error :
> org.ofbiz.widget.screen.ScreenRenderException: Error rendering screen
> [component://common/widget/CommonScreens.xml#FindScreenDecorator]:
> java.lang.UnsupportedOperationException (null)
> 
> that you can find here :
> https://ofbiz-vm.apache.org/sfa/control/FindLeads

Fixed in 909718.

Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Posted by Adrian Crum <ad...@yahoo.com>.
--- On Fri, 2/12/10, Adam Heath <do...@brainfood.com> wrote:
> From: Adam Heath <do...@brainfood.com>
> Subject: Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java
> To: dev@ofbiz.apache.org
> Date: Friday, February 12, 2010, 10:16 AM
> Adam Heath wrote:
> > Adrian Crum wrote:
> >> Actually, that error message was caused by rev
> 908700.
> > 
> > How?  That added an Enum converter; I didn't
> think ofbiz actually used
> > enums mutch.
> 
> Ok, I see it; Is this code trying to convert a String to an
> Enum?
> That's not supported.  To make that work, you also
> need to pass in a
> the target class.  Perhaps we should remove the single
> arg variant of
> convert.

Most likely the calling code defaulted to some other conversion.



      

Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Posted by Adam Heath <do...@brainfood.com>.
Adrian Crum wrote:
> --- On Fri, 2/12/10, Adam Heath <do...@brainfood.com> wrote:
>> It's also why I throw UnsupportedOperationException,
>> instead of
>> ConversionException, during convert(obj).  You
>> shouldn't do doing
>> unknown conversions, when dealing with enums.  In
>> those cases, you
>> should know that an enum is being requested, and use the
>> other convert
>> method.
> 
> But the client code is checking for ConversionException, and typically takes an alternate path when one is thrown. Throwing UnsupportedOperationException breaks that pattern.

ConversionException means that there was a problem converting.
Calling convert(Object) on StringToEnum is not a valid call to make,
it's a more serious issue.  It's not that a conversion failed, it's
that a conversion is not even allowed to take place.  You *must* use
the convert(Class, Object) variant.

StringToEnum can handle all enums, but can only create concrete
sub-classes.  It's not like List or Map, which allows any
implementation to be used.


Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Posted by Adrian Crum <ad...@yahoo.com>.
--- On Fri, 2/12/10, Adam Heath <do...@brainfood.com> wrote:
> It's also why I throw UnsupportedOperationException,
> instead of
> ConversionException, during convert(obj).  You
> shouldn't do doing
> unknown conversions, when dealing with enums.  In
> those cases, you
> should know that an enum is being requested, and use the
> other convert
> method.

But the client code is checking for ConversionException, and typically takes an alternate path when one is thrown. Throwing UnsupportedOperationException breaks that pattern.



      

Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Posted by Adam Heath <do...@brainfood.com>.
Adrian Crum wrote:
> --- On Fri, 2/12/10, Adam Heath <do...@brainfood.com> wrote:
>> From: Adam Heath <do...@brainfood.com>
>> Subject: Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java
>> To: dev@ofbiz.apache.org
>> Date: Friday, February 12, 2010, 10:16 AM
>> Adam Heath wrote:
>>> Adrian Crum wrote:
>>>> Actually, that error message was caused by rev
>> 908700.
>>> How?  That added an Enum converter; I didn't
>> think ofbiz actually used
>>> enums mutch.
>> Ok, I see it; Is this code trying to convert a String to an
>> Enum?
>> That's not supported.  To make that work, you also
>> need to pass in a
>> the target class.  Perhaps we should remove the single
>> arg variant of
>> convert.
> 
> Why would we want to do that? Also, why not extend
> AbstractConverter like the other classes? The exception
> goes away if the converter is written like the rest. Also,
> StringToEnum.convert(String obj) should throw ConversionException.

I choose not to extend AbstractConverter, because StringToEnum
requires a concrete class, it can't just pick any random class that
happens to extend Enum.  That's why I added convert(targetClass, obj)
variants.

It's also why I throw UnsupportedOperationException, instead of
ConversionException, during convert(obj).  You shouldn't do doing
unknown conversions, when dealing with enums.  In those cases, you
should know that an enum is being requested, and use the other convert
method.

While tracking this one down, I discovered that the url in question
was eventually calling into ObjectType, and the conversion framework,
and was trying to do a String->Object conversion; that would never
work, and is stupid to do.  The bug that I fixed in 909718 made the
StringToEnum converter think it could handle that request.

Also, this commit allows me to possibly remove the
checkExtendsImplements method.


> 
> 
> 
> 
>       


Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Posted by Adrian Crum <ad...@yahoo.com>.
--- On Fri, 2/12/10, Adam Heath <do...@brainfood.com> wrote:
> From: Adam Heath <do...@brainfood.com>
> Subject: Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java
> To: dev@ofbiz.apache.org
> Date: Friday, February 12, 2010, 10:16 AM
> Adam Heath wrote:
> > Adrian Crum wrote:
> >> Actually, that error message was caused by rev
> 908700.
> > 
> > How?  That added an Enum converter; I didn't
> think ofbiz actually used
> > enums mutch.
> 
> Ok, I see it; Is this code trying to convert a String to an
> Enum?
> That's not supported.  To make that work, you also
> need to pass in a
> the target class.  Perhaps we should remove the single
> arg variant of
> convert.

Why would we want to do that? Also, why not extend AbstractConverter like the other classes? The exception goes away if the converter is written like the rest. Also, StringToEnum.convert(String obj) should throw ConversionException.




      

Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Posted by Adam Heath <do...@brainfood.com>.
Adam Heath wrote:
> Adrian Crum wrote:
>> Actually, that error message was caused by rev 908700.
> 
> How?  That added an Enum converter; I didn't think ofbiz actually used
> enums mutch.

Ok, I see it; Is this code trying to convert a String to an Enum?
That's not supported.  To make that work, you also need to pass in a
the target class.  Perhaps we should remove the single arg variant of
convert.

Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Posted by Adam Heath <do...@brainfood.com>.
Adrian Crum wrote:
> Actually, that error message was caused by rev 908700.

How?  That added an Enum converter; I didn't think ofbiz actually used
enums mutch.

Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Posted by Adrian Crum <ad...@hlmksw.com>.
Actually, that error message was caused by rev 908700.

-Adrian

Matthieu Bollot wrote:
> Hi dev,
> I've got some problems since yesterday, may be it is related to this
> error :
> org.ofbiz.widget.screen.ScreenRenderException: Error rendering screen
> [component://common/widget/CommonScreens.xml#FindScreenDecorator]:
> java.lang.UnsupportedOperationException (null)
> 
> that you can find here :
> https://ofbiz-vm.apache.org/sfa/control/FindLeads
> 
> 
> in logs I've got :
> 2010-02-12 14:54:45,274 (Finalizer)
> [ EntityListIterator.java:546:ERROR] 
> ---- runtime exception report
> --------------------------------------------------
> Error closing the SQLProcessor in finalize EntityListIterator
> Exception: java.lang.NullPointerException
> Message: null
> ---- stack trace
> ---------------------------------------------------------------
> java.lang.NullPointerException
> --------------------------------------------------------------------------------
> 
> 
> so it may be related to this commit :
> 
> Le mercredi 10 février 2010 à 22:10 +0000, doogie@apache.org a écrit :
>> Author: doogie
>> Date: Wed Feb 10 22:10:44 2010
>> New Revision: 908676
> 
> hope it helps,
> 

Re: svn commit: r908676 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java

Posted by Matthieu Bollot <ma...@nereide.biz>.
Hi dev,
I've got some problems since yesterday, may be it is related to this
error :
org.ofbiz.widget.screen.ScreenRenderException: Error rendering screen
[component://common/widget/CommonScreens.xml#FindScreenDecorator]:
java.lang.UnsupportedOperationException (null)

that you can find here :
https://ofbiz-vm.apache.org/sfa/control/FindLeads


in logs I've got :
2010-02-12 14:54:45,274 (Finalizer)
[ EntityListIterator.java:546:ERROR] 
---- runtime exception report
--------------------------------------------------
Error closing the SQLProcessor in finalize EntityListIterator
Exception: java.lang.NullPointerException
Message: null
---- stack trace
---------------------------------------------------------------
java.lang.NullPointerException
--------------------------------------------------------------------------------


so it may be related to this commit :

Le mercredi 10 février 2010 à 22:10 +0000, doogie@apache.org a écrit :
> Author: doogie
> Date: Wed Feb 10 22:10:44 2010
> New Revision: 908676

hope it helps,

-- 
Matthieu BOLLOT
www.nereide.biz