#5 provide an expectMultiple() type method?

open
nobody
None
5
2004-01-15
2004-01-15
Keith Quint
No

Hi

There are a number of times when we expect a method to
be called and we are not bothered what the arguments are.
In steps the .expect(object,C.ANY_ARGS) however, there are
also a number of occasions where we expect a method to be
called multiple times and we still don’t care what’s passed
nor do we actually know how many times it’s going to be
called. Ie when we mock the apache.commons.logger we
may not care what we log or how often. Is it possible to
create an expectMultiple(object,C.ANY_ARGS) type method?
You could, if you desired, count the number of calls and
verify this.

This is not necessarily a problem in that you could created a
MockLogger() class instead of using the dynamic mock of the
Log interface and just implemented each method with stubs.

Kind regards
Keith

Discussion

  • Steve Freeman
    Steve Freeman
    2004-01-15

    Logged In: YES
    user_id=123464

    Not sure what you're actually testing here: that it's called
    at all? If you're just stubbing, you should use a match()
    method.

    If you can hold your breath, the new jmock implementation
    should support this sort of thing.

    Steve

     
  • Keith Quint
    Keith Quint
    2004-01-15

    Logged In: YES
    user_id=950876

    I'm not sure that there is a simple just 'match' method. When I
    tried this I was only presented with matchAndReturn methods. I
    don't actually want to return anything.

    All I'm trying to do is test a Class that cobtains a number of debug
    lines. Rather than doing anything special I wanted to mock the
    debug logger that I'm using, in this case the
    apache.commons.logger, and just ignore calls to its "trace" method
    etc. Obviously I could just set all the "is....Enabled" requests to
    return false and this would in effect acheive the same thing. I
    assume false is the default in which case I don't need to do
    anything. Interstingly this would also determine if I had any
    unenclosed debug statements.

    The more I think about it the more I realise that I don't need a
    expectMultiple().., However, I'm sure there will be circumstances
    where we do need a method to be called multiple times but where
    we don't care how many?

    ps: when is jmock due?