Sunday, September 24, 2006

Monday, September 18, 2006

The purpose of the MOCK

In response to a much nicer blog entry, that can be found here.


There are actually several distinct "tests" that make up usual unit tests, among them two that really do stand out:
  • one kind of testing to test method flows,
  • one to test some sort of computation.

Mock objects are for the purpose of testing method flows. A method flow is a series of message transmissions to dependent objects.

The control flow logic inside the method(the ifs and whiles) will alter the flow
  • in repsonse to the parameters of the method call parameters passed by calling the method under test,
  • depending on the state of the object that contains the method under test and
  • the return values of the external method calls(aka responses to the messages sent).
There should be one test method for every branch of an if statement, and usuale some sort of mock control objects in the mock framework will handle loop checking.

BTW: I partly use message transmission instead of method invocation to include other kinds of "not really method invocations" like "exceptions".

The author of the afore mentioned post is quite right with his observation, that his test resembles the method under test quite closely, except, of course, for the control flow code(loops, conditionals). And that is absolutely desired, as he is testing mainly the "method flow" - there is not much computation necessary in JDBC code like this anyway.

It is tempting to raise the objection that a change in the order of messages sent to another object inside the method under test will result in a failing test, but it is easy to perceive the fact that the order of messages send to ONE object SHOULD be relevant. If it is not, well then there is no point in changing the method under test, isn't there?

Even if the method under test send variuos messages to various distinct objects, the order will be relevant at some level of abstraction. Therefore mock-checking of the order of method invocations can be(and must be) adjusted, at least if multiple distinct objects are addressed by the method under test.

And nothing else is it, that the author proposes, although, a little more complicated, than necessary when using easymock, for what I know.

Friday, September 15, 2006

Free Programming Books

I stumbled over some not so common class of free programming books:

Although these books are not the most recent spiffy Ajax/Java books, the are worth reading:

  1. A nice book about Mozilla programming
  2. Some Free Smalltalk books(yes smalltalk ain't dead yet)

Thursday, September 14, 2006

Maven Changelog plugin

I tried to use the maven changelog plugin, as described here
but maven complained that it could not find the plugin!

That was due to the fact this plugin is not yet stable, this wasnt mentioned anywhere I looked.

To enable the plugin you must first add the apache maven snapshot repository, read this site to find out how.

Wednesday, September 13, 2006

AntiPatterns

I just realized some nice Articles in the English and German wikipedia about anti patterns. I was well aware of the existence of software engineering related anti patterns, but I read about two other categories of anti patterns, well explained in the afore mentioned articles:
  • organizational&project management anti-patterns
  • and Meta-(anti)-Patterns

I found it both enlightening and shocking to learn about these patterns. Nevertheless the most funniest were IMHO:
  1. Programmer Experience Clumping
  2. Fear of success
  3. Management by numbers
  4. Single head of knowledge

Sources:

Tuesday, September 12, 2006

Maven Source-Formatting/-Metrics

I needed to add source code formatting and some code metrics to my maven based project. These are the places on the web where I found help.

I wanted to get the Jalopy plugin to format my source code, and promptly failed to get the snaptshots from the mojo projects without the help of this resource,
this resources helped me to get the codehaus mojo snapshot plugins:
What to put in settings.xml

after that I could simply run:

mvn -Pcodehaus jalopy:format

As I was bothered by the command line cluttering by -Pcodehaus, I actived the profile by adding <activeByDefault/> into the activation tag in the profile definiton for the "codehaus" profile.
Now ....

mvn jalopy:format

... and voila! Jalopy formatted my sources.

See also: maven Jalopy plugin

Very helpful for the "other" reports was an interesting java world article...

I also wanted JDepend to check my project, to I added Jdepend.

my first migration of a legacy project to maven 2

I had to do migrate a legacy webstart swing application to the maven build process. The app was build into several(signed) jars from a single source directory(containing a mix of java files, property files and html help files). The app was deployed with webstart.

Sometimes the pom file reference and settings file reference were helpful...

Important is the introduction to maven lifecycles.
Interresting is the fact, that maven uses plexus container for IoC, reading the comparison, I figured I should try using plexus in another project...

These are the steps that needed to be done to migrate the project:

1. Install 3rd party jars into the local repository
- I checked in this repository

2. use the maven2 jar plugin to create a manifest wich points out the main class:
Maven2 Jar plugin

3. use the jar plugin to sign the jar
- use the maven keytool plugin to create the keystore automatically after reading this page.
- add the jar plugin sign goal

4. use the assembly plugin to creat a a zip file with my (bad practice) manually created jnlp file.
- read the assemply plugin introduction

this pages describes howto use the maven-antrun-plugin.

5. create the appropriate ant build file

Maven 2 3rd Party Jars

Maven: Installing 3rd Party JARs
This page states that one should install a file into the local repository; But another option I found more useful in a team development environment is to deploy 3rd party jars to a maven repository in the companies network via ssh/scp.

If multiple developers work on the project it is advisable to have a linux box somewhere with an ssh server installed and apache running. Just configure this
server in your settings.xml and define the deployment to use that server.


All 3rd party jars, the project website/reports and the project itself can then be deployd to that server with this:



mvn deploy:deploy-file -DgroupId= -DartifactId= -Dversion= -Dpackaging= -Dfile= -DrepositoryId= -Durl=


Taken fromhere.


I truely love maven ;-)