« Return to Thread: Ignore all methods except for one call

RE: Ignore all methods except for one call

by Guillaume Jeudy :: Rate this Message:

Reply to Author | View in Thread

I found how to do it. The order in which expectations are set is important. If I put ignoring() at the end it will only get there if any previous expectations didnt match.
 
mockContext.checking(new Expectations() {
{
   one(mockReleasePackage).hasADeploymentInProgress(); will(returnValue(true));
   ignoring(mockReleasePackage); // ignore any other method calls
}
});


________________________________

From: Jeudy, Guillaume [mailto:gjeudy@...]
Sent: Mon 4/13/2009 10:57 AM
To: user@...
Subject: RE: [jmock-user] Ignore all methods except for one call


Greg,
 
Thanks for the input. However I don't think it will work in my case. I just want to ignore every method calls except for 1. Using regexp I would need to specify all possible patterns for methods I want to ignore, I don't think that would help. Unless I can negate the logic such as:
 
 ignoring(any(IView.class).method(not(add.*))...

________________________________

From: Greg Akins [mailto:gakins@...]
Sent: Mon 4/13/2009 10:54 AM
To: user@...
Subject: Re: [jmock-user] Ignore all methods except for one call


Jeudy... I had that working last week.  But deleted that code and don't the example anymore.  There is a way to match methods on the mock to a regex.  Sorry I can't remember the exact syntax.


 ignoring(any(IView.class).method(add.*)...


On Apr 13, 2009, at 10:39 AM, Jeudy, Guillaume wrote:


        Hi,
         
        I have been using jmock 2 for a little while now. I would like to know is it possible to ignore all method calls to a particular mock except for certain expectations? For example I have:
         
        mockContext.checking(new Expectations() {
        {
        ignoring(mockReleasePackage).getReleasePackageNm();
        ignoring(mockReleasePackage).getId();
        ignoring(mockReleasePackage).isFrozen();
        ignoring(mockReleasePackage).getLatestDeployment();
        ignoring(deploymentMgtService);
        one(mockReleasePackage).hasADeploymentInProgress(); will(returnValue(true));
        }

        });
       

        That above sample works but I believe will make the test more brittle to changes and seems like it is overspecified. I tried doing something like that: but the ignoring() call seems to take precedence and therefore the test does not give expected results.
       
         

        mockContext.checking(new Expectations() {
        {
        ignoring(mockReleasePackage);
        ignoring(deploymentMgtService);
        one(mockReleasePackage).hasADeploymentInProgress(); will(returnValue(true));
        }

        });
       

        Thanks,
        Guillaume Jeudy



________________________________


        This electronic mail (including any attachments) may contain information that is privileged, confidential, and/or otherwise protected from disclosure to anyone other than its intended recipient(s). Any dissemination or use of this electronic email or its contents (including any attachments) by persons other than the intended recipient(s) is strictly prohibited. If you have received this message in error, please notify us immediately by reply email so that we may correct our internal records. Please then delete the original message (including any attachments) in its entirety. Thank you.


Greg Akins
Director of Software Development
724.935.8281 x 210 (office)
724.935.8283 (fax)
724.454.7790 (cell)
http://www.towercare.com <http://www.towercare.com/>
gakins@...



____________________________________________________________________________________________________
This electronic mail (including any attachments) may contain information that is privileged, confidential, and/or otherwise protected from disclosure to anyone other than its intended recipient(s). Any dissemination or use of this electronic email or its contents (including any attachments) by persons other than the intended recipient(s) is strictly prohibited. If you have received this message in error, please notify us immediately by reply email so that we may correct our internal records. Please then delete the original message (including any attachments) in its entirety. Thank you.


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

    http://xircles.codehaus.org/manage_email

winmail.dat (11K) Download Attachment

 « Return to Thread: Ignore all methods except for one call