<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Max Blog</title>
	<atom:link href="http://maxblog.bomzhi.de/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://maxblog.bomzhi.de</link>
	<description>My Blog</description>
	<lastBuildDate>Tue, 17 Aug 2010 11:36:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>From Test to Story, from Methods to Scenarios</title>
		<link>http://maxblog.bomzhi.de/?p=269</link>
		<comments>http://maxblog.bomzhi.de/?p=269#comments</comments>
		<pubDate>Wed, 11 Aug 2010 08:53:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[to Test or not to Test]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=269</guid>
		<description><![CDATA[As we discussed earlier tests shows how the program under test should work. JUnit test can be understood by people having some Java background. But what&#8217;s about people on your team that have no programming background but still are interested in the way the program work or even want to contribute there own expectations. Those [...]]]></description>
			<content:encoded><![CDATA[<p>As we discussed earlier tests shows how the program under test should work.<br />
JUnit test can be understood by people having some Java background. But what&#8217;s about people on your team that have no programming background but still are interested in the way the program work or even want to contribute there own expectations.</p>
<p>Those problems are addressed by <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">Behavior Driven Development (BDD)</a>.<br />
There are dozen of frameworks for BDD and they all trying to make testing more readable. In my opinion BDD Tests also improves structure of the testing itself.</p>
<p>The framework can be divided in two categories. One that use internal DSL and others that use external DSL. (<a href="http://maxblog.bomzhi.de/?p=185">for a few months I wrote a short post on internal DSL in ActionScript</a>)<br />
In my opinion the problem with internal DSL approach is that you can mix the code inside your scenario declaration and this is not a structural improvement.<br />
When you use an external DSL for testing you have to structure your code and the copy&#038;paste amount of source code keeps to the minimum. If you have another scenario that is pretty similar to one you already wrote you just copy the scenario and changes the parameter. You don&#8217;t have to write or duplicate any line of code.</p>
<p>My BDD framework of choice for MockitoViz is <a href="http://jbehave.org/">JBehave</a>. It&#8217;s external DSL based and has a clear structure.</p>
<p>It has three main keywords for Scenario description: Given, When, Then.</p>
<p>If you think about how a test is structured, you see that for a test you have to create a state where the unit under test will be used. It could be the instantiation of the class you would like to test, or creation of the input if it is a complex one.</p>
<p>The creation of the state should be described under the keyword <strong>Given</strong>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p269code4'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2694"><td class="code" id="p269code4"><pre class="text" style="font-family:monospace;">Given a Compilation Unit from this source code:
package foo;
public class A {
  public void bar(){
    A a = mock(A.class)
  }
} 
And a visitor to FindMockedObjects with stubbed BindingHandler
And stubbed BindingHandler witch returns 'A' as type</pre></td></tr></table></div>

<p>The <strong>And</strong> keyword can be used so you don&#8217;t have to write <strong>Given</strong> every time. </p>
<p>After that you want to fire up an action that will give you some output you wan&#8217;t to test. In other word&#8217;s you want to use your program under test.</p>
<p>This should be described under the keyword <strong>When</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p269code5'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2695"><td class="code" id="p269code5"><pre class="text" style="font-family:monospace;">When the visitor have visited the AST</pre></td></tr></table></div>

<p>Now we can write done our expectations leaded with the keyword <strong>Then</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p269code6'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2696"><td class="code" id="p269code6"><pre class="text" style="font-family:monospace;">Then found mocks should not be empty
And 1 mock should be found
And mocks name should be 'a' 
And mocks type should be 'A'</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=269</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mock to visit</title>
		<link>http://maxblog.bomzhi.de/?p=264</link>
		<comments>http://maxblog.bomzhi.de/?p=264#comments</comments>
		<pubDate>Tue, 10 Aug 2010 17:21:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[to Test or not to Test]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=264</guid>
		<description><![CDATA[Let&#8217;s write some actual code that we will use for visualization. To visualize mocked object we should collect the creation of the mocks in the class or method you are interested in. So we need to evaluate the code to find method calls that creates mocks in Mockito framework. The simplest way to evaluate AST [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s write some actual code that we will use for visualization.</p>
<p>To visualize mocked object we should collect the creation of the mocks in the class or method you are interested in.<br />
So we need to evaluate the code to find method calls that creates mocks in Mockito framework.<br />
The simplest way to evaluate AST is to create an ASTVisitor. AST parser will generate the AST from code but it is not the only thing that it normally does. It also binds symbols to declarations. The problem with that is that the AST parser have to be in position to look up all declarations and this is a problem if you just want to provide a snippet of code.</p>
<p>So any way, here is the test class for visitor witch should find creations of mocked objects.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p264code10'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p26410"><td class="code" id="p264code10"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestFindMockedObjects <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Block ast<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> BindingHandler bindingHandler<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>MockedObject<span style="color: #339933;">&gt;</span> foundMocks<span style="color: #339933;">;</span>
&nbsp;
	@Test
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> canFindMock<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> javaCode <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;A a = mock(A.class);&quot;</span><span style="color: #339933;">;</span>
		setup<span style="color: #009900;">&#40;</span>javaCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		when<span style="color: #009900;">&#40;</span>bindingHandler.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span>Matchers.<span style="color: #006633;">any</span><span style="color: #009900;">&#40;</span>Type.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		findMocks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>foundMocks.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, is<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Test
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> canFindMockWithProperName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> javaCode <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;A a = mock(A.class);&quot;</span><span style="color: #339933;">;</span>
		setup<span style="color: #009900;">&#40;</span>javaCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		when<span style="color: #009900;">&#40;</span>bindingHandler.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span>any<span style="color: #009900;">&#40;</span>Type.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		findMocks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>foundMocks.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getObjectName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, is<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>foundMocks.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, is<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Test
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> canFindMockInAssignment<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> javaCode <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;A a; a = mock(A.class);&quot;</span><span style="color: #339933;">;</span>
		setup<span style="color: #009900;">&#40;</span>javaCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		when<span style="color: #009900;">&#40;</span>bindingHandler.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span>Matchers.<span style="color: #006633;">any</span><span style="color: #009900;">&#40;</span>Type.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		findMocks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>foundMocks.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, is<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Test
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> canFindMocksWithProperNamesForDeclarationAndAssignment<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> javaCode <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;A a1 = mock(A.class); B b2; b2 = mock(B.class);&quot;</span><span style="color: #339933;">;</span>
		setup<span style="color: #009900;">&#40;</span>javaCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		when<span style="color: #009900;">&#40;</span>bindingHandler.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span>any<span style="color: #009900;">&#40;</span>Type.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		when<span style="color: #009900;">&#40;</span>bindingHandler.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span>any<span style="color: #009900;">&#40;</span>Expression.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;B&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		findMocks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>foundMocks.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getObjectName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, is<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>foundMocks.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, is<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>foundMocks.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getObjectName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, is<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;b2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>foundMocks.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, is<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;B&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Test
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> canFindMockAlsoIfItIsASpy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> javaCode <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;A a = spy(new A());&quot;</span><span style="color: #339933;">;</span>
		setup<span style="color: #009900;">&#40;</span>javaCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		when<span style="color: #009900;">&#40;</span>bindingHandler.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span>Matchers.<span style="color: #006633;">any</span><span style="color: #009900;">&#40;</span>Type.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		findMocks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>foundMocks.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, is<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> javaCode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		createAst<span style="color: #009900;">&#40;</span>javaCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		prepareBindingHandler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> createAst<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> javaCode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		ASTParser newParser <span style="color: #339933;">=</span> ASTParser.<span style="color: #006633;">newParser</span><span style="color: #009900;">&#40;</span>AST.<span style="color: #006633;">JLS3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		newParser.<span style="color: #006633;">setKind</span><span style="color: #009900;">&#40;</span>ASTParser.<span style="color: #006633;">K_STATEMENTS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		newParser.<span style="color: #006633;">setSource</span><span style="color: #009900;">&#40;</span>javaCode.<span style="color: #006633;">toCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		ast <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Block<span style="color: #009900;">&#41;</span>newParser.<span style="color: #006633;">createAST</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> NullProgressMonitor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> prepareBindingHandler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		bindingHandler <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>BindingHandler.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> findMocks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		FindMockedObjects finder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FindMockedObjects<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		finder.<span style="color: #006633;">setBindingHandler</span><span style="color: #009900;">&#40;</span>bindingHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		ast.<span style="color: #006633;">accept</span><span style="color: #009900;">&#40;</span>finder<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		foundMocks <span style="color: #339933;">=</span> finder.<span style="color: #006633;">getFoundMocks</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I created no @Before method because the state I am testing on is different from test to test. So I am reusing by extracting the logic in private methods and calling them in every test with different parameters. I have to copy and paste code though. This problem will be addressed in next posts.</p>
<p>So any way, the visitor can evaluate the AST, but we also need it to be binded because of Type name of mocked object.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p264code11'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p26411"><td class="code" id="p264code11"><pre class="java" style="font-family:monospace;">	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> visit<span style="color: #009900;">&#40;</span>MethodInvocation node<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>isMockingMethod<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			VariableDeclaration variableDecl <span style="color: #339933;">=</span> getParent<span style="color: #009900;">&#40;</span>node, VariableDeclarationFragment.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>variableDecl <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">String</span> objectName <span style="color: #339933;">=</span> variableDecl.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				VariableDeclarationStatement parent <span style="color: #339933;">=</span> getParent<span style="color: #009900;">&#40;</span>variableDecl, VariableDeclarationStatement.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				Type type <span style="color: #339933;">=</span> parent.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				foundMocks.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MockedObject<span style="color: #009900;">&#40;</span>objectName, bindingHandler.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			Assignment assignment <span style="color: #339933;">=</span> getParent<span style="color: #009900;">&#40;</span>node, Assignment.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>assignment<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				Expression leftHandSide <span style="color: #339933;">=</span> assignment.<span style="color: #006633;">getLeftHandSide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>leftHandSide <span style="color: #000000; font-weight: bold;">instanceof</span> SimpleName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					SimpleName name <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SimpleName<span style="color: #009900;">&#41;</span>leftHandSide<span style="color: #339933;">;</span>
					foundMocks.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MockedObject<span style="color: #009900;">&#40;</span>name.<span style="color: #006633;">getIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, bindingHandler.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span>leftHandSide<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So I extracted the logic that is depends on AST binding and put it in an extra class that I am mocking out in Test.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p264code12'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p26412"><td class="code" id="p264code12"><pre class="java" style="font-family:monospace;">...
<span style="color: #006633;">bindingHandler</span> <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>BindingHandler.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
<span style="color: #006633;">FindMockedObjects</span> finder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FindMockedObjects<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
finder.<span style="color: #006633;">setBindingHandler</span><span style="color: #009900;">&#40;</span>bindingHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
<span style="color: #006633;">when</span><span style="color: #009900;">&#40;</span>bindingHandler.<span style="color: #006633;">getTypeName</span><span style="color: #009900;">&#40;</span>Matchers.<span style="color: #006633;">any</span><span style="color: #009900;">&#40;</span>Type.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...</pre></td></tr></table></div>

<p>This way I can concentrate myself on the actual AST visiting and check binding resolving.<br />
I another test.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=264</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check parser, understand Matcher</title>
		<link>http://maxblog.bomzhi.de/?p=254</link>
		<comments>http://maxblog.bomzhi.de/?p=254#comments</comments>
		<pubDate>Mon, 09 Aug 2010 17:23:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[to Test or not to Test]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=254</guid>
		<description><![CDATA[Now we want to check what we get from AST parser. For this cause we need more consumers with deeper expectations. As I will test only single behavior, it is better to put it in an setup method of the test class ?View Code JAVA private ASTNode ast; ... @Before public void createAst&#40;&#41; &#123; String [...]]]></description>
			<content:encoded><![CDATA[<p>Now we want to check what we get from AST parser.</p>
<p>For this cause we need more consumers with deeper expectations.</p>
<p>As I will test only single behavior, it is better to put it in an setup method of the test class</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p254code17'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25417"><td class="code" id="p254code17"><pre class="java" style="font-family:monospace;">        <span style="color: #000000; font-weight: bold;">private</span> ASTNode ast<span style="color: #339933;">;</span>
        ...
        @Before
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> createAst<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> javaCode <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;class A {}&quot;</span><span style="color: #339933;">;</span>
		ASTParser newParser <span style="color: #339933;">=</span> ASTParser.<span style="color: #006633;">newParser</span><span style="color: #009900;">&#40;</span>AST.<span style="color: #006633;">JLS3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		newParser.<span style="color: #006633;">setSource</span><span style="color: #009900;">&#40;</span>javaCode.<span style="color: #006633;">toCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		ast <span style="color: #339933;">=</span> newParser.<span style="color: #006633;">createAST</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> NullProgressMonitor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The element that we get from AST parser is a compilation unit.<br />
Compilation unit is a smallest chunk of code than can be compiled to binary.<br />
In Eclipse AST class type hierarchy CompilationUnit is a subtype of ASTNode.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p254code18'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25418"><td class="code" id="p254code18"><pre class="java" style="font-family:monospace;">        @Test
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> ensureThatParsedElementIsAnCompilationUnit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		assertThat<span style="color: #009900;">&#40;</span>ast, is<span style="color: #009900;">&#40;</span>CompilationUnit.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This looks like a simple and readable Expectation.<br />
It also shows us that &#8220;is&#8221; Method can be used with a Class instance.</p>
<p>I already explained that &#8220;assertThat&#8221; uses Matchers to validate assumptions. But how does it work. <a href="http://code.google.com/p/hamcrest/wiki/Tutorial">The Hamcrest Tutorial</a> is a very good place to lookup everything you need.</p>
<p>Any way I would like to introduce another test. It will expect the compilation unit to provide types and one of this types should be our A class.<br />
So hear is the test:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p254code19'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25419"><td class="code" id="p254code19"><pre class="java" style="font-family:monospace;">        @Test
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> ensureThatCompilationUnitHasTypeCalledA<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		CompilationUnit cu <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>CompilationUnit<span style="color: #009900;">&#41;</span>ast<span style="color: #339933;">;</span>
		List<span style="color: #339933;">&lt;</span>AbstractTypeDeclaration<span style="color: #339933;">&gt;</span> allTypes <span style="color: #339933;">=</span> cu.<span style="color: #006633;">types</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>allTypes, is<span style="color: #009900;">&#40;</span>notNullValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>allTypes, hasItem<span style="color: #009900;">&#40;</span>isTypeWithName<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And this test is also pretty self explaining and readable.<br />
Here you can see the real power of Matcher. Matcher can be combined with each other and you can also provide your own matcher as I did with &#8220;isTypeName&#8221;.<br />
So you don&#8217;t have to write code for iterating through collection, just nest two Factory Methods will do the trick.</p>
<p>Here is the code of the Matcher I wrote to evaluate a type declaration.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p254code20'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25420"><td class="code" id="p254code20"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TypeHasName <span style="color: #000000; font-weight: bold;">extends</span> BaseMatcher<span style="color: #339933;">&lt;</span>AbstractTypeDeclaration<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> TypeHasName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> name<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> matches<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		AbstractTypeDeclaration type <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>AbstractTypeDeclaration<span style="color: #009900;">&#41;</span>item<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> type.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> describeTo<span style="color: #009900;">&#40;</span>Description description<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		description.<span style="color: #006633;">appendText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;type with name &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">appendValue</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Factory
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> TypeHasName isTypeWithName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> typeName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> TypeHasName<span style="color: #009900;">&#40;</span>typeName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=254</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git for that</title>
		<link>http://maxblog.bomzhi.de/?p=252</link>
		<comments>http://maxblog.bomzhi.de/?p=252#comments</comments>
		<pubDate>Mon, 09 Aug 2010 12:51:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[to Test or not to Test]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=252</guid>
		<description><![CDATA[By the way I created a Git repository for MockitoViz http://github.com/mzaks/MockitoViz Every post with examples will be tagged in repository.]]></description>
			<content:encoded><![CDATA[<p>By the way I created a Git repository for MockitoViz<br />
<a href="http://github.com/mzaks/MockitoViz">http://github.com/mzaks/MockitoViz</a></p>
<p>Every post with examples will be tagged in repository.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=252</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ready, Steady, Go!</title>
		<link>http://maxblog.bomzhi.de/?p=247</link>
		<comments>http://maxblog.bomzhi.de/?p=247#comments</comments>
		<pubDate>Mon, 09 Aug 2010 08:17:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[to Test or not to Test]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=247</guid>
		<description><![CDATA[What do we need to start a Test driven Eclipse Project. Well, first of all we need Eclipse RCP! Than we create two PlugIn project MockitoViz and MockitoVizTest. (It is better to create create two projects so you don&#8217;t mix productive code with test code) I saw an opening sequence of introduction to TDD from [...]]]></description>
			<content:encoded><![CDATA[<p>What do we need to start a Test driven Eclipse Project.</p>
<p>Well, first of all we need Eclipse RCP!<br />
Than we create two PlugIn project MockitoViz and MockitoVizTest. (It is better to create create two projects so you don&#8217;t mix productive code with test code)</p>
<p>I saw an <a href="http://vimeo.com/10789674">opening sequence of introduction to TDD from Kent Beck on vimeo</a>. (by the way <a href="http://en.wikipedia.org/wiki/Kent_Beck">Kent Beck</a> is the Father of XP, TDD and JUnit) And he introduced some interesting idea to me.</p>
<p>Mostly if I would start with Test first approach, I would start with theoretical classes that I would create and instantiate in my test (Programming by intention style), the test will not be compilable so I will have to create this classes. So in other word you create a consumer for something that does not yet exist and it&#8217;s kind of picky because you directly making assumptions about something.</p>
<p>Kent Beck started to implement the logic directly in the test and then extracted it to a Class under test. So if I would transfer it to my Consumer metaphor: </p>
<p>Do something your self, than delegate it to somebody else and check if he doing it write.</p>
<p>Now back to the real implementation and why I mentioned this stuff.<br />
I created two projects and I know that I would need &#8220;org.eclipse.jdt.core&#8221; plugin for code evaluation. So I start with a test for parsing Java Code. I add two dependencies to my test Plugin:<br />
- already mentioned &#8220;org.eclipse.jdt.core&#8221;<br />
- and <a href="http://junit.org/">JUnit 4</a>.</p>
<p>Now I implement something like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p247code22'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24722"><td class="code" id="p247code22"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.bomzhi.jdt.exploration</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">junit</span>.<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #339933;">*;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">hamcrest</span>.<span style="color: #006633;">CoreMatchers</span>.<span style="color: #339933;">*;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jdt.core.dom.AST</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jdt.core.dom.ASTNode</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jdt.core.dom.ASTParser</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Test</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExploreParser <span style="color: #009900;">&#123;</span>
&nbsp;
	@Test
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> parseSimpleClassDeclaration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> javaCode <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;class A {}&quot;</span><span style="color: #339933;">;</span>
		ASTParser newParser <span style="color: #339933;">=</span> ASTParser.<span style="color: #006633;">newParser</span><span style="color: #009900;">&#40;</span>AST.<span style="color: #006633;">JLS3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		newParser.<span style="color: #006633;">setSource</span><span style="color: #009900;">&#40;</span>javaCode.<span style="color: #006633;">toCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		ASTNode ast <span style="color: #339933;">=</span> newParser.<span style="color: #006633;">createAST</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> NullProgressMonitor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertThat<span style="color: #009900;">&#40;</span>ast, is<span style="color: #009900;">&#40;</span>notNullValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>By implementing this code I see that I need another two plugins:<br />
- &#8220;org.eclipse.core.resources&#8221; because of IProgressMonitor that is used in &#8220;createAST&#8221; method<br />
- and &#8220;org.eclipse.core.runtime&#8221; that is used internally by ASTParser</p>
<p>So here you see a client that converts a string to AST (<a href="http://en.wikipedia.org/wiki/Abstract_syntax_tree">Abstract Syntax Tree</a>) and checks if he was successful. It has no expectations about the AST it becomes. The client is just happy that AST is not null.</p>
<p>By the way I am using the assertThat function for checking the assumption. assertThat was introduced in JUnit 4 and is based on matchers from <a href="http://code.google.com/p/hamcrest/">Hamcrest framework</a>.<br />
Matchers provides pretty cool DSL for assertions. The error messages are also very readable.</p>
<p>Never the less, in this first short cast we created a first test which learns us how to use Eclipse ASTParser.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=247</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Motivation Nr. 2</title>
		<link>http://maxblog.bomzhi.de/?p=243</link>
		<comments>http://maxblog.bomzhi.de/?p=243#comments</comments>
		<pubDate>Mon, 09 Aug 2010 06:46:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[to Test or not to Test]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=243</guid>
		<description><![CDATA[Lately I was experimenting with code evaluation and visualization in Eclipse. So why shouldn&#8217;t I create a code visualization PlugIn for Eclipse while discussing about Testing. And what should I visualize? Well I planned to use Mockito as mocking framework anyway. Wouldn&#8217;t it be great if I would create a plugin that will visualize the [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I was experimenting with code evaluation and visualization in Eclipse.</p>
<p>So why shouldn&#8217;t I create a code visualization PlugIn for Eclipse while discussing about Testing.</p>
<p>And what should I visualize?</p>
<p>Well I planned to use <a href="http://www.mockito.org">Mockito</a> as mocking framework anyway. Wouldn&#8217;t it be great if I would create a plugin that will visualize the mocked objects?</p>
<p>I think it would, so let&#8217;s start&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=243</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Motivation</title>
		<link>http://maxblog.bomzhi.de/?p=237</link>
		<comments>http://maxblog.bomzhi.de/?p=237#comments</comments>
		<pubDate>Fri, 06 Aug 2010 17:25:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[to Test or not to Test]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=237</guid>
		<description><![CDATA[For me to test or not to test is not a question. As a &#8220;lightly&#8221; paranoid person I like to know if my work does what it suppose. And how do I achieve that knowledge? I try it out! I become a customer of my own code. Automatic tests has the same assignment. They use [...]]]></description>
			<content:encoded><![CDATA[<p>For me to test or not to test is not a question. </p>
<p>As a &#8220;lightly&#8221; paranoid person I like to know if my work does what it suppose.<br />
And how do I achieve that knowledge?<br />
I try it out!<br />
I become a customer of my own code.</p>
<p>Automatic tests has the same assignment. They use the code and they complain if this code does something they don&#8217;t expect it to do.</p>
<p>So by providing automatic test you provide your system with users.<br />
And how do you understand a system?<br />
By looking how it is used.</p>
<p>That means that you score two times. You satisfy you paranoia and give people information how they could use your code.</p>
<p>Second task could be achieved by documentation. But documents could lie. Tests become red when they do.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=237</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Summary on AS3 Creative point of view</title>
		<link>http://maxblog.bomzhi.de/?p=234</link>
		<comments>http://maxblog.bomzhi.de/?p=234#comments</comments>
		<pubDate>Sun, 25 Jul 2010 13:33:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>
		<category><![CDATA[IDE]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=234</guid>
		<description><![CDATA[I don&#8217;t think I would write something new to this topic because this year I kind of changed my sphere of action. And to summarize the category I would like to post a link to the talk I gave on Adobe User Group Nederland. It&#8217;s kind of embarrassing for me, because this video doesn&#8217;t put [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t think I would write something new to this topic because this year I kind of changed my sphere of action.</p>
<p>And to summarize the category I would like to post a link to the talk I gave on Adobe User Group Nederland.</p>
<p>It&#8217;s kind of embarrassing for me, because this video doesn&#8217;t put my presentation skills at the glance, but the content is quit interesting in my opinion. It is quit long though, it was a strange slot on this conference I got two hours. Too short for a tutorial and pretty long for a talk. But enough with explanations, here it is:</p>
<p><a href="http://www.adobeusergroup.nl/site/list_messages/391">http://www.adobeusergroup.nl/site/list_messages/391</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=234</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contraversive view on OO and Agile</title>
		<link>http://maxblog.bomzhi.de/?p=227</link>
		<comments>http://maxblog.bomzhi.de/?p=227#comments</comments>
		<pubDate>Mon, 31 May 2010 05:13:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[videos]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=227</guid>
		<description><![CDATA[http://www.infoq.com/interviews/coplien-dci-architecture]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.infoq.com/interviews/coplien-dci-architecture">http://www.infoq.com/interviews/coplien-dci-architecture</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=227</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Education Thoughts</title>
		<link>http://maxblog.bomzhi.de/?p=218</link>
		<comments>http://maxblog.bomzhi.de/?p=218#comments</comments>
		<pubDate>Fri, 28 May 2010 14:49:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[videos]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=218</guid>
		<description><![CDATA[Fast Food Education Math Education Sex Education God Education]]></description>
			<content:encoded><![CDATA[<p>Fast Food Education</p>
<p><!--copy and paste--><object width="446" height="326"><param name="movie" value="http://video.ted.com/assets/player/swf/EmbedPlayer.swf"></param><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"></param><param name="bgColor" value="#ffffff"></param><param name="flashvars" value="vu=http://video.ted.com/talks/dynamic/SirKenRobinson_2010-medium.flv&#038;su=http://images.ted.com/images/ted/tedindex/embed-posters/SirKenRobinson-2010.embed_thumbnail.jpg&#038;vw=432&#038;vh=240&#038;ap=0&#038;ti=865&#038;introDuration=15330&#038;adDuration=4000&#038;postAdDuration=830&#038;adKeys=talk=sir_ken_robinson_bring_on_the_revolution;year=2010;theme=a_taste_of_ted2010;theme=how_we_learn;theme=whipsmart_comedy;theme=the_rise_of_collaboration;theme=the_creative_spark;theme=new_on_ted_com;theme=master_storytellers;theme=how_the_mind_works;event=TED2010;&#038;preAdTag=tconf.ted/embed;tile=1;sz=512x288;" /><embed src="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" pluginspace="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" bgColor="#ffffff" width="446" height="326" allowFullScreen="true" allowScriptAccess="always" flashvars="vu=http://video.ted.com/talks/dynamic/SirKenRobinson_2010-medium.flv&#038;su=http://images.ted.com/images/ted/tedindex/embed-posters/SirKenRobinson-2010.embed_thumbnail.jpg&#038;vw=432&#038;vh=240&#038;ap=0&#038;ti=865&#038;introDuration=15330&#038;adDuration=4000&#038;postAdDuration=830&#038;adKeys=talk=sir_ken_robinson_bring_on_the_revolution;year=2010;theme=a_taste_of_ted2010;theme=how_we_learn;theme=whipsmart_comedy;theme=the_rise_of_collaboration;theme=the_creative_spark;theme=new_on_ted_com;theme=master_storytellers;theme=how_the_mind_works;event=TED2010;"></embed></object></p>
<p>Math Education</p>
<p><!--copy and paste--><object width="446" height="326"><param name="movie" value="http://video.ted.com/assets/player/swf/EmbedPlayer.swf"></param><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"></param><param name="bgColor" value="#ffffff"></param><param name="flashvars" value="vu=http://video.ted.com/talks/dynamic/DanMeyer_2010X-medium.flv&#038;su=http://images.ted.com/images/ted/tedindex/embed-posters/DanMeyer-2010X.embed_thumbnail.jpg&#038;vw=432&#038;vh=240&#038;ap=0&#038;ti=855&#038;introDuration=15330&#038;adDuration=4000&#038;postAdDuration=830&#038;adKeys=talk=dan_meyer_math_curriculum_makeover;year=2010;theme=how_we_learn;theme=unconventional_explanations;theme=new_on_ted_com;theme=media_that_matters;theme=design_like_you_give_a_damn;event=TEDxNYED;&#038;preAdTag=tconf.ted/embed;tile=1;sz=512x288;" /><embed src="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" pluginspace="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" bgColor="#ffffff" width="446" height="326" allowFullScreen="true" allowScriptAccess="always" flashvars="vu=http://video.ted.com/talks/dynamic/DanMeyer_2010X-medium.flv&#038;su=http://images.ted.com/images/ted/tedindex/embed-posters/DanMeyer-2010X.embed_thumbnail.jpg&#038;vw=432&#038;vh=240&#038;ap=0&#038;ti=855&#038;introDuration=15330&#038;adDuration=4000&#038;postAdDuration=830&#038;adKeys=talk=dan_meyer_math_curriculum_makeover;year=2010;theme=how_we_learn;theme=unconventional_explanations;theme=new_on_ted_com;theme=media_that_matters;theme=design_like_you_give_a_damn;event=TEDxNYED;"></embed></object></p>
<p>Sex Education<br />
<!--copy and paste--><object width="446" height="326"><param name="movie" value="http://video.ted.com/assets/player/swf/EmbedPlayer.swf"></param><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"></param><param name="bgColor" value="#ffffff"></param><param name="flashvars" value="vu=http://video.ted.com/talks/dynamic/JuliaSweeney_2010-medium.flv&#038;su=http://images.ted.com/images/ted/tedindex/embed-posters/JuliaSweeney-2010.embed_thumbnail.jpg&#038;vw=432&#038;vh=240&#038;ap=0&#038;ti=856&#038;introDuration=15330&#038;adDuration=4000&#038;postAdDuration=830&#038;adKeys=talk=julia_sweeney_has_the_talk;year=2010;theme=master_storytellers;theme=the_creative_spark;theme=whipsmart_comedy;theme=new_on_ted_com;theme=a_taste_of_ted2010;event=TED2010;&#038;preAdTag=tconf.ted/embed;tile=1;sz=512x288;" /><embed src="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" pluginspace="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" bgColor="#ffffff" width="446" height="326" allowFullScreen="true" allowScriptAccess="always" flashvars="vu=http://video.ted.com/talks/dynamic/JuliaSweeney_2010-medium.flv&#038;su=http://images.ted.com/images/ted/tedindex/embed-posters/JuliaSweeney-2010.embed_thumbnail.jpg&#038;vw=432&#038;vh=240&#038;ap=0&#038;ti=856&#038;introDuration=15330&#038;adDuration=4000&#038;postAdDuration=830&#038;adKeys=talk=julia_sweeney_has_the_talk;year=2010;theme=master_storytellers;theme=the_creative_spark;theme=whipsmart_comedy;theme=new_on_ted_com;theme=a_taste_of_ted2010;event=TED2010;"></embed></object></p>
<p>God Education</p>
<p><!--copy and paste--><object width="334" height="326"><param name="movie" value="http://video.ted.com/assets/player/swf/EmbedPlayer.swf"></param><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"></param><param name="bgColor" value="#ffffff"></param><param name="flashvars" value="vu=http://video.ted.com/talks/dynamic/JuliaSweeney_2006-medium.flv&#038;su=http://images.ted.com/images/ted/tedindex/embed-posters/JuliaSweeney-2006.embed_thumbnail.jpg&#038;vw=320&#038;vh=240&#038;ap=0&#038;ti=86&#038;introDuration=15330&#038;adDuration=4000&#038;postAdDuration=830&#038;adKeys=talk=julia_sweeney_on_letting_go_of_god;year=2006;theme=is_there_a_god;theme=art_unusual;theme=master_storytellers;theme=whipsmart_comedy;theme=spectacular_performance;event=TED2006;&#038;preAdTag=tconf.ted/embed;tile=1;sz=512x288;" /><embed src="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" pluginspace="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" bgColor="#ffffff" width="334" height="326" allowFullScreen="true" allowScriptAccess="always" flashvars="vu=http://video.ted.com/talks/dynamic/JuliaSweeney_2006-medium.flv&#038;su=http://images.ted.com/images/ted/tedindex/embed-posters/JuliaSweeney-2006.embed_thumbnail.jpg&#038;vw=320&#038;vh=240&#038;ap=0&#038;ti=86&#038;introDuration=15330&#038;adDuration=4000&#038;postAdDuration=830&#038;adKeys=talk=julia_sweeney_on_letting_go_of_god;year=2006;theme=is_there_a_god;theme=art_unusual;theme=master_storytellers;theme=whipsmart_comedy;theme=spectacular_performance;event=TED2006;"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=218</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
