#5 MockHttpServletRequest getAttribute prob

Al Briggs

the getAttribute in the MockHttpServletRequest does nto
work as it should - in that I set sometihing with the
setAttribute method and it is not returned by the
getAttribute method. Infact the getAttribute method
seems to ignore the attrobuteName that you pass into it
for some reason. At the moment this makes the framework
next to useless for us as we use these methods a lot.


  • Jeff Martin

    Jeff Martin - 2002-08-16

    Logged In: YES

    getAttribute should not return the value passed into
    setAttribute, but the value passed into setupGetAttribute.

    It should however allow the verification of the attribute name.

    This is now in CVS

  • Jeff Martin

    Jeff Martin - 2002-08-16
    • status: open --> closed-invalid
  • Al Briggs

    Al Briggs - 2002-08-19
    • status: closed-invalid --> open-invalid
  • Al Briggs

    Al Briggs - 2002-08-19

    Logged In: YES

    I do not understand why getAttribute should not return what
    is set with setAttribute - this is what happens with the
    real object. I would only use the setupGetAttribute from a
    test case inside my normal code the behaviour shoudl allow
    me to use this as a normal object surely?

  • Jeff Martin

    Jeff Martin - 2002-09-03

    Logged In: YES

    You have to have the setup methods to set values from test.
    To be able to use both setup and set the resulting list of
    values would need to be merged, this can make tests
    A more pradictable approach is to have to lists one
    containing all the values you think should be set and the
    second containing all the values which are to be got.

    In any case why would you get a value within the same
    servlet which set it? You must alread have that values.

  • Jeff Martin

    Jeff Martin - 2002-09-03
    • status: open-invalid --> closed-invalid
  • John-Mason P. Shackelford

    Logged In: YES

    > getAttribute should not return the value passed into
    > setAttribute,

    I'd like to point out that this approach severly limits the
    usefulness of this object as the addExpected / getAttribute is
    far less flexible than the API itself. Consider the following

    I want to test a method which takes an HttpServlet request
    and then sets some attributes in the request. For the test to
    be considered successful the attributes do not have to be
    equivalent, but merely of a particular type or perhaps one of a
    couple of different options.

    I must agree that the Mock should actually implement (and
    keep the contract) of the interface for it to be flexible enough
    for general use.

  • Steve Freeman

    Steve Freeman - 2003-03-24

    Logged In: YES

    Please clarify for yourself what this library is for. These
    are not stubs. The purpose of the class is to verify that
    you're calling it with the right methods and to maintain
    just enough state to get through a single unit test. There
    are other libraries if you want stubs.


Log in to post a comment.