<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog &#187; Computer stuff</title>
	<atom:link href="http://blog.bprog.no/index.php/category/computerstuff/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bprog.no</link>
	<description>Some personal and some technical posts</description>
	<lastBuildDate>Sun, 14 Jun 2009 19:04:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Intel X25-M rules on Ubuntu 9.04</title>
		<link>http://blog.bprog.no/index.php/2009/05/intel-x25-m-rules-on-ubuntu-904/</link>
		<comments>http://blog.bprog.no/index.php/2009/05/intel-x25-m-rules-on-ubuntu-904/#comments</comments>
		<pubDate>Sun, 17 May 2009 11:17:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Intel SSD]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[X25-M]]></category>

		<guid isPermaLink="false">http://blog.bprog.no/?p=139</guid>
		<description><![CDATA[I finally got tired of waiting for the prices to drop further so I bought me a little from-me-to-me present, the Intel X25-M SSD. Ubuntu 9.04 already boots pretty fast, but with this drive it&#8217;s amazing! As you can read from the chart belove it takes around 10 seconds to get to the login screen. [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got tired of waiting for the prices to drop further so I bought me a little from-me-to-me present, the Intel X25-M SSD. Ubuntu 9.04 already boots pretty fast, but with this drive it&#8217;s amazing! As you can read from the chart belove it takes around 10 seconds to get to the login screen. When I bought it I had hoped that it would make NetBeans and compilation of some semi-heavy Java projects more snappy, but it turnes out that the CPU was a much larger bottleneck than I had expected.</p>
<p><img class="aligncenter size-full wp-image-142" title="Ubuntu 9.04 boot with Intel X25-M SSD" src="http://blog.bprog.no/wp-content/uploads/2009/05/lappis2-jaunty-20090515-11.png" alt="Ubuntu 9.04 boot with Intel X25-M SSD" width="588" height="2268" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bprog.no/index.php/2009/05/intel-x25-m-rules-on-ubuntu-904/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jøss NRK er ikke bekymret for utgiftene ved arrangering av MGP!!</title>
		<link>http://blog.bprog.no/index.php/2009/05/j%c3%b8ss-nrk-er-ikke-bekymret-for-utgiftene-ved-arrangering-av-mgp/</link>
		<comments>http://blog.bprog.no/index.php/2009/05/j%c3%b8ss-nrk-er-ikke-bekymret-for-utgiftene-ved-arrangering-av-mgp/#comments</comments>
		<pubDate>Sun, 17 May 2009 11:09:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Nyheter]]></category>
		<category><![CDATA[MGP]]></category>
		<category><![CDATA[NRK]]></category>

		<guid isPermaLink="false">http://blog.bprog.no/?p=136</guid>
		<description><![CDATA[Jeg hadde heller ikke bekymret meg stort om penger hvis alle i landet med en tv var tvunget til å betale meg nesten tre tusen kroner i året!
http://e24.no/medier-og-reklame/article3079677.ece
]]></description>
			<content:encoded><![CDATA[<p>Jeg hadde heller ikke bekymret meg stort om penger hvis alle i landet med en tv var tvunget til å betale meg nesten tre tusen kroner i året!</p>
<p><a title="http://e24.no/medier-og-reklame/article3079677.ece" href="http://e24.no/medier-og-reklame/article3079677.ece">http://e24.no/medier-og-reklame/article3079677.ece</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bprog.no/index.php/2009/05/j%c3%b8ss-nrk-er-ikke-bekymret-for-utgiftene-ved-arrangering-av-mgp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash script for creating files in empty folders &#8211; Mercurial workaround</title>
		<link>http://blog.bprog.no/index.php/2009/05/bash-script-for-creating-files-in-empty-folders-mercurial-workaround/</link>
		<comments>http://blog.bprog.no/index.php/2009/05/bash-script-for-creating-files-in-empty-folders-mercurial-workaround/#comments</comments>
		<pubDate>Sun, 10 May 2009 01:00:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Empty folders]]></category>
		<category><![CDATA[Mercurial]]></category>

		<guid isPermaLink="false">http://blog.bprog.no/?p=125</guid>
		<description><![CDATA[I was astonished to find out that Mercurial was unable to represent empty folders. The most obvious workaround is to create an empty file in each of those folders. But hey, you don&#8217;t want to do that by hand do you? Well luckily we&#8217;re all using a Linux based OS with an extremely powerful command [...]]]></description>
			<content:encoded><![CDATA[<p>I was astonished to find out that Mercurial was unable to represent empty folders. The most obvious workaround is to create an empty file in each of those folders. But hey, you don&#8217;t want to do that by hand do you? Well luckily we&#8217;re all using a Linux based OS with an extremely powerful command line. It took me just a couple of minutes to come up with a one-liner bash script which creates an empty file in every empty directory.</p>
<blockquote><p>find . -empty -type d | xargs &#8211;replace=EMPTYDIR touch &#8220;EMPTYDIR/.empty&#8221;</p></blockquote>
<p>This will put an empty file named &#8220;.empty&#8221; in every empty sub directory from where you&#8217;re standing.</p>
<p><strong><em><span style="color: #800000;">Please make sure that you copy the line correctly. There is an double hyphen before xargs&#8217;s replace parameter and regular double quotes around the touch argument. </span></em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bprog.no/index.php/2009/05/bash-script-for-creating-files-in-empty-folders-mercurial-workaround/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A first look at Mercurial &#8211; Bye bye Subversion?</title>
		<link>http://blog.bprog.no/index.php/2009/05/a-first-look-at-mercurial-bye-bye-subversion/</link>
		<comments>http://blog.bprog.no/index.php/2009/05/a-first-look-at-mercurial-bye-bye-subversion/#comments</comments>
		<pubDate>Sun, 10 May 2009 00:39:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mercurial SVN]]></category>

		<guid isPermaLink="false">http://blog.bprog.no/?p=123</guid>
		<description><![CDATA[I&#8217;m so sick and tired of Subversion! A couple of days ago our repository server was down which caused the f&#8230; stupid svn client to hang. Not even pressing Ctrl-C would stop it. In the end I had to kill it the hard way. This obviously messed up the svn locks. You should think that [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m so sick and tired of Subversion! A couple of days ago our repository server was down which caused the f&#8230; stupid svn client to hang. Not even pressing Ctrl-C would stop it. In the end I had to kill it the hard way. This obviously messed up the svn locks. You should think that they had implemented a timeout and sensible error message by 2009? And don&#8217;t even get me started on all those .svn directories laying around!</p>
<p>Anyway, this finally pushed me to have a look at alternatives. I&#8217;ve been wanting to try out Mercurial for some time now and this pushed me over the edge. My first impression is really good! I obviously have to spend some time getting used to the distributed model, but it seems like it might be worth it. Everything was looking rose red until I figured out that it doesn&#8217;t support tracking of empty folders!? It does make sense when I think about their architecture built up around sha1 sums, but I still think that it&#8217;s strange. I often create a directory structure before I start coding. The workaround seems to be creating empty files inside each folder, which sounds a little annoying to me.</p>
<p>That&#8217;s it for now. Man it felt good to shout and scream a little about Subversion! <img src='http://blog.bprog.no/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bprog.no/index.php/2009/05/a-first-look-at-mercurial-bye-bye-subversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NetBeans 6.7 is looking good!</title>
		<link>http://blog.bprog.no/index.php/2009/05/netbeans-67-is-looking-good/</link>
		<comments>http://blog.bprog.no/index.php/2009/05/netbeans-67-is-looking-good/#comments</comments>
		<pubDate>Fri, 08 May 2009 20:45:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[NetBeans]]></category>

		<guid isPermaLink="false">http://blog.bprog.no/index.php/2009/05/netbeans-67-is-looking-good/</guid>
		<description><![CDATA[I&#8217;ve been trying out the beta build of NetBeans version 6.7 and it&#8217;s looking very good. The PHP support is becoming very good.
Even Grails support is coming along with support for Grails 1.1. Rumors has it that even debugging is supported now! Nice work!
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying out the beta build of NetBeans version 6.7 and it&#8217;s looking very good. The PHP support is becoming very good.</p>
<p>Even Grails support is coming along with support for Grails 1.1. Rumors has it that even debugging is supported now! Nice work!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bprog.no/index.php/2009/05/netbeans-67-is-looking-good/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grails converters not available in unit testing</title>
		<link>http://blog.bprog.no/index.php/2009/05/grails-converters-not-available-in-unit-testing/</link>
		<comments>http://blog.bprog.no/index.php/2009/05/grails-converters-not-available-in-unit-testing/#comments</comments>
		<pubDate>Fri, 08 May 2009 20:42:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[convertes]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://blog.bprog.no/?p=117</guid>
		<description><![CDATA[Bah, can&#8217;t believe that it took me that long to figure it out. Apparently you need to have the Grails application context up and running in order to use convertes (as XML / JSON) in your unit tests. After moving my test from the unit test folder over into the integration test folder it worked [...]]]></description>
			<content:encoded><![CDATA[<p>Bah, can&#8217;t believe that it took me that long to figure it out. Apparently you need to have the Grails application context up and running in order to use convertes (as XML / JSON) in your unit tests. After moving my test from the unit test folder over into the integration test folder it worked like a charm. Well, I&#8217;ve wasted time and blogged about it so you won&#8217;t have to repeat the mistake. Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bprog.no/index.php/2009/05/grails-converters-not-available-in-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedded Java LDAP server for unit testing</title>
		<link>http://blog.bprog.no/index.php/2009/04/embedded-java-ldap-server-for-unit-testing/</link>
		<comments>http://blog.bprog.no/index.php/2009/04/embedded-java-ldap-server-for-unit-testing/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 19:20:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[apacheds]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[opends]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.bprog.no/?p=114</guid>
		<description><![CDATA[I&#8217;ve just spent about a day trying different embeddable Java LDAP servers. To save you from all the trouble I came across I&#8217;m going to share some of my experiences.
Basically you have three choices when it comes to  embeddable Java LDAP servers (at least open source). First of you have Sun&#8217;s OpenDS, they have a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just spent about a day trying different embeddable Java LDAP servers. To save you from all the trouble I came across I&#8217;m going to share some of my experiences.</p>
<p>Basically you have three choices when it comes to  embeddable Java LDAP servers (at least open source). First of you have Sun&#8217;s <a href="https://opends.dev.java.net/">OpenDS</a>, they have a page dedicated to <a href="https://www.opends.org/wiki/page/TipsAndTricksForWritingUnitTests">Tips and tricks for writing unit tests</a>. I have to say that I&#8217;m not very impressed by OpenDS. Don&#8217;t take me wrong it might be a fantastic LDAP server, but it certainly does not give me the feeling of being very embeddable! First of all the documentation refers to a mysterious class TestCaseUtils. I&#8217;ve checked builds from version 1.0.something to 1.2.something without finding it. The second drawback is that OpenDS is like a flesh-eating-configuration-monster sent back in time to kill the spirit of any developers getting near it. It comes with a 2000+ lines ldif config file, which is supposed to work for servers running embedded as well. It would be nice if they could provide a minimal configuration file for embedded use. To me it complained a lot about errors in the bundled schemas. Oh that&#8217;s right you need to set up a directory structure for config files, schemas and locks. Again, not very embeddable!</p>
<p>The second and third choise is <a href="http://directory.apache.org/">ApacheDS.</a> You have the newer version 1.5. with support for fancy things like triggers and stuff and you have the older 1.0 series. Both LDAPv3 compatible. The project is very well documented and they even maintain something they call Apache Directory Studio, which is a graphical LDAP GUI based on Eclipse. Very nice! If you don&#8217;t need the fancy stuff implemented in the 1.5 series I really recommend that you go for the older 1.0 series for your unit testing. You&#8217;ll find jars in Maven repos and it&#8217;s really simple to get started. It just works the way you expect it to! Just follow this <a href="http://directory.apache.org/apacheds/1.0/using-apacheds-for-unit-tests.html">guide</a> and you will be unit testing your LDAP code in no time.</p>
<p>At the time I&#8217;m writing this 1.5.4 is the newest version of the 1.5 series. They have a <a href="http://directory.apache.org/apacheds/1.5/42-using-apacheds-for-unit-tests.html">guide for doing unit testing with 1.5 as well</a>, but due to some problems it won&#8217;t work with 1.5.4 so you&#8217;ll have to build the trunk for your self or track down a Maven snapshot repo (good luck!).</p>
<p>Happy testing!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bprog.no/index.php/2009/04/embedded-java-ldap-server-for-unit-testing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The OCZ SSD syndrome</title>
		<link>http://blog.bprog.no/index.php/2009/02/the-ocz-ssd-syndrome/</link>
		<comments>http://blog.bprog.no/index.php/2009/02/the-ocz-ssd-syndrome/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 00:34:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[apex]]></category>
		<category><![CDATA[ocz]]></category>
		<category><![CDATA[SSD]]></category>
		<category><![CDATA[vertex]]></category>

		<guid isPermaLink="false">http://blog.bprog.no/?p=112</guid>
		<description><![CDATA[It&#8217;s a shame that all the OCZ disks are haunted by what I like to call the &#8220;OCZ SSD syndrome&#8221; which is a ridiculous low number of write operations per second. The first disk to be plagued by this problem was the OCZ Core disk. Today I read a review of their Apex model and [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a shame that all the OCZ disks are haunted by what I like to call the &#8220;OCZ SSD syndrome&#8221; which is a ridiculous low number of write operations per second. The first disk to be plagued by this problem was the OCZ Core disk. Today I read a <a href="http://www.hardware.no/artikler/ocz_apex_120_gb/67481">review of their Apex model</a> and it seems to suffer from the same problem.</p>
<p>I can&#8217;t believe that they&#8217;re still releasing disks with this problem! It has to affect their reputation in a very negative way!? I&#8217;m curious to read reviews of their new Vertex series. They&#8217;re supposed to have 32-64MB on board cache that should remove some of the iops problems.</p>
<p>Guess it&#8217;s just left to hope that we&#8217;ll see cheap SSDs without iops problems soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bprog.no/index.php/2009/02/the-ocz-ssd-syndrome/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A w3.org standard for smileys?!</title>
		<link>http://blog.bprog.no/index.php/2009/01/a-w3org-standard-for-smileys/</link>
		<comments>http://blog.bprog.no/index.php/2009/01/a-w3org-standard-for-smileys/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 07:24:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[emoticon]]></category>
		<category><![CDATA[smiley]]></category>
		<category><![CDATA[standard]]></category>
		<category><![CDATA[w3.org]]></category>

		<guid isPermaLink="false">http://blog.bprog.no/?p=110</guid>
		<description><![CDATA[You better be kidding me!!
http://www.w3.org/2005/Incubator/emotion/XGR-emotionml-20081120/
]]></description>
			<content:encoded><![CDATA[<p>You better be kidding me!!</p>
<p><a href="http://www.w3.org/2005/Incubator/emotion/XGR-emotionml-20081120/">http://www.w3.org/2005/Incubator/emotion/XGR-emotionml-20081120/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bprog.no/index.php/2009/01/a-w3org-standard-for-smileys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit testing private methods in Java</title>
		<link>http://blog.bprog.no/index.php/2009/01/unit-testing-private-methods-in-java/</link>
		<comments>http://blog.bprog.no/index.php/2009/01/unit-testing-private-methods-in-java/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 01:26:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.bprog.no/?p=101</guid>
		<description><![CDATA[Want to unit test a private method in Java?
You could obviously change your methods access modifier from private. By making it public you&#8217;re breaking encapsulation and by making it protected you&#8217;re making your API less intuitive. Don&#8217;t do that.
Another way to go about this is to create a new class that&#8217;s extending the one with [...]]]></description>
			<content:encoded><![CDATA[<p>Want to unit test a private method in Java?</p>
<p>You could obviously change your methods access modifier from private. By making it public you&#8217;re breaking encapsulation and by making it protected you&#8217;re making your API less intuitive. Don&#8217;t do that.</p>
<p>Another way to go about this is to create a new class that&#8217;s extending the one with your private method</p>
<p>I find the easiest and most convenient way achieve unit testing of private methods is <a href="http://java.sun.com/docs/books/tutorial/reflect/index.html">reflection</a>. Some of the features the Java reflection API offers is access to private fields and invocation of private methods. This sounds like something useful for our problem, by using reflection we&#8217;re able to test our private methods without making any changes to our classes.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> TestSubject <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * For some reason we want to unit-test this method
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> adder<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> numberOne, <span style="color: #000066; font-weight: bold;">int</span> numberTwo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> answer <span style="color: #339933;">=</span> numberOne <span style="color: #339933;">+</span> numberTwo<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> answer<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is the method we want to test, here is how we go around to actually do it:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">TestSubject subjectInstance <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TestSubject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">Class</span> testClass <span style="color: #339933;">=</span> subjectInstance.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Find the method. getDeclaredMethod will give you any methods from that</span>
<span style="color: #666666; font-style: italic;">// class whether it's public or not where getMethod only will give you</span>
<span style="color: #666666; font-style: italic;">// methods with public access. The first argument is obviously our method's name,</span>
<span style="color: #666666; font-style: italic;">// where the next arguments are the formal types of the adder methods parameters.</span>
<span style="color: #003399;">Method</span> adderMethod <span style="color: #339933;">=</span> testClass.<span style="color: #006633;">getDeclaredMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;adder&quot;</span>, <span style="color: #000066; font-weight: bold;">int</span>.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">int</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Method is a sub class of AccessibleObject if we don't call it's</span>
<span style="color: #666666; font-style: italic;">// setAccessible method we'll get an IllegalAccessException when we</span>
<span style="color: #666666; font-style: italic;">// try to invoke it on our object.</span>
adderMethod.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// Invoke the method on our instance of TestSubject</span>
<span style="color: #000066; font-weight: bold;">int</span> answer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span><span style="color: #009900;">&#41;</span> adderMethod.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>subjectInstance, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// assert answer = 4</span></pre></div></div>

<p>It&#8217;s more or less just to plug it into your testing framework of choice and you&#8217;ll have unit testing of your private methods.</p>
<p>But hey! Do you <em>really</em> want to unit test your private methods? Doesn&#8217;t it give you that bad feeling in your stomach. You know the feeling you get when you&#8217;re code smells a little? I mean, a part of the reason for those methods being private is that they&#8217;re subject to change.</p>
<p>It&#8217;s the oldest oo rule in the book, hide the inner working of you&#8217;re classes so you later can change the inner workings of the class without exposing any change to your clients. What you really want to do is to unit test the public methods using those private once. If you find that difficult it <em>might</em> be a little hint that you should consider changing your design a little in order to improve it&#8217;s testability.</p>
<p>Why did I bother showing you how to unit test private methods if I consider it bad practice? Well, sometimes when I&#8217;m working on complicated things I like to unit-test private methods while working on the class. And there might be situations where unit testing of private methods is the right way to go. Just be careful so you&#8217;re not writing a lot of tests you&#8217;ll waste a lot of time maintaining later!</p>
<p>Relevant Java API: <a href="http://java.sun.com/javase/6/docs/api/java/lang/Class.html">Class</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/reflect/Method.html">Method</a> and <a href="http://java.sun.com/javase/6/docs/api/java/lang/reflect/package-summary.html">reflect</a>.</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bprog.no/index.php/2009/01/unit-testing-private-methods-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
