commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Colebourne <scolebou...@joda.org>
Subject Re: [lang] Validate class with NullPointerException handling
Date Wed, 13 Apr 2011 09:22:30 GMT
These errors look pretty fine as is to me.

The concepts of "empty" and "blank" (from StringUtils) both include
the concept of null, so I would expect to see errors referring to
empty/blank, and not null. The other cases are mostly to taste.

The "MSG" cases are correct too. Any message you supply overrides any
message Validate uses by default.

Stephen


On 12 April 2011 20:21, Hoat Le <hoatlevan@gmail.com> wrote:
>     /**
>      * Expected: java.lang.NullPointerException: The validated object is
> null
>      * Actual:   java.lang.NullPointerException: The validated array is
> empty
>      */
>     Validate.notEmpty((Object[]) null);
>     /**
>      * Expected: java.lang.NullPointerException: The validated object is
> null
>      * Actual:   java.lang.NullPointerException: MSG
>      */
>     Validate.notEmpty((Object[]) null, "MSG");
>     /**
>      * Expected:  java.lang.NullPointerException: The validated object is
> null
>      * Actual:    java.lang.NullPointerException: The validated collection
> is empty
>      */
>     Validate.notEmpty((Collection<?>) null);
>     /**
>      * Expected:  java.lang.NullPointerException: The validated object is
> null
>      * Actual:    java.lang.NullPointerException: MSG
>      */
>     Validate.notEmpty((Collection<?>) null, "MSG");
>     /**
>      * Expected:  java.lang.NullPointerException: The validated object is
> null
>      * Actual:    java.lang.NullPointerException: The validated map is empty
>      */
>     Validate.notEmpty((Map<?, ?>) null);
>     /**
>      * Expected: java.lang.NullPointerException: The validated object is
> null
>      * Actual:   java.lang.NullPointerException: MSG
>      */
>     Validate.notEmpty((Map<?, ?>) null, "MSG");
>     /**
>      * Expected: java.lang.NullPointerException: The validated object is
> null
>      * Actual:   java.lang.NullPointerException: The validated character
> sequence is empty
>      */
>     Validate.notEmpty((CharSequence) null);
>     /**
>      * Expected: java.lang.NullPointerException: The validated object is
> null
>      * Actual:   java.lang.NullPointerException: MSG
>      */
>     Validate.notEmpty((CharSequence) null, "MSG");
>     /**
>      * Expected: java.lang.NullPointerException: The validated object is
> null
>      * Actual:   java.lang.NullPointerException: The validated character
> sequence is blank
>      */
>     Validate.notBlank((CharSequence) null);
>     /**
>      * Expected: java.lang.NullPointerException: The validated object is
> null
>      * Actual:   java.lang.NullPointerException: MSG
>      */
>     Validate.notBlank((CharSequence) null, "MSG");
>     /**
>      * Ok: java.lang.NullPointerException: The validated object is null
>      */
>     Validate.noNullElements((Object[]) null);
>     /**
>      * Ok: java.lang.NullPointerException: The validated object is null
>      */
>     Validate.noNullElements((Object[]) null, "MSG");
>
>     Validate.validIndex(...); //=> ok will null
> If you agree on the expected NullPointerException, please consider my
> attached patch for this issue; there are duplicated code in *Validate*
> class, and some unit test parts for *ValidateTest* are not relevant, too.
> Thanks and best regards!
> --
> Hoat Le [hoatle.net]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message