Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
ArgumentMatcher.matches() and the use of assertions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chris Bartling  
View profile  
 More options Jan 23, 11:43 am
From: Chris Bartling <chris.bartl...@gmail.com>
Date: Fri, 23 Jan 2009 08:43:52 -0800 (PST)
Local: Fri, Jan 23 2009 11:43 am
Subject: ArgumentMatcher.matches() and the use of assertions
The javadoc description for ArgumentMatcher.matches(java.lang.Object
argument) makes a statement about never using assertions within this
method and favoring returning false instead.

http://mockito.googlecode.com/svn/branches/1.6/javadoc/org/mockito/Ar...)

The documentation does not state why you should not use assertions
within your ArgumentMatcher.matches implementation.  We recently used
assertions in this method and it worked really well, giving us a nice
stack trace to exactly the place in the custom ArgumentMatcher
implementation where the assertion failed.  Is there something that
I'm missing here.  The statement in the ArgumentMatcher seems awfully
strong and perhaps a bit misleading.  It seems like if I return a
false, I've lost the context of what exactly didn't match in the
custom ArgumentMatcher implementation.  I guess the describeTo
(org.hamcrest.Description) gets me customized messages.

Thoughts?

-- chris --


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
szczepiq  
View profile  
 More options Jan 23, 5:26 pm
From: szczepiq <szcze...@gmail.com>
Date: Fri, 23 Jan 2009 23:26:24 +0100
Local: Fri, Jan 23 2009 5:26 pm
Subject: Re: [mockito] ArgumentMatcher.matches() and the use of assertions
Hi,

You're right the docs might be better. ArgumentMatcher is a hamcrest
matcher and it's just a contract of Matchers. You might have a look
here: http://code.google.com/p/hamcrest

I realize completely that the point of failure in matchers is worse
than with plain assertions.

However, there are benefits if you adhere to the contract:

1. you can use your matcher also when stubbing. If your matcher throws
exceptions than you wouldn't be able to use it in stubbing.
2. you can combine your matcher with other matchers. For example if
'validArticle()' returns your matcher you can do the following:
not(validArticle()), hasItems(validArticle()). not() and hasItems()
are just some examples of existing hamcrest matchers.

You can also implement an ArgumentMatcher that just captures the arg.
Then you can get the argument and perform assertions straight in the
test code.

Cheers,
Szczepan Faber

On Fri, Jan 23, 2009 at 5:43 PM, Chris Bartling


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Bartling  
View profile  
 More options Jan 23, 11:10 pm
From: Chris Bartling <chris.bartl...@gmail.com>
Date: Fri, 23 Jan 2009 20:10:39 -0800 (PST)
Local: Fri, Jan 23 2009 11:10 pm
Subject: Re: ArgumentMatcher.matches() and the use of assertions
Szczepan,

Thanks for you thoughts on my topic.  I like your idea of capturing
the indirect output argument using the ArgumentMatcher and performing
the assertions directly in the test code.  I will look into the
hamcrest matchers a bit more.  Thanks again for commenting so quickly
regarding my issue.

Regards,

-- chris --

On Jan 23, 4:26 pm, szczepiq <szcze...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google