struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject [S1] Trouble writing a unit test
Date Sun, 20 Jan 2013 15:27:37 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

All,

I'm trying to write a unit test to test my fix(es) for but I keep
getting this exception during the test:

java.lang.NullPointerException
	at
org.apache.struts.util.ModuleUtils.getModuleConfig(ModuleUtils.java:93)
	at
org.apache.struts.util.ModuleUtils.getModuleConfig(ModuleUtils.java:135)
	at
org.apache.struts.validator.Resources.getMessageResources(Resources.java:127)
	at
org.apache.struts.validator.Resources.getActionMessage(Resources.java:390)
	at
org.apache.struts.validator.FieldChecks.validateDouble(FieldChecks.java:676)
	at
org.apache.struts.validator.TestFieldChecks.testValidateDouble(TestFieldChecks.java:107)

I know I'm not properly setting-up my environment, but I'm not quite
sure how I should be doing it.


TestFieldChecks is declared:

public class TestFieldChecks
    extends TestMockBase

The setUp method is inherited from the superclass and this is my
entire test method:

    public void testValidateDouble()
        throws Exception
    {
        ValidatorAction va = new ValidatorAction();
        va.setClassname("org.apache.struts.validator.FieldChecks");

va.setMethodParams("java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionMessages,org.apache.commons.validator.Validator,javax.servlet.http.HttpServletRequest");
        va.setMsg("errors.double");
        field.setProperty("field");

        va.setMethod("validateDouble");
        request.setLocale(Locale.US);
        request.setPathElements(null, "/foo", null, null);
        bean.setField("1.5h");

        Double d= (Double)FieldChecks.validateDouble(bean, va, field,
errors, validator, request);
        Assert.assertEquals(new Double(1.5), d);
    }

(The local 'bean' is the thing I'm trying to test: a simple bean with
a single field called "field").

Do I have to manually shove something somewhere so that ModuleUtils is
happy? I'm not sure what to poke where...

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEAREIAAYFAlD8DOgACgkQ9CaO5/Lv0PDvfwCfedjeG8Qe1j/+S5+UUMt5a7W1
zjgAnA4TDjEJ5HQNb09JXW4sIRhN0o+u
=u3E7
-----END PGP SIGNATURE-----

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


Mime
View raw message