Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] Clear Expectation (aka Mockery.reset())

ben grant

2008-01-11

Replies: Find Java Web Hosting

Author LoginPost Reply

Hi

I've made a request for a reset function to be added to the
org.jmock.Mockery.
The idea behind this is to reset the Mockery Object, in particular the
Expectations of Mock Objects.

I see its use as


prop = context.mock(Properties.class,"properties");



context.checking(new Expectations() {{

remove(prop)

atLeast(1).of(prop).getProperty(Properties.KEY_PASSWORD);will(returnValue(

"password"));

atLeast(1).of(prop).getProperty(Properties.KEY_USERNAME);will(returnValue(

"joebloggs"));

}});



//Make some test calls and assertions, etc (1st Test)

.

.

.

.

.



context.assertIsSatisfied();



context.checking(new Expectations() {{

remove(prop); // clears all Expectations for this mocked object - maybe

clear(prop)

one(prop).getProperty(Properties.KEY_PASSWORD);will(returnValue("password"

));

}});






//Make some test calls and assertions, etc (2st Test)

This can indeed be looked at as two test, but the 2nd test depends on the
state of the object being tested. If i split this test, i would be simply
reruning a test again in.

The idea is the TestObject.methodB depends on TestObject.methodA being run
first, to put the object in to a particular state.

The Object it self depends on mocked objects, and you can not determine how
many times methodA is going to use that mockObject, but you do know it
should be used at least once. On the other hand you know that methodB
should use the object at least once.

I think it would be simpler to just reset the context. or even a
context.assertIsSatisfied(true); //true would remove the expectations


Ben

************************************************************
HSBC Bank plc may be solicited in the course of its placement efforts for a
new issue, by investment clients of the firm for whom the Bank as a firm
already provides other services. It may equally decide to allocate to its
own proprietary book or with an associate of HSBC Group. This represents a
potential conflict of interest. HSBC Bank plc has internal arrangements
designed to ensure that the firm would give unbiased and full advice to the
corporate finance client about the valuation and pricing of the offering as
well as internal systems, controls and procedures to identify and manage
conflicts of interest.

HSBC Bank plc
Registered Office: 8 Canada Square, London E14 5HQ, United Kingdom
Registered in England - Number 14259
Authorised and regulated by the Financial Services Authority.
************************************************************


-----------------------------------------
SAVE PAPER - THINK BEFORE YOU PRINT!

This transmission has been issued by a member of the HSBC Group
"HSBC" for the information of the addressee only and should not be
reproduced and/or distributed to any other person. Each page
attached hereto must be read in conjunction with any disclaimer
which forms part of it. Unless otherwise stated, this transmission
is neither an offer nor the solicitation of an offer to sell or
purchase any investment. Its contents are based on information
obtained from sources believed to be reliable but HSBC makes no
representation and accepts no responsibility or liability as to its
completeness or accuracy.

---------------------------------------------------------------------
To unsubscribe from this list please visit:

  http://xircles.codehaus.org/manage_email

©2008 gg3721.com - Jax Systems, LLC, U.S.A.