<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Mockito in six easy examples</title>
	<atom:link href="http://gojko.net/2009/10/23/mockito-in-six-easy-examples/feed/" rel="self" type="application/rss+xml" />
	<link>http://gojko.net/2009/10/23/mockito-in-six-easy-examples/</link>
	<description>Building software that matters</description>
	<lastBuildDate>Thu, 02 Feb 2012 07:12:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: kiran</title>
		<link>http://gojko.net/2009/10/23/mockito-in-six-easy-examples/comment-page-1/#comment-143119</link>
		<dc:creator>kiran</dc:creator>
		<pubDate>Tue, 19 Jul 2011 12:31:37 +0000</pubDate>
		<guid isPermaLink="false">http://gojko.net/?p=1346#comment-143119</guid>
		<description>i am new to mokito

without implementing the interfaces how can call the methods with interface references

in mockito,


we pass the interface class to &quot;mock()&quot; method
then we call the methods which are present in interface(that methods does not have the body)


explain the above


thanks</description>
		<content:encoded><![CDATA[<p>i am new to mokito</p>
<p>without implementing the interfaces how can call the methods with interface references</p>
<p>in mockito,</p>
<p>we pass the interface class to &#8220;mock()&#8221; method<br />
then we call the methods which are present in interface(that methods does not have the body)</p>
<p>explain the above</p>
<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Setya</title>
		<link>http://gojko.net/2009/10/23/mockito-in-six-easy-examples/comment-page-1/#comment-65960</link>
		<dc:creator>Setya</dc:creator>
		<pubDate>Sat, 14 Nov 2009 16:28:09 +0000</pubDate>
		<guid isPermaLink="false">http://gojko.net/?p=1346#comment-65960</guid>
		<description>Hi,

I have inherited method that calls super followed by my own implementation. I want to test this method by calling my own implementation without super call. Is it possible to do this with Mockito ?

Regards,

Setya</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I have inherited method that calls super followed by my own implementation. I want to test this method by calling my own implementation without super call. Is it possible to do this with Mockito ?</p>
<p>Regards,</p>
<p>Setya</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nico</title>
		<link>http://gojko.net/2009/10/23/mockito-in-six-easy-examples/comment-page-1/#comment-63592</link>
		<dc:creator>nico</dc:creator>
		<pubDate>Sun, 25 Oct 2009 04:33:36 +0000</pubDate>
		<guid isPermaLink="false">http://gojko.net/?p=1346#comment-63592</guid>
		<description>Thanks for the post!

I tried the examples in Netbeans, and the compiler complained when i typed in the last line :

verify(mock).write(argThat(arrayStartingWithA), eq(0),eq(1));

It preferred verify(mock).write((byte[])argThat(arrayStartingWithA), eq(0),eq(1));

have a nice day.</description>
		<content:encoded><![CDATA[<p>Thanks for the post!</p>
<p>I tried the examples in Netbeans, and the compiler complained when i typed in the last line :</p>
<p>verify(mock).write(argThat(arrayStartingWithA), eq(0),eq(1));</p>
<p>It preferred verify(mock).write((byte[])argThat(arrayStartingWithA), eq(0),eq(1));</p>
<p>have a nice day.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Niederwieser</title>
		<link>http://gojko.net/2009/10/23/mockito-in-six-easy-examples/comment-page-1/#comment-63561</link>
		<dc:creator>Peter Niederwieser</dc:creator>
		<pubDate>Sat, 24 Oct 2009 18:19:25 +0000</pubDate>
		<guid isPermaLink="false">http://gojko.net/?p=1346#comment-63561</guid>
		<description>I agree that Mockito is a great Java mocking framework. However, there are frameworks in the Java and .Net world that make mocking even easier, typically by using a more flexible language than Java. One of them is Spock (www.spockframework.org), a Groovy-based testing framework for Java and Groovy apps (disclaimer: I&#039;m the author of Spock). As an exercise, I translated your test code to Spock. I tried to stick as closely to your code as I could, even if that meant writing more code than would be necessary in idiomatic Groovy/Spock. Naturally, more complex tests (like your last example) will see a bigger gain than simple ones. Here is what I came up with:

void &quot;iterator will return hello world&quot;() {
  given:
  Iterator i = Mock()
  i.next() &gt;&gt;&gt; [&quot;Hello&quot;, &quot;World&quot;]

  when:
  String result = i.next() + &quot; &quot; + i.next()

  then:
  result == &quot;Hello World&quot;
}
	
void &quot;with arguments&quot;() {
  Comparable c = Mock()
  c.compareTo(&quot;Test&quot;) &gt;&gt; 1
  expect: c.compareTo(&quot;Test&quot;) == 1
}

void &quot;with unspecified arguments&quot;() {
  Comparable c = Mock()
  c.compareTo(_ as Int) &gt;&gt; -1
  expect: c.compareTo(5) == -1
}

void &quot;OutputStreamWriter rethrows an exception from OutputStream&quot;() {
  OutputStream mock = Mock()
  OutputStreamWriter osw = new OutputStreamWriter(mock)
  mock.close() &gt;&gt; { throw new IOException() } 
  when: osw.close()
  then: thrown(IOException)
}
	
void &quot;OutputStreamWriter closes OutputStream on close&quot;() {
  OutputStream mock = Mock()
  OutputStreamWriter osw = new OutputStreamWriter(mock)
  when: osw.close()
  then: 1 * mock.close()
}

void &quot;OutputStreamWriter buffers and forwards to OutputStream&quot;() {
  OutputStream mock = Mock()
  OutputStreamWriter osw = new OutputStreamWriter(mock)

  when:
  osw.write(&quot;a&quot;)
  osw.flush()

  then:
  1 * mock.write({ it[0] == &quot;a&quot; }, 0, 1)
}</description>
		<content:encoded><![CDATA[<p>I agree that Mockito is a great Java mocking framework. However, there are frameworks in the Java and .Net world that make mocking even easier, typically by using a more flexible language than Java. One of them is Spock (www.spockframework.org), a Groovy-based testing framework for Java and Groovy apps (disclaimer: I&#8217;m the author of Spock). As an exercise, I translated your test code to Spock. I tried to stick as closely to your code as I could, even if that meant writing more code than would be necessary in idiomatic Groovy/Spock. Naturally, more complex tests (like your last example) will see a bigger gain than simple ones. Here is what I came up with:</p>
<p>void &#8220;iterator will return hello world&#8221;() {<br />
  given:<br />
  Iterator i = Mock()<br />
  i.next() &gt;&gt;&gt; ["Hello", "World"]</p>
<p>  when:<br />
  String result = i.next() + &#8221; &#8221; + i.next()</p>
<p>  then:<br />
  result == &#8220;Hello World&#8221;<br />
}</p>
<p>void &#8220;with arguments&#8221;() {<br />
  Comparable c = Mock()<br />
  c.compareTo(&#8220;Test&#8221;) &gt;&gt; 1<br />
  expect: c.compareTo(&#8220;Test&#8221;) == 1<br />
}</p>
<p>void &#8220;with unspecified arguments&#8221;() {<br />
  Comparable c = Mock()<br />
  c.compareTo(_ as Int) &gt;&gt; -1<br />
  expect: c.compareTo(5) == -1<br />
}</p>
<p>void &#8220;OutputStreamWriter rethrows an exception from OutputStream&#8221;() {<br />
  OutputStream mock = Mock()<br />
  OutputStreamWriter osw = new OutputStreamWriter(mock)<br />
  mock.close() &gt;&gt; { throw new IOException() }<br />
  when: osw.close()<br />
  then: thrown(IOException)<br />
}</p>
<p>void &#8220;OutputStreamWriter closes OutputStream on close&#8221;() {<br />
  OutputStream mock = Mock()<br />
  OutputStreamWriter osw = new OutputStreamWriter(mock)<br />
  when: osw.close()<br />
  then: 1 * mock.close()<br />
}</p>
<p>void &#8220;OutputStreamWriter buffers and forwards to OutputStream&#8221;() {<br />
  OutputStream mock = Mock()<br />
  OutputStreamWriter osw = new OutputStreamWriter(mock)</p>
<p>  when:<br />
  osw.write(&#8220;a&#8221;)<br />
  osw.flush()</p>
<p>  then:<br />
  1 * mock.write({ it[0] == &#8220;a&#8221; }, 0, 1)<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mark</title>
		<link>http://gojko.net/2009/10/23/mockito-in-six-easy-examples/comment-page-1/#comment-63537</link>
		<dc:creator>mark</dc:creator>
		<pubDate>Sat, 24 Oct 2009 14:37:41 +0000</pubDate>
		<guid isPermaLink="false">http://gojko.net/?p=1346#comment-63537</guid>
		<description>I&#039;m interested in mockito, but there&#039;s one thing I&#039;ve never seen addressed: Can I pass a mockito object as an argument to an ejb 3 stateless bean?</description>
		<content:encoded><![CDATA[<p>I&#8217;m interested in mockito, but there&#8217;s one thing I&#8217;ve never seen addressed: Can I pass a mockito object as an argument to an ejb 3 stateless bean?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

