<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Manual Mocking: Resisting the Invasion of Dots and Parentheses</title>
    <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Manual Mocking: Resisting the Invasion of Dots and Parentheses</title>
      <description>&lt;p&gt;The twittersphere has been all abuzz today because of something I tweeted early this morning (follow @unclebobmartin).  In my tweet I said that I hand-roll most of my own mock objects in Java, rather than using a mocking framework like &lt;a href="mockito.org"&gt;mockito&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;The replies were numerous and vociferous.  Dave Astels poignantly stated that hand-rolling mocks is so 2001!&lt;/p&gt;


	&lt;p&gt;So why do I roll my own mocks?&lt;/p&gt;


Consider the following two tests:
&lt;pre&gt;
public class SelectorTest {
  private List&amp;lt;Object&amp;gt; list;

  @Before
  public void setup() {
    list = new ArrayList&amp;lt;Object&amp;gt;();
    list.add(new Object());
  }

  @Test
  public void falseMatcherShouldSelectNoElements_mockist() {
    Matcher&amp;lt;Object&amp;gt; falseMatcher = mock(Matcher.class);
    Selector&amp;lt;Object&amp;gt; selector = new Selector&amp;lt;Object&amp;gt;(falseMatcher);
    when(falseMatcher.match(anyObject())).thenReturn(false);
    List&amp;lt;Object&amp;gt; selection = selector.select(list);
    assertThat(selection.size(), equalTo(0));
  }

  @Test
  public void falseMatcherShouldSelectNoElements_classic() {
    Matcher&amp;lt;Object&amp;gt; falseMatcher = new FalseMatcher();
    Selector&amp;lt;Object&amp;gt; selector = new Selector&amp;lt;Object&amp;gt;(falseMatcher);
    List&amp;lt;Object&amp;gt; selection = selector.select(list);
    assertThat(selection.size(), equalTo(0));}

  private static class FalseMatcher implements Matcher&amp;lt;Object&amp;gt; {
    public boolean match(Object element) {
      return false;
    }
  }
}
&lt;/pre&gt;

	&lt;p&gt;The first test shows the really cool power of &lt;a href="mockito.org"&gt;mockito&lt;/a&gt; (which is my current favorite in the menagerie of java mocking frameworks).  Just in case you can&amp;#8217;t parse the syntax, let me describe it for you:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;falseMatcher is assigned the return value of the &amp;#8220;mock&amp;#8221; function.  This is a very cool function that takes the argument class and builds a new stubbed object that derives from it.  In mockito, the argument can be a class or an interface.  Cool!&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;Now don&amp;#8217;t get all panicy about the strange parenthetic syntax of the &amp;#8216;when&amp;#8217; statement.  The &amp;#8216;when&amp;#8217; statement simply tells the mock what to do when a method is called on it.  In this case it instructs the falseMatcher to return false when the &amp;#8216;match&amp;#8217; function is called with any object at all.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;The second test needs no explanation.&lt;/p&gt;


	&lt;p&gt;...&lt;/p&gt;


	&lt;p&gt;And that&amp;#8217;s kind of the point.  Why would I include a bizzare, dot-ridden, parentheses-laden syntax into my tests, when I can just as easily hand-roll the stub in pure and simple java?  How hard was it to hand-roll that stub?  Frankly, it took a lot less time and effort to hand-roll it than it took to write the (when(myobj.mymethod(anyx())).)()).))); statement.&lt;/p&gt;


	&lt;p&gt;OK, I&amp;#8217;m poking a little fun here.  But it&amp;#8217;s true.  My &lt;span class="caps"&gt;IDE&lt;/span&gt; (InteliJ) generated the stub for me.  I simply started with:&lt;/p&gt;


&lt;pre&gt;
Matcher&amp;lt;Object&amp;gt; falseMatcher = new Matcher&amp;lt;Object&amp;gt;() {};
&lt;/pre&gt;

	&lt;p&gt;InteliJ complained that some methods weren&amp;#8217;t implemented and offered to implement them for me.  I told it to go ahead.  It wrote the &amp;#8216;match&amp;#8217; method exactly as you see it.  Then I chose &amp;#8220;Convert Anonymous to Inner&amp;#8230;&amp;#8221; from the refactoring menu and named the new class FalseMatcher.  Voila!  No muss, no fuss, no parenthetic maze of dots.&lt;/p&gt;


