<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>Thinking Inside a Bigger Box</title>
	<atom:link href="http://johannesbrodwall.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://johannesbrodwall.com</link>
	<description>Johannes Brodwall&#039;s Musings on Software Architecture and Programming</description>
	<lastBuildDate>Tue, 07 May 2013 06:33:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
		<item>
		<title>A jQuery inspired server side view model for Java</title>
		<link>http://johannesbrodwall.com/2013/05/07/a-jquery-inspired-server-side-view-model-for-java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-jquery-inspired-server-side-view-model-for-java</link>
		<comments>http://johannesbrodwall.com/2013/05/07/a-jquery-inspired-server-side-view-model-for-java/#comments</comments>
		<pubDate>Tue, 07 May 2013 06:33:13 +0000</pubDate>
		<dc:creator>Johannes Brodwall</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://johannesbrodwall.com/?p=1049</guid>
		<description><![CDATA[In HTML applications, jQuery has changed the way people thing about view rendering. Instead of an input or a text field in the view pulling data into it, the jQuery code pushes data into the view. How could this look &#8230; <a href="http://johannesbrodwall.com/2013/05/07/a-jquery-inspired-server-side-view-model-for-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>In HTML applications, jQuery has changed the way people thing about view rendering. Instead of an input or a text field in the view pulling data into it, the jQuery code pushes data into the view. How could this look in a server side situation like Java?</p>
<p>In this code example, I read an HTML template file from the classpath, set the value of an input field and append more data based on a template (also in the HTML file).</p>

<div class="wp_syntax"><table><tr><td class="code"><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> ContactServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet <span style="color: #009900;">&#123;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest req, HttpServletResponse resp<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> nameQuery <span style="color: #339933;">=</span> req.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nameQuery&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Read a pure html template from the classpath</span>
        Xhtml document <span style="color: #339933;">=</span> Xhtml.<span style="color: #006633;">fromResource</span><span style="color: #009900;">&#40;</span>getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;html/contact/index.html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Set the value of the nameQuery input field in the HTML</span>
        document.<span style="color: #006633;">getForm</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#findForm&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nameQuery&quot;</span>, nameQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">Element</span> contactsEl <span style="color: #339933;">=</span> document.<span style="color: #006633;">select</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#contacts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Element</span> contactTmpl <span style="color: #339933;">=</span> contactsEl.<span style="color: #006633;">take</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.contact&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Contact contact <span style="color: #339933;">:</span> findContacts<span style="color: #009900;">&#40;</span>nameQuery<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// Fill in the .contact template of the HTML with data</span>
            <span style="color: #003399;">Element</span> contactHtml <span style="color: #339933;">=</span> contactTmpl.<span style="color: #006633;">copy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#40;</span>contact.<span style="color: #006633;">print</span><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: #666666; font-style: italic;">// And add it to the #contacts element</span>
            contactsEl.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>contactHtml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        document.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>resp.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        resp.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/html&quot;</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>This is a simplified version of the HTML:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
  &lt;form method='get' id=&quot;findForm&quot;&gt;
	&lt;input type='text' name='nameQuery' value='null' /&gt;
    &lt;input type='submit' name='findContact' value=&quot;Find contact&quot; /&gt;
  &lt;/form&gt;
  &lt;ul id='contacts'&gt;
    &lt;li class='contact'&gt;Johannes (4444444)&lt;/li&gt;
  &lt;/ul&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>This is a third way from the alternatives of templated views like Velocity and JSP and from component models like JSF. In this model, the view, the model and the binding of the model variables to the view are all separate.</p>
<p>Disclaimer: In this example, I&#8217;ve used my still in pre-alpha XML library with the working name of <a href="http://github.com/jhannes/eaxy">Eaxy</a>. You can get similiar results with libraries like <a href="">jSoup</a> and <a href="">JOOX</a>.</p>
<p>Caveat: I&#8217;ve never tried this on a grand scale. It&#8217;s an idea that compels me for three reasons: First, it&#8217;s very explicit. Nothing happens through @annotation, conventions or some special syntax in a template. Second, it&#8217;s very unit testable. There is nothing tying this code to running in a web application server. Finally, it&#8217;s easy to get to this code through incremental steps. I initially wrote the example application with code that embedded the HTML as strings in Java code and refactored to use the Java Query approach.</p>
<p>Could this approach be worth trying out more?</p>
]]></content:encoded>
			<wfw:commentRss>http://johannesbrodwall.com/2013/05/07/a-jquery-inspired-server-side-view-model-for-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Scrum as an impediment to Agility</title>
		<link>http://johannesbrodwall.com/2013/04/24/scrum-as-an-impediment-to-agility/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=scrum-as-an-impediment-to-agility</link>
		<comments>http://johannesbrodwall.com/2013/04/24/scrum-as-an-impediment-to-agility/#comments</comments>
		<pubDate>Wed, 24 Apr 2013 08:07:26 +0000</pubDate>
		<dc:creator>Johannes Brodwall</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Extreme Programming]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://johannesbrodwall.com/?p=1054</guid>
		<description><![CDATA[As I&#8217;m working with smaller and more agile projects, I&#8217;m increasingly seeing the classic way that Scrum is executed as more of an impediment to agility than a helper. This is especially the case when it comes to the classic &#8230; <a href="http://johannesbrodwall.com/2013/04/24/scrum-as-an-impediment-to-agility/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>As I&#8217;m working with smaller and more agile projects, I&#8217;m increasingly seeing the classic way that Scrum is executed as more of an impediment to agility than a helper.</p>
<p>This is especially the case when it comes to the classic Sprint Planning as described in <a href="http://www.scrum.org/Portals/0/Documents/Scrum Guides/Scrum_Guide.pdf">the Scrum Guide</a>:</p>
<ul>
<li>&#8220;For example, two-week Sprints have four-hour Sprint Planning Meetings&#8221;</li>
<li>In the Sprint Planning Meeting part 1: &#8220;Development Team works to forecast the functionality that will be developed during the Sprint.&#8221;</li>
<li>In the Sprint Planning Meeting part 1: &#8220;Product Owner presents ordered Product Backlog items&#8221;
  </li>
<li>&#8220;Work planned for the first days of the Sprint by the Development Team is decomposed to units of one day or less by the end of this meeting&#8221;</li>
</ul>
<p>I&#8217;ve seen many sprint planning meetings struggle for the same reasons again and again:</p>
<ul>
<li>The user stories described by the product owner doesn&#8217;t fit the team&#8217;s way of working</li>
<li>The team dives into too many details on each user story to be able to break it down to the level required</li>
<li>The team blames the product owner for not providing enough details to the user stories</li>
<li>Most of the design discussions are considered to be over once the sprint starts</li>
<li>The forecasting/commitment to future velocity becomes a heated negotiation</li>
</ul>
<p>If your project experienced these sorts of Sprint planning meetings, I would expect that the reaction of the project was to add meetings (&#8220;backlog grooming&#8221;), documentation and checkpoint prior to starting a new sprint. These activities would probably resulted in the product owner (team) spending less amount of time with the development team.</p>
<p>Scrum&#8217;s Sprint planning is assuming a situation where the product backlog is detailed for a considerable amount of time and where the ideal is that the product owner spends their time adding more details to the product backlog all the time.</p>
<p>The resulting projects have huge rigid backlogs describing the details for several months into the future. They communication between the users and developers is limited to the acceptance criteria that the product owner writes down before each sprint planning. They spend a considerable amount of the sprint planning the rest of the sprint. Deviations from the sprint backlog are considered problematic.</p>
<p>I think this is misguided. I think this is why we left waterfall in the first place.</p>
<p>In order for Scrum to work better, we have to abandon the idea that the product owner comes to the planning with a perfect set of stories, we have to abandon the sprint backlog detailing the work and design for several weeks and we probably should be very careful with what estimates we ask for.</p>
<p>Instead I would suggest the following approach to planning a sprint:</p>
<ul>
<li>The product owner and the team comes into the room informed by their current understanding of the value the system can deliver</li>
<li>The product owner describes the current most important gaps in the value available to stakeholders</li>
<li>The team already knows their current trajectory and together with the product owner, they can describe &#8220;what&#8217;s the next meaningful thing we could demonstrate to closing these gaps&#8221; as <a href="http://johannesbrodwall.com/2013/02/08/better-scrum-sprint-planning-look-to-the-demo/">a script for the next demonstration</a></li>
<li>The team isn&#8217;t asked to estimate their work, but the product owner, project managers and others are free to make qualified guesses based on the team&#8217;s past performance</li>
<li>Keep it short and frequent!</li>
</ul>
<p>Scrum was developed in the time where it had to match the perception of projects that did huge batches of planning and design. In response, it does smaller batches of planning and design. But &#8220;give a man an inch and he&#8217;ll take a yard&#8221;. The smaller batches leads to frustration over lack of details and the sprints become more and more plan driven and the connection between the users and the developers more and more document-driven.</p>
<p>A new approach is needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://johannesbrodwall.com/2013/04/24/scrum-as-an-impediment-to-agility/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>How to start an agile project</title>
		<link>http://johannesbrodwall.com/2013/04/08/how-to-start-an-agile-project/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-start-an-agile-project</link>
		<comments>http://johannesbrodwall.com/2013/04/08/how-to-start-an-agile-project/#comments</comments>
		<pubDate>Mon, 08 Apr 2013 09:57:29 +0000</pubDate>
		<dc:creator>Johannes Brodwall</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://johannesbrodwall.com/?p=1034</guid>
		<description><![CDATA[During the recent panel debate in Colombo Agile Meetup my colleague Lasantha Bandara asked the following question: How do you start an agile project and ensure room for future enhancements? How can we achieve flexibity at the beginning? This is &#8230; <a href="http://johannesbrodwall.com/2013/04/08/how-to-start-an-agile-project/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>During <a href="http://www.meetup.com/Colombo-Agile-meetup/events/109963882/">the recent panel debate in Colombo Agile Meetup</a> my colleague Lasantha Bandara asked the following question:</p>
<blockquote><p>How do you start an agile project and ensure room for future enhancements? How can we achieve flexibity at the beginning?</p></blockquote>
<p>This is my answer:</p>
<p>Flexibility is about having an acceptable cost of change. Sometimes, the best cost of change is to create something and throw it away early to try something else if it doesn&#8217;t work out.</p>
<p>The first <em>technical</em> decision I make on projects is what I call the deployment model. That is: How will the users access the application and where will the data reside. The most common categories of deployment model include web, disconnected client, rich client with server, and mobile client. There are other less common as well, for example an email responder. A mobile web client could also be considered a category of its own and so may perhaps a rich JavaScript web application.</p>
<p>As Sabri Sawaad said during in the panel: You must make decisions, but consider the cost of changing them.</p>
<p>You have to choose a deployment model and client-server communication protocol before you write any code that you can demo. Often, the project comes with an assumed deployment model, but it&#8217;s not always set in stone. For example, a project where the customer was aiming for a traditional web application, we suggested a JavaScript application due to the skillset of the developers. In another project, we challenged the customer to try a rich client instead of a web application, but after the first sprint, we discarded the code and did the web application instead. In a final example, discussing the requirements further with the client it turned out that a web client was more appropriate than the initial idea of a mobile application, so we had to replace team members to get the correct skillset.</p>
<p>As an architect, it&#8217;s part of your job to help the customer find a deployment model that matches the requirements of the users and the skillset of the team.</p>
<p>On the panel, Subuki Shihabdeen and Buddhima Wickramasinghe both pointed out the importance of early feedback. In my opinion, this implies that the beginning of a project is a bad time to learn new technologies. When you know the deployment model, use the technologies and frameworks you are familiar with to quickly show something to the customer. If this means delaying using a database, as Hasith Yaga suggested in the panel, do this. If it means using Entity Framework and SQL Server, because the team is familiar with this, do that. But as Sabri said: Invest in strategies to minimize the cost of changing these decisions, such as encapsulating the data layer.</p>
<p>In order to quickly choose and roll out a first demo, the only think I&#8217;ve found to work is to practice. I&#8217;ve created applications repeatedly from scratch in many frameworks and languages for practice. Each time I do it faster.</p>
<p>So here is my process, summarized:</p>
<ol>
<li>Spend time to practice technologies so you can choose good options with confidence</li>
<li>Help the customer choose an appropriate deployment model based on the user needs and developer skills (including your own)</li>
<li>Put something in front of the customer quickly by using your existing skills</li>
<li>Invest to reduce the cost of changing decisions on frameworks and technologies</li>
<li>Change course if you find a better technology or even deployment model</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://johannesbrodwall.com/2013/04/08/how-to-start-an-agile-project/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>A canonical Repository test</title>
		<link>http://johannesbrodwall.com/2013/03/08/a-canonical-repository-test/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-canonical-repository-test</link>
		<comments>http://johannesbrodwall.com/2013/03/08/a-canonical-repository-test/#comments</comments>
		<pubDate>Fri, 08 Mar 2013 07:31:58 +0000</pubDate>
		<dc:creator>Johannes Brodwall</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Extreme Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://johannesbrodwall.com/?p=1029</guid>
		<description><![CDATA[There are only so many ways to test that your persistence layer is implemented correctly or that you&#8217;re using an ORM correctly. Here&#8217;s my canonical tests for a repository (Java-version): import static org.fest.assertions.api.Assertions.*; &#160; public class PersonRepositoryTest &#123; private PersonRepository &#8230; <a href="http://johannesbrodwall.com/2013/03/08/a-canonical-repository-test/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>There are only so many ways to test that your persistence layer is implemented correctly or that you&#8217;re using an ORM correctly. Here&#8217;s my canonical tests for a repository (Java-version):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">fest</span>.<span style="color: #006633;">assertions</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">Assertions</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> PersonRepositoryTest <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> PersonRepository repository<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// TODO &lt; == you must initialize this</span>
&nbsp;
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> shouldSaveAllProperties<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Person person <span style="color: #339933;">=</span> randomPerson<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        repository.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>person<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// TODO: Make sure your repository flushes!</span>
        assertThat<span style="color: #009900;">&#40;</span>repository.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span>person.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">isNotSameAs</span><span style="color: #009900;">&#40;</span>person<span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">isEqualTo</span><span style="color: #009900;">&#40;</span>person<span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">isEqualsToByComparingFields</span><span style="color: #009900;">&#40;</span>person<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> shouldFindByCaseInsensitiveSubstringOfName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Person matching <span style="color: #339933;">=</span> randomPerson<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Person nonMatching <span style="color: #339933;">=</span> randomPerson<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        matching.<span style="color: #006633;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A. Matching Person&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        nonMatching.<span style="color: #006633;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A. Random Person&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        repository.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>matching<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        repository.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>nonMatching<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertThat<span style="color: #009900;">&#40;</span>repository.<span style="color: #006633;">findByNameLike</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MATCH&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>matching<span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">doesNotContain</span><span style="color: #009900;">&#40;</span>nonMatching<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>Very simple. The <code>randomPerson</code> test helper generates actually random people:</p>
</pre>

<div class="wp_syntax"><table><tr><td class="code"><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> PersonTest <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// ....</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Person randomPerson<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Person person <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Pesron<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        person.<span style="color: #006633;">setName</span><span style="color: #009900;">&#40;</span>randomName<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: #666666; font-style: italic;">// TODO Initialize all properties</span>
        <span style="color: #000000; font-weight: bold;">return</span> person<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> randomName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> RandomData.<span style="color: #006633;">randomWord</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">+</span> RandomData.<span style="color: #006633;">randomWord</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;son&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RandomData <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> randomString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> random<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo&quot;</span>, <span style="color: #0000ff;">&quot;bar&quot;</span>, <span style="color: #0000ff;">&quot;baz&quot;</span>, <span style="color: #0000ff;">&quot;qux&quot;</span>, <span style="color: #0000ff;">&quot;quux&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// TODO: Add more!</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> T random<span style="color: #009900;">&#40;</span>T... <span style="color: #006633;">options</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> options<span style="color: #009900;">&#91;</span>random<span style="color: #009900;">&#40;</span>options.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> random<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> max<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> random.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span>max<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: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Random</span> random <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If your data has relationships with other entities, you may want to include those as well:</p>

<div class="wp_syntax"><table><tr><td class="code"><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> OrderRepositoryTest <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> OrderRepository repository<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// TODO &lt; == you must initialize this</span>
    <span style="color: #000000; font-weight: bold;">private</span> PersonRepository personRepository<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// TODO &lt;== you must initialize this</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Person person <span style="color: #339933;">=</span> PersonTest.<span style="color: #006633;">randomPerson</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    @Before
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> insertData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        personRepository.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>person<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> shouldSaveAllProperties<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Order order <span style="color: #339933;">=</span> randomOrder<span style="color: #009900;">&#40;</span>person<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        repository.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>order<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// TODO: Make sure your repository flushes!</span>
        assertThat<span style="color: #009900;">&#40;</span>repository.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span>order.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">isNotSameAs</span><span style="color: #009900;">&#40;</span>order<span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">isEqualTo</span><span style="color: #009900;">&#40;</span>order<span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">isEqualsToByComparingFields</span><span style="color: #009900;">&#40;</span>order<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>A simple and easy way to simplify your Repository testing.</p>
<p>(The tests use <a href="https://github.com/alexruiz/fest-assert-2.x">FEST assert 2</a> for the syntax. Look at FluentAssertions for a similar API in .NET)</p>
<p>(Yes, this is what some people would call an integration test. Personally, I can't be bothered with this sort of classifications)</pre>
]]></content:encoded>
			<wfw:commentRss>http://johannesbrodwall.com/2013/03/08/a-canonical-repository-test/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Sweet C# test syntax</title>
		<link>http://johannesbrodwall.com/2013/02/22/sweet-c-test-syntax/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sweet-c-test-syntax</link>
		<comments>http://johannesbrodwall.com/2013/02/22/sweet-c-test-syntax/#comments</comments>
		<pubDate>Fri, 22 Feb 2013 11:23:48 +0000</pubDate>
		<dc:creator>Johannes Brodwall</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://johannesbrodwall.com/?p=1002</guid>
		<description><![CDATA[Two of my favorite libraries in C#: FluentAssertions and NUnit (of course). NUnit has a &#8220;hidden&#8221; gem (that is, it&#8217;s well documented, yet few developers use it): [TestCase]. Look at this: using FluentAssertions; using NUnit.Framework; &#160; public class RomanNumeralsTest &#123; &#8230; <a href="http://johannesbrodwall.com/2013/02/22/sweet-c-test-syntax/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Two of my favorite libraries in C#: <a href="http://fluentassertions.codeplex.com/">FluentAssertions</a> and <a href="http://www.nunit.org/">NUnit</a> (of course). NUnit has a &#8220;hidden&#8221; gem (that is, it&#8217;s well documented, yet few developers use it): [TestCase]. Look at this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">FluentAssertions</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">NUnit.Framework</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> RomanNumeralsTest
<span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#91;</span>TestCase<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">3333</span>, <span style="color: #666666;">&quot;MMMCCCXXXIII&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #008000;">&#91;</span>TestCase<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">555</span>, <span style="color: #666666;">&quot;DLV&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #008000;">&#91;</span>TestCase<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">999</span>, <span style="color: #666666;">&quot;CMXCIX&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #008000;">&#91;</span>TestCase<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">444</span>, <span style="color: #666666;">&quot;CDXLIV&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> ItConvertsNumbersToRomanNumerals<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> number, <span style="color: #6666cc; font-weight: bold;">string</span> roman<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        ToRoman<span style="color: #008000;">&#40;</span>number<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Should</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Be</span><span style="color: #008000;">&#40;</span>roman<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The [TestCase] lets us easily have several test cases implemented by the same method. FluentAssertions adds the Should() extension method to all objects (and primitives, too) that let&#8217;s us write things like <code>ToRoman(3333).Should().Be("MMMCCCXXXIII")</code>.</p>
<p>Add some sugar to your C# tests today. What&#8217;s your favorite ways of writing sweeter tests?</p>
]]></content:encoded>
			<wfw:commentRss>http://johannesbrodwall.com/2013/02/22/sweet-c-test-syntax/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Better Scrum sprint planning &#8211; look to the demo</title>
		<link>http://johannesbrodwall.com/2013/02/08/better-scrum-sprint-planning-look-to-the-demo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=better-scrum-sprint-planning-look-to-the-demo</link>
		<comments>http://johannesbrodwall.com/2013/02/08/better-scrum-sprint-planning-look-to-the-demo/#comments</comments>
		<pubDate>Fri, 08 Feb 2013 09:28:06 +0000</pubDate>
		<dc:creator>Johannes Brodwall</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Extreme Programming]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://johannesbrodwall.com/?p=1003</guid>
		<description><![CDATA[After having worked with Scrum for a number of years, I still witness sprint reviews where the team&#8217;s demonstration of the product is confusing and the value produced in the sprint is unclear. The demo may consist of just a &#8230; <a href="http://johannesbrodwall.com/2013/02/08/better-scrum-sprint-planning-look-to-the-demo/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>After having worked with Scrum for a number of years, I still witness sprint reviews where the team&#8217;s demonstration of the product is confusing and the value produced in the sprint is unclear. The demo may consist of just a bunch of different functions and screens without any meaning. Or maybe the team is just talking about what happens behind the curtains in the database. Or maybe the demo just doesn&#8217;t display the value that the team was supposed to give to the stakeholders. Most teams have okay demos most of the time, but every now and then, it&#8217;s a complete train wreck.</p>
<p>If you&#8217;ve experienced a sprint like this, you probably noticed some problems from the very beginning. The sprint planning may have been chaotic and the work during the sprint may have felt purposeless. Chances are that the team was most of the time discussing technical terms that didn&#8217;t make much sense to the product owner.</p>
<p>If your team learns to be clear about the sprint goal, you can avoid anemic demos, unstructured planning and undirected work. &#8220;But wait&#8221;, you may say, &#8220;we had a sprint goal and our demo still sucked&#8221;. You may think you have a clear sprint goal, but very few teams know what a sprint goal looks like. You may have one, but you might have gotten there by accident.</p>
<p>Here is what a sprint goal looks like: At the end of this period of time, we will demonstrate something to our stakeholders. What we will demonstrate will tell a compelling story that demonstrates real value. We can create the first draft plan of what the demo will look like already at the sprint planning, and we can use this description both to verify our understanding and plan our work.</p>
<p>Let&#8217;s say that the product owner says &#8220;the goal for the next sprint is to verify the payment solution.&#8221; What would a plan for this sprint look like?</p>
<p>At a sprint planning meeting, after the product owner has described the goal, the team plans its work. Then they come back to the product owner to verify that their plan matches the goal. This is what a good plan may sound like: &#8220;We will set up so that all users on the web site has a random set of items in their shopping cart. Then we will go to the checkout page. Here, we will see that the shopping cart is displayed in a reasonable way. When we click the payment button, the user will be redirected to the test site for payment provider. We&#8217;ll input credit card details and pay. The user will be redirected back to the web site and the web site will display the success or the failure of the payment. We&#8217;ll also show the order along with the payment status in a early mockup of the order list page&#8221;</p>
<p>The product owner may agree to this sprint plan. If the team knows their technologies well, it is now easy to break this down into tasks, such as &#8220;create a shopping cart model&#8221;, &#8220;display shopping cart page&#8221;, &#8220;retrieve the payment status from the payment provider&#8221; and &#8220;store the payment status in the database&#8221;.</p>
<p>This demo script will guide the team both during the construction and during the actual sprint review. During the construction a team member is now in a position to solve the sprint goal in the simplest way possible. By focusing on how the team will demonstrate value instead of what technical tasks may or may not be required (e.g. &#8220;construct a new order facade service&#8221; &#8211; whatever that may mean!) we can dramatically cut down on wasteful and convoluted design.</p>
<p>Agile methods emphasize &#8220;adapting to change over following a plan&#8221;. The same holds true for a demo script. The purpose of the script is not to create a perfect plan (which is of limited value), but to get a clear picture of what we need to create and how we will demonstrate that we have indeed delivered real value.</p>
]]></content:encoded>
			<wfw:commentRss>http://johannesbrodwall.com/2013/02/08/better-scrum-sprint-planning-look-to-the-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Let&#8217;s reinvent more wheels!</title>
		<link>http://johannesbrodwall.com/2013/01/31/reinventing-wheels/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=reinventing-wheels</link>
		<comments>http://johannesbrodwall.com/2013/01/31/reinventing-wheels/#comments</comments>
		<pubDate>Thu, 31 Jan 2013 10:21:48 +0000</pubDate>
		<dc:creator>Johannes Brodwall</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[English]]></category>

		<guid isPermaLink="false">http://johannesbrodwall.com/?p=991</guid>
		<description><![CDATA[When I learned math in elementary school, I would reach for my calculator. But my father stopped me: &#8220;You only get to use the calculator when you can do math without it.&#8221; As you can imagine, at the time I &#8230; <a href="http://johannesbrodwall.com/2013/01/31/reinventing-wheels/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>When I learned math in elementary school, I would reach for my calculator. But my father stopped me: &#8220;You only get to use the calculator when you can do math without it.&#8221; As you can imagine, at the time I though this was unfair and unreasonable, but later I have discovered what advantage it is to understand the basics before you reach for a powerful tool.</p>
<p>Many developers are focused on what fancy framework they will learn next. Or what programming language might solve all their problems. Before we reach for the tools, it&#8217;s useful to learn how they really work. My motto is: &#8220;I will not use a framework I would be unable to recreate.&#8221; It is of course, too time consuming to create a framework as complete as many of those available, but I should at least be able to solve all the normal cases myself.</p>
<p>Having recreated the behavior of a framework means that I will understand how the framework is implemented. I get better intuition about how to use the framework, I understand more quickly what the problem might be when something doesn&#8217;t work, and last, but not least: I understand when the framework is harming me more than it&#8217;s helping me.</p>
<p>An example I have enjoyed using is to create a web application in Java without framework. I may use a simple domain like creating an address book where you can register your contacts and search for them. In honor of my C#-friends, I have solved the same task in C#: How to make a web application without MVC, without ASP.NET or even without IIS.</p>
<p>Test-driven development is an essential tool for me to think clearly. I&#8217;ve made an exception from the calculator rule above and used a few testing libraries: <a href="https://github.com/Teun/SimpleBrowser.WebDriver">SimpleBrowser.WebDriver</a>, <a href="http://fluentassertions.codeplex.com/">FluentAssertions</a> and <a href="http://www.nunit.org/">NUnit</a>. This test demonstrates the behavior that I want from the application when I&#8217;m done:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> ShouldFindSavedPerson<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Start a web server INSIDE THE TEST :-D</span>
    <span style="color: #0600FF; font-weight: bold;">var</span> server <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> My<span style="color: #008000;">.</span><span style="color: #0000FF;">Application</span><span style="color: #008000;">.</span><span style="color: #0000FF;">WebServer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    server<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">var</span> browser <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SimpleBrowser<span style="color: #008000;">.</span><span style="color: #0000FF;">WebDriver</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SimpleBrowserDriver</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span> <span style="color: #008000;">=</span> server<span style="color: #008000;">.</span><span style="color: #0000FF;">BaseUrl</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Navigate to the &quot;add contact&quot; page</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElement</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LinkText</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Add contact&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Click</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Add a new contact</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElement</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;fullName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendKeys</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Darth Vader&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElement</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;address&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendKeys</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Death Star&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElement</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;saveContact&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Submit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Navigate to the &quot;find contact&quot; page</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElement</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LinkText</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Find contact&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Click</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Execute some queries:</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElement</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;nameQuery&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendKeys</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;vader&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElement</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;nameQuery&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Submit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElement</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CssSelector</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;#contacts li&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span>
        <span style="color: #008000;">.</span><span style="color: #0000FF;">Should</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Be</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Darth Vader (Death Star)&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElement</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;nameQuery&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendKeys</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;anakin&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElement</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;nameQuery&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Submit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">FindElements</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">By</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CssSelector</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;#contacts li&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
       <span style="color: #008000;">.</span><span style="color: #0000FF;">Should</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BeEmpty</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>I add an empty class for <tt>My.Application.WebServer</tt> and the test will fail at the line <tt>browser.Url = server.BaseUrl</tt> as there is not real server.</p>
<p>To implement the server, I&#8217;m using a cute small class which is part of the .NET core library: <a href="http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx">System.Net.HttpListener</a>. Here are the essentials:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">class</span> WebServer
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Start<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">var</span> listener <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">HttpListener</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        listener<span style="color: #008000;">.</span><span style="color: #0000FF;">Prefixes</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Add</span><span style="color: #008000;">&#40;</span>BaseUrl<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        listener<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">new</span> Thread<span style="color: #008000;">&#40;</span>HttpThread<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span>listener<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> HttpThread<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> listenerObj<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        HttpListener listener <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>HttpListener<span style="color: #008000;">&#41;</span>listenerObj<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> context <span style="color: #008000;">=</span> listener<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>context<span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Running the test again, I get one step further. This time, I am told that the test can&#8217;t find the link to &#8220;Add contact&#8221;. No big surprise, as I&#8217;m not serving any HTML! A small change in the <tt>WebServer</tt> code will fix this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">var</span> context <span style="color: #008000;">=</span> listener<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>context<span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008000;">new</span> AddressBookController<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Service</span><span style="color: #008000;">&#40;</span>context<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Then we just have to create a simple implementation for <tt>AddressBookController.Service</tt>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">class</span> AddressBookController
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">void</span> Service<span style="color: #008000;">&#40;</span>HttpListenerContext context<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">var</span> html <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&lt;html&gt;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;&lt;p&gt;&lt;a href='/contact/create'&gt;Add contact&lt;/a&gt;&lt;/p&gt;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;&lt;p&gt;&lt;a href='/contact/'&gt;Find contact&lt;/a&gt;&lt;/p&gt;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;&lt;/html&gt;&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">var</span> buffer <span style="color: #008000;">=</span> Encoding<span style="color: #008000;">.</span><span style="color: #0000FF;">UTF8</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>html<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        context<span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OutputStream</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>buffer, <span style="color: #FF0000;">0</span>, buffer<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Again, the test will get one step further. Now we can see that the main page is presented with the links &#8220;<tt>Add contact</tt>&#8221; and &#8220;<tt>Find contact</tt>&#8220;. After <tt>Click()</tt>ing &#8220;<tt>Add contact</tt>&#8221; the test will of course fail to find the field <tt>fullName</tt> as we have not created the form yet. The method <tt>HandleGetRequest</tt> inspects the URL to determine which page should be displayed:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">void</span> Service<span style="color: #008000;">&#40;</span>HttpListenerContext context<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">var</span> html <span style="color: #008000;">=</span> HandleGetRequest<span style="color: #008000;">&#40;</span>context<span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">var</span> buffer <span style="color: #008000;">=</span> Encoding<span style="color: #008000;">.</span><span style="color: #0000FF;">UTF8</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>html<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    context<span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OutputStream</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>buffer, <span style="color: #FF0000;">0</span>, buffer<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> HandleGetRequest<span style="color: #008000;">&#40;</span>HttpListenerRequest request<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>request<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LocalPath</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;/contact/create&quot;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;&lt;html&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;form method='post' action='/contact/create'&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;p&gt;&lt;input type='text' name='fullName'/&gt;&lt;/p&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;p&gt;&lt;input type='text' name='address'/&gt;&lt;/p&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;p&gt;&lt;input type='submit' name='saveContact' value='Save'/&gt;&lt;/p&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;/form&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;/html&gt;&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// As before</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>We&#8217;re almost done saving contacts. The test fails to find the link &#8220;<tt>Find contact</tt>&#8221; after submitting the form. The method <tt>Service</tt> must be modified to handle <tt>POST</tt> requests and perform a redirect back to the menu:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">void</span> Service<span style="color: #008000;">&#40;</span>HttpListenerContext context<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>context<span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">HttpMethod</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;GET&quot;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">var</span> html <span style="color: #008000;">=</span> HandleGetRequest<span style="color: #008000;">&#40;</span>context<span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">var</span> buffer <span style="color: #008000;">=</span> Encoding<span style="color: #008000;">.</span><span style="color: #0000FF;">UTF8</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>html<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        context<span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OutputStream</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>buffer, <span style="color: #FF0000;">0</span>, buffer<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span>
    <span style="color: #008000;">&#123;</span>
        context<span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Redirect</span><span style="color: #008000;">&#40;</span>context<span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetLeftPart</span><span style="color: #008000;">&#40;</span>UriPartial<span style="color: #008000;">.</span><span style="color: #0000FF;">Authority</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>We are still missing the form to search for contacts. We&#8217;ll get some help from the copy/paste pattern:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> HandleGetRequest<span style="color: #008000;">&#40;</span>HttpListenerRequest request<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>request<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LocalPath</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;/contact/create&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">...</span>
    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>request<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LocalPath</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;/contact/&quot;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;&lt;html&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;form method='get' action='/contact/'&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;p&gt;&lt;input type='text' name='nameQuery'/&gt;&lt;/p&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;p&gt;&lt;input type='submit' value='Find'/&gt;&lt;/p&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;/form&gt;&quot;</span> <span style="color: #008000;">+</span>
                <span style="color: #666666;">&quot;&lt;/html&gt;&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">...</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The next error is obvious &#8211; we need to actually include the contacts in the response:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #6666cc; font-weight: bold;">class</span> Contact
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> FullName <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">get</span><span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">set</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Address <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">get</span><span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">set</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> List<span style="color: #008000;">&lt;</span>Contact<span style="color: #008000;">&gt;</span> contacts <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Contact<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> HandleGetRequest<span style="color: #008000;">&#40;</span>HttpListenerRequest request<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>request<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LocalPath</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;/contact/&quot;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">var</span> contactsHtml <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Join</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span>,
                    contacts<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>c <span style="color: #008000;">=&gt;</span> <span style="color: #666666;">&quot;&lt;li&gt;&quot;</span> <span style="color: #008000;">+</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; (&quot;</span> <span style="color: #008000;">+</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">Address</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;)&lt;/li&gt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;html&gt;&quot;</span> <span style="color: #008000;">+</span> <span style="color: #008000;">...</span>
                        <span style="color: #666666;">&quot;&lt;ul id='contacts'&gt;{0}&lt;/ul&gt;&quot;</span> <span style="color: #008000;">+</span>
                        <span style="color: #666666;">&quot;&lt;/html&gt;&quot;</span>, contactsHtml<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The only thing missing is to store the contacts when we post the &#8220;<tt>Add contact</tt>&#8221; form:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">void</span> Service<span style="color: #008000;">&#40;</span>HttpListenerContext context<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>context<span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">HttpMethod</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;GET&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">...</span>
        <span style="color: #0600FF; font-weight: bold;">else</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Read the parameters from the POST body (Request.InputStream)</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> request <span style="color: #008000;">=</span> context<span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> encoding <span style="color: #008000;">=</span> context<span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ContentEncoding</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> reader <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamReader<span style="color: #008000;">&#40;</span>context<span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">InputStream</span>, encoding<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> parameters <span style="color: #008000;">=</span> HttpUtility<span style="color: #008000;">.</span><span style="color: #0000FF;">ParseQueryString</span><span style="color: #008000;">&#40;</span>reader<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadToEnd</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, encoding<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            context<span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Redirect</span><span style="color: #008000;">&#40;</span>HandlePostRequest<span style="color: #008000;">&#40;</span>request, parameters<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> HandlePostRequest<span style="color: #008000;">&#40;</span>HttpListenerRequest request, NameValueCollection parameters<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        contacts<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Contact<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> FullName <span style="color: #008000;">=</span> parameters<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;fullName&quot;</span><span style="color: #008000;">&#93;</span>, Address <span style="color: #008000;">=</span> parameters<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;address&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> request<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetLeftPart</span><span style="color: #008000;">&#40;</span>UriPartial<span style="color: #008000;">.</span><span style="color: #0000FF;">Authority</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>One last check is failing: We&#8217;re failing to filter contacts to the query:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> HandleGetRequest<span style="color: #008000;">&#40;</span>HttpListenerRequest request<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>request<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LocalPath</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;/contact/create&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">...</span>
        <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>request<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LocalPath</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;/contact/&quot;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> query <span style="color: #008000;">=</span> request<span style="color: #008000;">.</span><span style="color: #0000FF;">QueryString</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;nameQuery&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> contactsHtml <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Join</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span>,
                contacts
                    <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>c <span style="color: #008000;">=&gt;</span> query <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>query<span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>c <span style="color: #008000;">=&gt;</span> <span style="color: #666666;">&quot;&lt;li&gt;&quot;</span> <span style="color: #008000;">+</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; (&quot;</span> <span style="color: #008000;">+</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">Address</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;)&lt;/li&gt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;html&gt;&quot;</span> <span style="color: #008000;">+</span>
                    <span style="color: #008000;">...</span>
                    <span style="color: #666666;">&quot;&lt;ul id='contacts'&gt;{0}&lt;/ul&gt;&quot;</span> <span style="color: #008000;">+</span>
                    <span style="color: #666666;">&quot;&lt;/html&gt;&quot;</span>, contactsHtml<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">...</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>All that remains to turn this into a real application is to use a real database and correct the obvious security vulnerability when we display contacts. The <tt>AddressBookWebServer</tt> could have a <tt>Main</tt> method to enable you to run the code. But I&#8217;ll leave these issues as an exercise to you, dear reader.</p>
<p>This article has showed how HTTP really works and how frameworks like ASP.NET MVC work behind the curtains. There are many details that we&#8217;re glad that the framework can fix for us, like the character encoding and reading the contents of a POST request. And there are many things that turn out to be not as hard as you&#8217;d think, like a real &#8220;redirect-on-post&#8221; pattern. In more than one project, I&#8217;ve realized that after spending a few days understanding the underlying technology, I could deliver the project much better and faster without the &#8220;obvious&#8221;, popular frameworks that everyone recommend that you use.</p>
<p>Did I reinvent the wheel in this article? You could argue that I did, but let me stretch the metaphor of &#8220;reinventing the wheel&#8221; as far as possible:</p>
<p>My experience is that many &#8220;cars&#8221; today have misaligned wheels where the axel isn&#8217;t mounted in the center. Maybe the wheel was poorly constructed, or maybe the car was just assembled wrong. Maybe we notice that the car is bouncing because two of the wheels have a misaligned axel. And then we spend a lot of work trying to adjust these wheels to synchronize the bouncing. Finally we publish articles about the nice even undulations of our car after aligning the errors in the wheels.</p>
<p>If we have some experience contructing one or two &#8220;wheels&#8221;, it&#8217;s possible that we&#8217;re able to identify the real problems with the &#8220;wheels&#8221; we were given, so we can determine which &#8220;wheels&#8221; are good and which &#8220;wheels&#8221; are bad. Not to mention: We may learn how to use them properly.</p>
<p>Reinvent wheels you don&#8217;t understand, don&#8217;t use a framework you couldn&#8217;t have made yourself and don&#8217;t use a calculatore before you understand math.</p>
<p><em>This article was previously published in Norwegian in <a href="http://blog.kjempekjekt.com/2012/12/20/brodwall-finner-opp-hjulet-luke-20-2012/">Torbjørn Marø&#8217;s programming blog</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://johannesbrodwall.com/2013/01/31/reinventing-wheels/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>If you&#8217;re an architect, knowledge is your enemy</title>
		<link>http://johannesbrodwall.com/2012/12/13/if-youre-an-architect-knowledge-is-your-enemy/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-youre-an-architect-knowledge-is-your-enemy</link>
		<comments>http://johannesbrodwall.com/2012/12/13/if-youre-an-architect-knowledge-is-your-enemy/#comments</comments>
		<pubDate>Thu, 13 Dec 2012 19:51:43 +0000</pubDate>
		<dc:creator>Johannes Brodwall</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Extreme Programming]]></category>
		<category><![CDATA[Non-technical]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://johannesbrodwall.com/?p=982</guid>
		<description><![CDATA[When a software architect gets a good idea or learns something new, he has a problem. The main job of the architect is to ensure that the right information in present inside the heads of the people who should build &#8230; <a href="http://johannesbrodwall.com/2012/12/13/if-youre-an-architect-knowledge-is-your-enemy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>When a software architect gets a good idea or learns something new, he has a problem. The main job of the architect is to ensure that the right information in present inside the heads of the people who should build the application. Every new piece of information in the architect&#8217;s head represents a broader gap between his brain and that of the rest of the team.</p>
<p>The classical ways of adressing this gap is for the architect to write huge documents or sets of wiki pages. When they realize that there&#8217;s not sufficient time set aside in the project schedule for the developers to read all this information, the architect may present the material to developers who sit and nod their heads. But what did they really understand?</p>
<p>Instead of the read-listen-and-nod approach, I prefer an approach that I sometimes call &#8220;dragging the information throught the heads of the team and looking at what comes out in the other end.&#8221; I provide as little processed information as possible, but instead give the team a structured workshop to uncover and structure the information by asking me or business stakeholders. The outcomes of the workshop should be some tanglible results presented by the team. This result is always different from what I had in mind. Sometimes the difference shows a critical misunderstanding, which allows me to go more in depth in this area. Sometimes the difference represents a trivial misunderstanding or difference in opinion and the architect has the difficult task of accepting a small disgreement without distracting the team. Sometimes, the team has discovered something much smarter than the original idea of the architect.</p>
<p>I find it most useful to do workshops in small groups of three people per group. Each group should produce something that they can show to the whole team afterwards. Here are some examples of workshops that I run:</p>
<ul>
<li>Divide in groups of three with the users/business and the developers represented in each group. Each group should discuss and fill in a template for the vision of the product being created: &#8220;For <em>some user</em> who <em>performs some business function</em> the <em>name of system</em> is <em>a type of system</em> which <em>gives a capability related to the task</em>. Unlike <em>most interesting alternative</em> our solution <em>has an important advantage</em>&#8220;. The groups get 10 minutes before a debrief with the whole team.</li>
<li>Each group then brainstorms a list of users, consumers and others affected by the system and write these on sticky notes. This should be about 20-30 roles. The whole team decides on a few interesting users and the groups then write down for some these: What characterizes the user, what tasks do they perform and what do they value?</li>
<li>Based on the list of tasks that stakeholders perform, we create a sketch of a usage flow. I like to refine the documented usage flow with a small task group which takes a few hours to prepare a description of the flow of interaction between the system and external actors</li>
<li>Groups of three go through the usage flow to come up with Actors (users and systems), Domain concepts (classes) or Containers (deployment diagram) mentioned or implied in the usage flow and write these on sticky notes. After showing the Actors, Concepts or Containers to the whole group, each workgroup then organizes these on flipcharts to create a Context Model, a Domain Model and a Deployment Model.</li>
</ul>
<p>Many of these workshops can also be run with distributed groups over video conference and screen sharing.</p>
<p>I like to collect all of these artifacts (vision, users, usage flow, context model, domain model and deployment model) in a PowerPoint presentation so it can be easily showed by the team to external stakeholders. Sometimes someone on the team feel that photographed flipcharts with sticky notes are too informal and decide to draw something in Visio or another fancy tool. This is just a plus.</p>
<p>By asking the team to produce something and present it, rather than explaining the architecture to the team, I ensure that the information is really in their heads and not just my fooling myself by my own understanding.</p>
]]></content:encoded>
			<wfw:commentRss>http://johannesbrodwall.com/2012/12/13/if-youre-an-architect-knowledge-is-your-enemy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>The Rainbow Sprint Plan</title>
		<link>http://johannesbrodwall.com/2012/10/24/the-rainbow-sprint-plan/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-rainbow-sprint-plan</link>
		<comments>http://johannesbrodwall.com/2012/10/24/the-rainbow-sprint-plan/#comments</comments>
		<pubDate>Wed, 24 Oct 2012 16:40:57 +0000</pubDate>
		<dc:creator>Johannes Brodwall</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Extreme Programming]]></category>
		<category><![CDATA[Non-technical]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://johannesbrodwall.com/?p=968</guid>
		<description><![CDATA[Do you ever feel it&#8217;s hard to get real progress in a sprint towards the business goal? Do you feel the feedback from a iteration picks on all the details you didn&#8217;t mean to cover this sprint? Do you feel &#8230; <a href="http://johannesbrodwall.com/2012/10/24/the-rainbow-sprint-plan/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Do you ever feel it&#8217;s hard to get real progress in a sprint towards the business goal? Do you feel the feedback from a iteration picks on all the details you didn&#8217;t mean to cover this sprint? Do you feel like sprint planning meetings are dragging out? Then a Rainbow Sprint Plan may be for you.</p>
<p>Here is an example of a Rainbow Sprint plan:</p>
<ol>
<li style="color:black">A customer wants cheap vacations</li>
<li style="color:red">The customer signs up for daily or weekly notifications of special flight offers</li>
<li style="color:orange">Periodically the System checks which customers should get notifications</li>
<li style="color:red">The System checks for offers that matches the customer&#8217;s travel preference by looking up flights with the travel provider system</li>
<li style="color:#BEBE08">
    The System notifies customer of any matching offers via SMS</p>
<ol>
<li style="color:black">Variation: The System notifies customer of any matching offers via email</li>
</ol>
</li>
<li style="color:orange">The customer accepts the offer via SMS</li>
<li style="color:red">The System books the tickets on behalf of the customer</li>
<li style="color:orange">The system confirms the booking by sending an SMS to the customer</li>
<li style="color:black">The customer can at any point see their active offers and accepted offers on the system website</li>
<li style="color:black">The customer enjoys a cheap vacation!</li>
</ol>
<p>What you can see from this plan:</p>
<p><strong>Use case overview</strong>: The plan gives a high-level picture of the next release. We can see how the work we are doing is fitting together and how it ends up satisfying a customer need. This is a requirement technique that is basically Use Cases as per Alistair Cockburn&#8217;s &#8220;<a href="http://www.amazon.com/Writing-Effective-Cases-Alistair-Cockburn/dp/0201702258">Writing Effective Use Cases</a>&#8220;. I&#8217;ve been writing use cases at this level for the last three years and found it to be a good way to understand requirements. The trick of good use cases is to stay at a the right level. In this example, each step is some interaction between the system and a user or the system and another system. How this communication is handled is something I find best to leave for an individual sprint.</p>
<p><strong>Iterative completion</strong>: Each step has a color code:</p>
<ul>
<li style="color:black">Black: The team hasn&#8217;t started looking into this</li>
<li style="color:red">Red: We have made something, but it&#8217;s a dummy version just to show something</li>
<li style="color:orange">Orange: We have made something, but we expect lots of work remaining</li>
<li style="color:#BEBE08">Yellow: We&#8217;re almost done, we&#8217;re ready to receive feedback</li>
<li style="color:#04CF04">Green: Development is complete, we have done reasonable verification and documentation</li>
</ul>
<p>So the plan accepts that we revisit a feature. As we get closer to the next release, things will move further and further into the rainbow. But we can choose whether we want to get everything to orange first, or whether we will leave some things at red (or even black) while bringing other steps all the way to green.</p>
<p><strong>Demonstration script</strong>: When we get to the end of the sprint and demonstrate what we&#8217;ve created, this plan gives a pretty good idea of what the demo will look like: We will sign up the customer to a dummy signup page (red), we will register some flights in another dummy page (red), trigger the actual scheduling code (orange), then we will see that an SMS is received on an actual phone (yellow). Then we will simulate an SMS response (orange), see that they system made some communication to a dummy system (red), and send &#8220;ok&#8221; back as an SMS to the customer (orange). This will focus the team around a shared vision of what to do in this sprint.</p>
<p>I have been thinking in terms of a Rainbow Plan in my last projects, but I&#8217;ve never used the term before. I think the plan addresses three of the most common problems that I see in Scrum implementations:</p>
<ul>
<li>The team doesn&#8217;t see where it&#8217;s going, because user stories are too fine grained to get the big picture. User story mapping and use cases address this, and rainbow plans put it into a sprint-context</li>
<li>The team dives into technical details during sprint planning. With rainbow plans, the sprint plan becomes the demo plan which coincides with the requirements.</li>
<li>The project has a purely incremental approach, where each feature should be completed in a single sprint. This means that it&#8217;s hard to keep the big picture and the product owner is forced to look for even small bugs in everything that&#8217;s done in a sprint. With rainbow plans, the team agrees on the completeness of each feature.</li>
</ul>
<p>May you always become more goal oriented and productive in your sprints.</p>
]]></content:encoded>
			<wfw:commentRss>http://johannesbrodwall.com/2012/10/24/the-rainbow-sprint-plan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Loud failures are better than silent, faulty behavior</title>
		<link>http://johannesbrodwall.com/2012/10/12/fail-loudly/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fail-loudly</link>
		<comments>http://johannesbrodwall.com/2012/10/12/fail-loudly/#comments</comments>
		<pubDate>Fri, 12 Oct 2012 08:11:05 +0000</pubDate>
		<dc:creator>Johannes Brodwall</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://johannesbrodwall.com/?p=955</guid>
		<description><![CDATA[Sometimes, small questions lead to big answers. Sometimes these answers are controversial. One such question is &#8220;What does this warning about serialVersionUID mean&#8221;? All the advice out there basically is for developers who don&#8217;t know what&#8217;s going on to write &#8230; <a href="http://johannesbrodwall.com/2012/10/12/fail-loudly/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Sometimes, small questions lead to big answers. Sometimes these answers are controversial. One such question is &#8220;What does this warning about serialVersionUID mean&#8221;? All the advice out there basically is for developers who don&#8217;t know what&#8217;s going on to write code that will ignore errors when something unexpected happens. In my view &#8211; this is exactly the wrong approach. The safe way to act is to make sure that your program crashes if you don&#8217;t have control.</p>
<p>Java programmers usually get this warning when they write code that looks like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><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> MyServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpRequest req, HttpResponse resp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Some logic goes here</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>On <a href="http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it">stackoverflow</a> this question has an answer that is extensive, well-written, accepted and, in my opinion, wrong. In short, the answer just recommends to implement something like the following:</p>

<div class="wp_syntax"><table><tr><td class="code"><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> MyServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 123L<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Let&#8217;s dig deeper.</p>
<p>The reason we get this warning is that HttpServlet implements the interface Serializable. This was a design flaw in the first version of the servlet-api, and now we&#8217;re stuck with it. A serialized object can be written to and read from byte streams, such as a file. Here is an example:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lang" style="font-family:monospace;">        ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
        outputStream.writeObject(new Person(&quot;Johannes&quot;, &quot;Brodwall&quot;));
&nbsp;
       // ... somewhere else:
&nbsp;
        ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(file));
        Object object = inputStream.readObject();
        System.out.println(object);</pre></td></tr></table></div>

<p>In this case, everything is fine. But let&#8217;s imagine that some time passes between the write and the read. For example, what if we try to read the file with the next version of the program. A version in which the Person class is changed? For example, what if we changed the implementation of Person to store the name as a single field fullName, instead of two fields firstName and lastName?</p>
<p>In this case, we would get an error message like the following:</p>
<pre>
java.io.InvalidClassException: Person; local class incompatible:
                             stream classdesc serialVersionUID = -4897183855179110397,
                             local class serialVersionUID = -1928642322738440913
</pre>
<p>In other words: If we had set the serialVersionUID, we could still have read the file. Now we&#8217;re stuck.</p>
<p>This is why <a href="http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it">the stackoverflow answer</a> recommends putting a serialVersionUID field in the class.</p>
<p>But <strong>wait</strong>, there&#8217;s another option. Let&#8217;s say we found this problem when we tested if our new version was backwards compatible. Now, we could just cut and paste the serialVersionUID from the stack trace. If we do test our software, this is just as easy as putting the serialVersionUID there in the first place. So, let&#8217;s fix the Person class:</p>

<div class="wp_syntax"><table><tr><td class="code"><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> Person <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>4897183855179110397L<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> fullName<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Person<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> firstName, <span style="color: #003399;">String</span> lastName<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;">fullName</span> <span style="color: #339933;">=</span> firstName <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">+</span> lastName<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: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;[name=&quot;</span> <span style="color: #339933;">+</span> fullName <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;]&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Voila! Problem fixed. Our code will run again. Here&#8217;s the output of printing the object:</p>
<pre>
Person[name=null]
</pre>
<p><strong>Whoops!</strong> By forcing different versions of class Person to have the same serialVersionUID, the code now has a serious bug. FullName should never be null (especially since it&#8217;s final!). And what&#8217;s worse, the bug is a silent one. If we don&#8217;t examine the contents of System.out (in this case), we might not catch it before it escapes into the wild.</p>
<p>When you&#8217;re not sure, the correct behavior should be to fail, not to silently do the wrong thing.</p>
<h3>TL;DR</h3>
<p>If you omit a serialVersionUID field from your class, many changes will cause serialized objects to no longer be readable. Even for trivial changes.</p>
<p>Sadly, classes like HttpServlet, AbstractAction and JFrame which are meant to be subclassed implements Serializable, even though they are almost never serialized in practice. Adding serialVersionUID to these classes would only be noise.</p>
<p>The serialVersionUID field can be added to a class afterward if you actually want to read old objects in a new version of the program. This leaves you no worse off than if you added the serialVersionUID field in the first place.</p>
<p>If the old and the new version of the class are deeply incompatible, giving the class a serialVersionUID when you first create it will cause silent faulty behavior.</p>
<p>I prefer loud, failing behavior that is easy to detect during testing over quiet, faulty behavior that may escape into production. I think you do, too.</p>
]]></content:encoded>
			<wfw:commentRss>http://johannesbrodwall.com/2012/10/12/fail-loudly/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>
