You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by otisg <ot...@ureach.com> on 2003/02/26 22:51:18 UTC

Q: Running unit tests for Validator used with Struts

Hello,

It is almost impossible to get anyone
attention on struts-user.
I'm using Struts and Validator with it.
I wrote a custom Validator and want to write
a unit test for it.
My Validator has a method like this:

public static boolean validateStartLetter(
    Object bean,
    ValidatorAction validatorAction,
    Field field,
    ActionErrors errors,
    HttpServletRequest request
    )
{
    String value =
ValidatorUtil.getValueAsString(bean,
field.getProperty());
    if
((GenericValidator.isBlankOrNull(value)) ||
!Character.isLetter(value.charAt(0)))
    {
        errors.add(field.getKey(),
Resources.getActionError(request,
validatorAction, field));
    }

    return errors.isEmpty();
}

I am running JUnit from Ant to run my unit
test class.
Apparently this doesn't work because the
instance of ActionErrors passed to this
method is null, causing a NPE.

I wanted to check the unit tests for
Validator in Struts (FieldChecks) to see how
you wrote your unit tests, so that this NPE
is avoided, but I could not find any unit
tests for it.
Are there really no unit tests there?

Regardless, how would you go about running
unit tests for a custom validator from
something like Ant?

It seems to me that doing that may be
impossible, because there is no Struts
running to instantiate ActionErrors, there
is no HttpServletRequest, and so on.

Is there a way to do this?

Thanks,
Otis


________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag

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