Now look, I&amp;#8217;m not saying you shouldn&amp;#8217;t use mockito, or any of these other mocking tools.  I use them myself when I must.  Here, for example, is a test I wrote in FitNesse.  I was forced to use a mocking framework because I did not have the source code of the classes I was mocking.
&lt;pre&gt;
  @Before
  public void setUp() {
    manager = mock(GSSManager.class);
    properties = new Properties();
  }

  @Test
  public void credentialsShouldBeNonNullIfServiceNamePresent() throws Exception {
    properties.setProperty("NegotiateAuthenticator.serviceName", "service");
    properties.setProperty("NegotiateAuthenticator.serviceNameType", "1.1");
    properties.setProperty("NegotiateAuthenticator.mechanism", "1.2");
    GSSName gssName = mock(GSSName.class);
    GSSCredential gssCredential = mock(GSSCredential.class);
    when(manager.createName(anyString(), (Oid) anyObject(), (Oid) anyObject())).thenReturn(gssName);
    when(manager.createCredential((GSSName) anyObject(), anyInt(), (Oid) anyObject(), anyInt())).thenReturn(gssCredential);
    NegotiateAuthenticator authenticator = new NegotiateAuthenticator(manager, properties);
    Oid serviceNameType = authenticator.getServiceNameType();
    Oid mechanism = authenticator.getMechanism();
    verify(manager).createName("service", serviceNameType, mechanism);
    assertEquals("1.1", serviceNameType.toString());
    assertEquals("1.2", mechanism.toString());
    verify(manager).createCredential(gssName, GSSCredential.INDEFINITE_LIFETIME, mechanism, GSSCredential.ACCEPT_ONLY);
    assertEquals(gssCredential, authenticator.getServerCredentials());
  }
&lt;/pre&gt;

	&lt;p&gt;If I&amp;#8217;d had the source code of the &lt;span class="caps"&gt;GSS&lt;/span&gt; classes, I could have created some very simple stubs and spies that would have allowed me to make these tests a &lt;em&gt;lot&lt;/em&gt; cleaner than they currently appear.  Indeed, I might have been able to test the true &lt;em&gt;behavior&lt;/em&gt; of the classes rather than simply testing that I was calling them appropriately&amp;#8230;&lt;/p&gt;


	&lt;h2&gt;&lt;em&gt;Mockism&lt;/em&gt;&lt;/h2&gt;


	&lt;p&gt;That last bit is pretty important.  Some time ago Martin Fowler wrote a &lt;a href="http://martinfowler.com/articles/mocksArentStubs.html#SoShouldIBeAClassicistOrAMockist"&gt;blog&lt;/a&gt; about the &lt;em&gt;Mockist&lt;/em&gt; and &lt;em&gt;Classical&lt;/em&gt; style of &lt;span class="caps"&gt;TDD&lt;/span&gt;.  In short, &lt;em&gt;Mockists&lt;/em&gt; don&amp;#8217;t test the behavior of the system so much as they test that their classes &amp;#8220;dance&amp;#8221; well with other classes.  That is, they mock/stub out all the other classes that the class under test uses, and then make sure that all the right functions are called in all the right orders with all the right arguments. etc.  There is value to doing this in many cases.  However you can get pretty badly carried away with the approach.&lt;/p&gt;


	&lt;p&gt;The classical approach is to test for desired behavior, and trust that if the test passes, then the class being tested must be dancing well with its partners.&lt;/p&gt;


	&lt;p&gt;Personally, I don&amp;#8217;t belong to either camp.  I sometimes test the choreography, and I sometimes test the behavior.  I test the choreography when I am trying to isolate one part of the system from another.  I test for the behavior when such isolation is not important to me.&lt;/p&gt;


	&lt;p&gt;The point of all this is that I have observed that a heavy dependence on mocking frameworks tends to tempt you towards testing the dance when you &lt;em&gt;should&lt;/em&gt; be testing behavior.  Tools can drive the way we think.  So remember, &lt;em&gt;you&lt;/em&gt; dominate the tool; don&amp;#8217;t let the tool dominate you!&lt;/p&gt;


	&lt;h2&gt;But aren&amp;#8217;t hand-rolled mocks fragile?&lt;/h2&gt;


	&lt;p&gt;Yes, they can be.  If you are mocking a class or interface that it very volatile (i.e. you are adding new methods, or modifying method signatures a lot) then you&amp;#8217;ll have to go back and maintain all your hand-rolled mocks every time you make such a change.  On the other hand, if you use a mocking framework, the framework will take care of that for you unless one of the methods you are specifically testing is modified.&lt;/p&gt;


	&lt;p&gt;But here&amp;#8217;s the thing.  Interfaces should not usually be volatile.  They should not continue to grow and grow, and the methods should not change much.  OK, I realize that&amp;#8217;s wishful thinking.  But, &lt;em&gt;yes&lt;/em&gt;, I wish for the kind of a design in which interfaces are the &lt;em&gt;least&lt;/em&gt; volatile source files that you have.  That&amp;#8217;s kind of the point of interfaces after all&amp;#8230;  You create interfaces so that you can separate volatile implementations from non-volatile clients.  (Or at least that&amp;#8217;s one reason.)&lt;/p&gt;


	&lt;p&gt;So if you are tempted to use a mocking framework because you don&amp;#8217;t want to maintain your volatile interfaces, perhaps you should be asking yourself the more pertinent question about why your interfaces are so volatile.&lt;/p&gt;


	&lt;p&gt;Still, if you&amp;#8217;ve got volatile interfaces, and there&amp;#8217;s just no way around it, then a mocking framework may be the right choice for you.&lt;/p&gt;


	&lt;h2&gt;So here&amp;#8217;s the bottom line.&lt;/h2&gt;


	&lt;ul&gt;
	&lt;li&gt;It&amp;#8217;s easy to roll your own stubs and mocks. Your &lt;span class="caps"&gt;IDE&lt;/span&gt; will help you and they&amp;#8217;ll be easier and more natural to read than the dots and parentheses that the mocking frameworks impose upon you.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;Mocking frameworks drive you towards testing choreography rather than behavior.  This can be useful, but it&amp;#8217;s not always appropriate.  And besides, even when you are testing choreography, the hand-rolled stubs and mocks are probably easier to write and read.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;There are special cases where mocking tools are &lt;em&gt;invaluable&lt;/em&gt;, specifically when you have to test choreography with objects that you have no source for or when your design has left you with a plethora of volatile interfaces.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Am I telling you to avoid using mocking frameworks?  No, not at all.  I&amp;#8217;m just telling you that &lt;em&gt;you&lt;/em&gt; should drive tools, tools should not drive you.&lt;/p&gt;


	&lt;p&gt;If you have a situation where a mocking tool is the right choice, by all means use it.   But don&amp;#8217;t use it because you think it&amp;#8217;s &amp;#8220;agile&amp;#8221;, or because you think it&amp;#8217;s &amp;#8220;right&amp;#8221; or because you somehow think you are supposed to.  And remember, hand-rolling often results in simpler tests without the litter of dots and parentheses!&lt;/p&gt;</description>
      <pubDate>Wed, 28 Oct 2009 18:12:16 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:55f13a22-2823-4ae4-bd47-d32a1759e267</guid>
      <author>Uncle Bob</author>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses</link>
      <category>Uncle Bob's Blatherings</category>
      <category>Agile Methods</category>
      <category>Clean Code</category>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by ?????? ????</title>
      <description>&lt;p&gt;thanks about it&lt;/p&gt;</description>
      <pubDate>Sat, 24 Jul 2010 14:47:16 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:adf3938b-2b68-4a30-b9bb-4adc2681caf9</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-17295</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Buzzword</title>
      <description>&lt;p&gt;Summer is very hot, who can wear article 7 minutes of &lt;a href="www.lydress.com" rel="nofollow"&gt;pants&lt;/a&gt;, must the cowboy oh, the best side or a small beads embroidery that paillette, or color, the best is shallow blue, body parts, the condole belt unlined upper &lt;a href="http://www.ququgofashion.com" rel="nofollow"&gt;garments &lt;/a&gt;  grows out of a piece of short sweater, small hollow-out sweater is better, there is colour with cream-colored, white, give priority to, in a few pieces of bright, very pretty, tie-in use: oh!!!!!!!!!!!&lt;/p&gt;</description>
      <pubDate>Tue, 13 Jul 2010 02:56:23 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:8e5c1a75-1814-40de-80b3-a76f04463639</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-16104</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Hoop skirt</title>
      <description>&lt;p&gt;&lt;a href="www.lydress.com" rel="nofollow"&gt;clothing&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 13 Jul 2010 02:55:05 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:73529507-23d9-422b-b4a9-d16491b6e1ab</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-16103</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Kevin Durant jerseys</title>
      <description>&lt;p&gt;I may not shift camps sometime soon but I will give your suggestions a try.&lt;/p&gt;</description>
      <pubDate>Mon, 28 Jun 2010 02:27:39 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:b4f60a31-c291-4126-8c45-d8652ce96499</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-14272</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by yosisi</title>
      <description>&lt;p&gt;&lt;a href="http://www.kefpo.co.il" rel="nofollow"&gt;http://www.kefpo.co.il&lt;/a&gt;
thanks about it&lt;/p&gt;</description>
      <pubDate>Mon, 14 Jun 2010 09:03:27 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:d2701b44-fa04-4f96-8f4f-84b98c9fe779</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-13047</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Daniel</title>
      <description>&lt;p&gt;I belong to the classical camp and am happy that someone who professes to not belong to either camp has presented a very comprehensive look at mockism. I may not shift camps sometime soon but I will give your suggestions a try.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.cookinglightrecipesjournal.com" rel="nofollow"&gt;Fruitarian Diet&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 19 May 2010 12:15:09 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:bfc00850-70d2-4691-b47f-a26b21818fe7</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-11679</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Nex</title>
      <description>&lt;p&gt;I prefer to work on game programming.&lt;/p&gt;</description>
      <pubDate>Tue, 20 Apr 2010 11:17:35 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:868c707c-0b47-472d-ba40-12eab5e6047f</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-10230</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by ShAaNiG</title>
      <description>&lt;p&gt;I think that too often we get carried away by shiny things, and forget that there may be less sexy, but more practical ways of achieving tasks.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.hubofwholesale.com/" rel="nofollow"&gt;Wholesalers&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 12 Apr 2010 05:57:27 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:bd6635e5-04c1-43d9-8f38-3248abed272e</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-9659</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by ShAaNiG</title>
      <description>&lt;p&gt;On the other hand, spies are superior to mocks in every conceivable way as far as I can tell. That might give you additional incentive to hand code, since mock frameworks often aren&#8217;t capable of generating spies.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.dinowholesale.com/" rel="nofollow"&gt;Wholesale Brand Name Clothing&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Sat, 10 Apr 2010 11:09:49 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:c927c70f-5581-4d7b-b35d-79037f6a7e2e</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-9612</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by ShAaNiG</title>
      <description>&lt;p&gt;great info mate. will read it. thanks in advance&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://blog.prudentialwest.com/about/" rel="nofollow"&gt;Prudential West&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 02 Apr 2010 05:41:10 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:488e0cb5-2b74-41db-892e-8670afb1a0aa</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-9151</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by moncler clearance</title>
      <description>&lt;p&gt;Very quietly I take my leave.To seek a dream
in &lt;a href="http://www.edhardy-buy.com/" rel="nofollow"&gt;http://www.edhardy-buy.com/&lt;/a&gt; starlight.&lt;/p&gt;</description>
      <pubDate>Wed, 31 Mar 2010 22:14:33 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:da333d91-6a81-4bd3-b441-4df318bcd5b4</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-8836</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by highkoo ugg boots</title>
      <description>&lt;p&gt;all products are high quality but low price,welcome to &lt;a href="http://www.uggjordanghd.com/.&lt;/p" rel="nofollow"&gt;http://www.uggjordanghd.com/.&lt;/a&gt;&lt;/p&gt;&gt;</description>
      <pubDate>Wed, 31 Mar 2010 22:13:15 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:65cef802-9eab-4d5b-a401-d2c96ff95575</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-8834</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Kooba Handbags   </title>
      <description>&lt;p&gt;Living without an aim is like sailing without a compass.
with a new &lt;a href="http://www.handbags4buy.com/" rel="nofollow"&gt;http://www.handbags4buy.com/&lt;/a&gt; idea is a crank until the idea succeeds.&lt;/p&gt;</description>
      <pubDate>Wed, 31 Mar 2010 22:11:30 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:1c526cac-1323-4e78-a3eb-eb7fbfcc159b</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-8829</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by UGG Classic Metallicaz`</title>
      <description>&lt;p&gt;welcome to &lt;a href="http://www.uggboots4buy.com/" rel="nofollow"&gt;http://www.uggboots4buy.com/&lt;/a&gt; l,will have a unexpection.&lt;/p&gt;</description>
      <pubDate>Wed, 31 Mar 2010 22:08:29 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:739c1e0e-fcc6-48d2-93a5-014b4af4b2b0</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-8821</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Ga,es365</title>
      <description>&lt;p&gt;I prefer to work on game programming.&lt;/p&gt;</description>
      <pubDate>Sun, 07 Mar 2010 06:15:16 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:df6bb277-0134-4827-8405-3d9c851af4ed</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-7727</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by John Erickson, Cousins Subs, </title>
      <description>&lt;p&gt;SHUT YOUR GOD DAMN MOTHER FUCKING PUNK ASS MOUTH JACK YOU FAG FUCK YOU DON&amp;#8217;T KNOW WHAT THE FUCK YOU ARE YAPPING ABOUT.&lt;/p&gt;</description>
      <pubDate>Tue, 29 Dec 2009 20:40:12 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:f30b5fde-3e29-47ae-b909-c5aae23f7674</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-6456</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Jack</title>
      <description>&lt;p&gt;FUCK YOU!&lt;/p&gt;</description>
      <pubDate>Tue, 29 Dec 2009 20:35:15 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:3d1a5e54-bce4-448f-b20c-a8a4637aac96</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-6455</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by dungeon fighter gold</title>
      <description>&lt;p&gt;thank you for sharing.&lt;/p&gt;</description>
      <pubDate>Fri, 25 Dec 2009 02:15:02 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:e4f98311-e28a-471d-96c5-4552dffb94af</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-6286</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by sikis</title>
      <description>&lt;p&gt;bu kodlar ne i?e yar?yor bi anlam veremedim?&lt;/p&gt;</description>
      <pubDate>Wed, 23 Dec 2009 16:01:44 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:821418f2-a0af-4dd2-9c56-d33e52c3d2f3</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-6274</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Chris Morris</title>
      <description>&lt;p&gt;Vindication? &lt;a href="http://clabs.org/blogki/index.cgi?page=" rel="nofollow"&gt;http://clabs.org/blogki/index.cgi?page=&lt;/a&gt;/ComputersAndTechnology/DiyMocks&lt;/p&gt;


	&lt;p&gt;JB didn&amp;#8217;t agree with me either &amp;#8230;&lt;/p&gt;</description>
      <pubDate>Mon, 02 Nov 2009 11:05:56 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:750fc44d-3ee3-4201-b388-d617dbeb023e</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-4995</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by &lt;a href="http://www.questia.com/questialibraryplus"&gt;Questia App&lt;/a&gt;</title>
      <description>&lt;p&gt;It is only the text, Which i can understood, however, programming code has just gone above my brain. Indeed, this would be a great idea to be used in Twitter.&lt;/p&gt;</description>
      <pubDate>Mon, 02 Nov 2009 00:29:19 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:90d71ae1-de3a-4a36-9f82-8f9aa0bf9c6d</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-4984</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Philip Schwarz</title>
      <description>&lt;p&gt;@Uncle Bob&lt;/p&gt;


	&lt;p&gt;In The Art of Unit Testing, Roy Osherove says:&lt;/p&gt;


&lt;blockquote&gt;
&lt;b&gt;In a test where you test only one thing (which is how I recommend you write tests), there should be no more than one mock object. All other fake objects will act as stubs. &lt;/b&gt;Having more than one mock per test usually means you are testing more than one thing, and this can lead to &lt;b&gt;complicated or brittle tests&lt;/b&gt;.
&lt;/blockquote&gt;

	&lt;p&gt;Your test &lt;b&gt; 
credentialsShouldBeNonNullIfServiceNamePresent&lt;/b&gt; conforms to this practice: it has one mock called manager, and two stubs called gssName and gssCredential.&lt;/p&gt;


	&lt;p&gt;Do you think it would enhance readability to have mock names contain &amp;#8216;mock&amp;#8217;, and stub names containing &amp;#8216;stub&amp;#8217;,  like in the Apps flavour of &lt;a href="http://en.wikipedia.org/wiki/Hungarian_notation" rel="nofollow"&gt;Hungarian Notation&lt;/a&gt;?&lt;/p&gt;


	&lt;p&gt;e.g. 1: mockManager,  nameStub and credentialStub
&lt;br&gt;
e.g. 2: mockManager, stubbedName and stubbedCredential.&lt;/p&gt;


	&lt;p&gt;We would then have:&lt;/p&gt;


&lt;pre&gt;
when(mockManager.createName(anyString(), (Oid) anyObject(), (Oid) anyObject())).thenReturn(stubbedGssName);
...
when(mockManager.createCredential((GSSName) anyObject(), anyInt(), (Oid) anyObject(), anyInt())).thenReturn(stubbedGssCredential);
...
NegotiateAuthenticator authenticator = new NegotiateAuthenticator(mockManager, properties);
...
verify(mockManager).createName("service", serviceNameType, mechanism);
...
verify(mockManager).createCredential(stubbedGssName, GSSCredential.INDEFINITE_LIFETIME, mechanism, GSSCredential.ACCEPT_ONLY);
...
assertEquals(stubbedGssCredential, authenticator.getServerCredentials());
&lt;/pre&gt;

	&lt;p&gt;This could also help to quickly check that there is no verification of methods called on stubs.&lt;/p&gt;</description>
      <pubDate>Sun, 01 Nov 2009 08:03:31 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:5f505b2e-2b83-4cb8-a142-1ec47b17bf25</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-4978</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Erik Przekop</title>
      <description>&lt;p&gt;I think the comments point out clearly that this is a &amp;#8220;religious&amp;#8221; argument to some extent.&lt;/p&gt;


	&lt;p&gt;I use EasyMock very often, and I think I need to write more hand-rolled mocks / stubs.  At the very least I need to try it and see how well it works for a given situation.&lt;/p&gt;


	&lt;p&gt;I certainly don&amp;#8217;t agree with the assertion that boils down to &amp;#8220;good programmers should be able to read code using mocks&amp;#8221; (which is what I took away from Reflective Surface&amp;#8217;s post).  That&amp;#8217;s as bad as saying &amp;#8220;it was hard to write, so it should be hard to read.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;If a mediocre programmer can&amp;#8217;t make sense of your code, then it could (and usually should) be written more clearly.&lt;/p&gt;


	&lt;p&gt;I really need to give Mockito a try, though.  I&amp;#8217;m not very keen on doing behavior-based verification unless I absolutely have to.  My (admittedly stone-aged) mind finds it much easier to understand tests that verify state.&lt;/p&gt;</description>
      <pubDate>Sat, 31 Oct 2009 20:10:48 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:39c19add-cee5-4b03-9787-69ee2b52b8a9</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-4975</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Philip Schwarz</title>
      <description>&lt;p&gt;@Franco Lombardo&lt;/p&gt;


	&lt;p&gt;Which assertion better communicates that &lt;b&gt;&amp;#8216;it is true that the selection size is zero&amp;#8217;&lt;/b&gt; ?&lt;/p&gt;


	&lt;p&gt;If we use&lt;/p&gt;


&lt;pre&gt;
assertEquals(0, selection.size()); 
&lt;/pre&gt;

	&lt;p&gt;it reads as &lt;b&gt;&amp;#8216;it is true equals zero selection size&amp;#8217;&lt;/b&gt;. Not too clear. Partly because &amp;#8216;equals&amp;#8217; is used as a prefix operator, as in the LISP-like (= a  b), and partly because the result operand comes before the computation operand, as in the LISP-like (=  result  computation).&lt;/p&gt;


	&lt;p&gt;If we use&lt;/p&gt;


&lt;pre&gt;
assertThat(selection.size(), equalTo(0)); 
&lt;/pre&gt;

	&lt;p&gt;it reads as &lt;b&gt;&amp;#8216;it is true that selection size equal to zero&amp;#8217;&lt;/b&gt;. That is clearer. The equals is now in infix position, as in a = b, and the computation comes before the expected result: computation = result. But we can do better.&lt;/p&gt;


	&lt;p&gt;If we use&lt;/p&gt;


&lt;pre&gt;
assertThat(selection.size(), is(equalTo(0))); 
&lt;/pre&gt;

	&lt;p&gt;it reads as &lt;b&gt;&amp;#8216;it is true that selection size is equal to zero&amp;#8217;&lt;/b&gt;, which is pretty much what we are trying to communicate.&lt;/p&gt;


	&lt;p&gt;Which one do you prefer?&lt;/p&gt;


	&lt;p&gt;As it says in &lt;a href="http://code.google.com/p/hamcrest/wiki/Tutorial" rel="nofollow"&gt;this Hamcrest tutorial&lt;/a&gt;, the &amp;#8216;is()&amp;#8217; matcher is pure syntactic sugar, to make your tests as readable as possible.&lt;/p&gt;</description>
      <pubDate>Sat, 31 Oct 2009 19:34:01 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:17db9624-88a7-4a60-895a-e3d7203eed7e</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-4974</link>
    </item>
    <item>
      <title>"Manual Mocking: Resisting the Invasion of Dots and Parentheses" by Philip Schwarz</title>
      <description>&lt;p&gt;In &lt;a href="http://www.manning.com/osherove/" rel="nofollow"&gt;The Art of Unit Testing&lt;/a&gt;, which according to Michael Feathers (who wrote the Foreword) is &amp;#8216;an important title that should have been written years ago&amp;#8217;, Roy Osherove, the author, says:&lt;/p&gt;


&lt;blockquote&gt;
Although there are many advantages to using isolation frameworks [a set of programmable APIs that make creating mock and stub objects much easier], there are some possible dangers too. Some examples are &lt;b&gt;overusing an isolation framework when a manual mock object would suffice&lt;/b&gt;, making tests unreadable because of overusing mocks in a test, or not separating tests well enough.
&lt;/blockquote&gt;

	&lt;p&gt;He also says:&lt;/p&gt;


&lt;blockquote&gt;
Learn how to use the advanced features of an isolation framework&amp;#8230; and you can pretty much make sure that anything happens or doesn&amp;#8217;t happen in your tests. All you need is for your code to be testable.
&lt;br&gt;
&lt;br&gt;
You can also shoot yourself in the foot by creating overspecified tests that aren&amp;#8217;t readable or will likely break. &lt;b&gt;The art lies in knowing when to use dynamic versus handwritten mocks. My guideline is that, when the code using the isolation framework starts to look ugly, it&amp;#8217;s a sign that you may want to simplify things. Use a handwritten mock&lt;/b&gt;, or change your test to test a different result that proves your point but is easier to test.
&lt;/blockquote&gt;</description>
      <pubDate>Sat, 31 Oct 2009 18:05:19 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:af81142a-3160-446b-9613-38148fd66da1</guid>
      <link>http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses#comment-4973</link>
    </item>
  </channel>
</rss>
