Ignore all methods except for one call

View: New views
9 Messages — Rating Filter:   Alert me  

Ignore all methods except for one call

by Guillaume Jeudy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

Re: Ignore all methods except for one call

by Greg Akins-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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)


RE: Ignore all methods except for one call

by Guillaume Jeudy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 (9K) Download Attachment

RE: Ignore all methods except for one call

by Guillaume Jeudy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Ignore all methods except for one call

by Steve Freeman-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes. We used to have more complex search options but it was too  
confusing, so now it's first-to-last.

We should write this up more clearly...

S.

On 13 Apr 2009, at 17:01, Jeudy, Guillaume wrote:

> 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
> }
> });

Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006

http://www.m3p.co.uk

M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England & Wales. Number 03689627



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

    http://xircles.codehaus.org/manage_email



Re: Ignore all methods except for one call

by Nat Pryce :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/4/13 Steve Freeman <steve@...>:
> Yes. We used to have more complex search options but it was too confusing,
> so now it's first-to-last.
>
> We should write this up more clearly...

It's documented here: http://www.jmock.org/dispatch.html

>> 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.

Yes, but it will also get there if hasADeploymentInProcess() is called
more than once which does not appear to be what you want.

It seems odd, to me, that you are expecting a *query* once, and
ignoring commands.  Why is it important that the object under test
only calls hasADeploymentInProgress once?  Why not just allow that to
return true and ignore everything else (in which case, putting the
ignoring(mockReleasePackage); call last *will* do what you want).

--Nat

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

    http://xircles.codehaus.org/manage_email



RE: Ignore all methods except for one call

by Guillaume Jeudy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Steve and Nat,
 
allowing() passes even if the method is not called which is not what I want. But you are right the test should still pass if hasADeploymentInProgress() is called more than once. Therefore using atLeast(1).of(mockReleasePackage) should fulfill my needs.
 
-Guillaume

________________________________

From: Nat Pryce [mailto:nat.pryce@...]
Sent: Mon 4/13/2009 12:01 PM
To: user@...
Subject: Re: [jmock-user] Ignore all methods except for one call



2009/4/13 Steve Freeman <steve@...>:
> Yes. We used to have more complex search options but it was too confusing,
> so now it's first-to-last.
>
> We should write this up more clearly...

It's documented here: http://www.jmock.org/dispatch.html

>> 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.

Yes, but it will also get there if hasADeploymentInProcess() is called
more than once which does not appear to be what you want.

It seems odd, to me, that you are expecting a *query* once, and
ignoring commands.  Why is it important that the object under test
only calls hasADeploymentInProgress once?  Why not just allow that to
return true and ignore everything else (in which case, putting the
ignoring(mockReleasePackage); call last *will* do what you want).

--Nat

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

    http://xircles.codehaus.org/manage_email







____________________________________________________________________________________________________
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 (6K) Download Attachment

Re: Ignore all methods except for one call

by Nat Pryce :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/4/13 Jeudy, Guillaume <gjeudy@...>:
> allowing() passes even if the method is not called which is not what I want.

The smell is that you are expecting a query.  Why is it important that
it is called at all.  The fact that the object acts on the result the
query returned should be enough.  I would expect the  test to check
that the object causes some effects when the query returns true (or
false, or whatever), not check that it performs a query and ignore the
effects.  As someone reading the test, it appears very odd.

--Nat

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

    http://xircles.codehaus.org/manage_email



RE: Ignore all methods except for one call

by Guillaume Jeudy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey Nat,
 
I understand what you mean, in fact I expect an exception being thrown by the object under test based on the query results. Based on this using: allowing(mockReleasePackage).hasADeploymentInProgress();  will(return(true)); is effectively only used as a stub to control indirect input. I see how it can be misleading to someone reading the test, where atLeast(1).of() would be overspecification and only create noise in the test. If a change was made to the object under test so that it no longer called the stubbed method the test would fail anyways because the expected exception would no longer be thrown...
 
Thanks,
Guillaume

________________________________

From: Nat Pryce [mailto:nat.pryce@...]
Sent: Mon 4/13/2009 2:18 PM
To: user@...
Subject: Re: [jmock-user] Ignore all methods except for one call



2009/4/13 Jeudy, Guillaume <gjeudy@...>:
> allowing() passes even if the method is not called which is not what I want.

The smell is that you are expecting a query.  Why is it important that
it is called at all.  The fact that the object acts on the result the
query returned should be enough.  I would expect the  test to check
that the object causes some effects when the query returns true (or
false, or whatever), not check that it performs a query and ignore the
effects.  As someone reading the test, it appears very odd.

--Nat

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

    http://xircles.codehaus.org/manage_email







____________________________________________________________________________________________________
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 (6K) Download Attachment