Results 1 to 3 of 3

Thread: Unit testing with BindException

  1. #1
    Join Date
    Oct 2004
    Posts
    2

    Default Unit testing with BindException

    Hi,

    I'm writing a unittest for a view class that generates a xml structure of the command object. This xml structure also contains possible binding errors.

    Right now I have a unittest that tests for the correct structure of the xml using a mock command object. I'm trying to find out how I can simulate/mock the BindException Object.

    Any clues?

  2. #2
    Join Date
    Oct 2004
    Location
    NYC, USA
    Posts
    13

    Default

    You don't have to mock a BindException like you would a ServletRequest/Response. You can just instantiate one and pass it to the method you're testing. I do that all the time when I have to test.

    If you need to get into it more, and simulate errors, the BindException class has a whole list of methods you can use to add/list/get errors, etc... check out the API: http://www.springframework.org/docs/...Exception.html

    I'd try to be more specific, but I'm not sure what exactly you need to test.

  3. #3
    Join Date
    Oct 2004
    Posts
    2

    Default

    Ill try to explain some more.

    I need to test a method called

    Code:
    view.buildDocument(map,null,null);
    Where buildDocument takes the ModelAndView map as input.

    As everything else is mocked, there is no ServletRequest or anything like it, also no validation has been done.

    You would like to test if the view renders BindingErrors correctly. Therefore I would like to create a BindException myself. I think I'm misunderstanding the constructor of BindException.

    The code that generates the XML for errors I need to test is:

    Code:
    List errors = ex.getFieldErrors(name);
    
    for (Iterator it = errors.iterator(); it.hasNext();) {
    			FieldError error = (FieldError) it.next();
    
    			Element errorElement = new Element("error");
    
    			//add the error message
    			Element errorMessage = new Element("errorMessage");
    			errorMessage.addContent(error.toString());
    			errorElement.addContent(errorMessage);
                         .......
    So I want to fill the FieldErrors of BindException for testing.

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. Replies: 2
    Last Post: Jul 8th, 2005, 10:37 PM
  3. Please help! Unit testing code for JPetStore
    By lakershen in forum Container
    Replies: 4
    Last Post: Jan 13th, 2005, 05:00 PM
  4. Replies: 2
    Last Post: Jan 6th, 2005, 02:49 AM
  5. Problem using hibernate and unit testing
    By rodney.gallart in forum Data
    Replies: 5
    Last Post: Oct 25th, 2004, 12:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •