Categories:
Software Design, Java, Testing
JMock and Multi Threading
I came across a problem recently regarding
jMock and threading.
The problem was that the test seemed to have "passed", but the expectations set on the mock object were not executed.
The cause of this was because the test's thread was separate to the thread spawned by the program.
According to
jMock - threading should be covered by integration testing, while
jMock is meant to be used for
unit testing - as such multi-threading is not supported.
However,there is a way around this...
Instead of spawning a thread in the program - create an interface which can be mocked.
The implementation of the interface would have a method that accepted a
Runnable class, and the thread would be spawned in this method.
The test would have it's own implementation of the interface, but instead of spawning a thread, the test would just execute the
run() method of
the
Runnable class.
Here's a simple example:
public interface Runner {
void start(Runnable handle);
}
public class RunnerImpl implements Runner {
public void start(Runnable handle) {
Thread t = new Thread(handle);
t.start();
}
}
public class ThreadHandle implements Runnable {
public void run() {
//actual behaviour when the thread runs
}
}
public class Server {
private Runner runner;
private ThreadHandle handle;
public Server (Runner runner, ThreadHandle handle) {
this.runner = runner;
this.handle = handle;
}
public void startUp() {
//code...
runner.start(handle);
}
}
This would be the implementation class that the test would use:
public MockRunnerImpl implements Runner {
public void start(Runnable handle) {
handle.run(); //call run of the Runnable class instead of creating a thread and calling start()
}
}
Another way around this is to use Executor - this is described on jMock's site
here
While I'm on the topic of jMock, another tip (applicable to
1.x versions) - when mocking concrete classes, use
cglib. An example of this can be found
here
Categories:
Graphic Design, Hints & Tips
Open Source Alternatives to Adobe Illustrator
I seemed to have misplaced my Adobe Illustrator CD... as such I trawled the internet for a free open source alternative.
As it turned out, I came across a site called
Open Source Alternative, which listed some
open source programs I could use as an alternative to Adobe Illustrator.
I'm now trialling
Inkscape, and it seems to be ok, although I've only opened it for about 5 minutes and
played with drawing lines and layers (I haven't trialled a lot just yet!).
I'm adding other alternatives that were listed, in case anyone is interested in trialling these other open source alternatives.
Categories:
Web Design, Hints & Tips
Conditional Comments - Making HTML/CSS work with Internet Explorer
Sometimes no matter how much I tweak my HTML/CSS to work with different browsers, I find that I have to resort to conditional comments...
(Note: these work with Internet Explorer, other browsers will treat these are normal comments).
These generally look like:
<!--[if IE]>
Add IE specific HTML
<![endif]-->
You can also check which version of Internet Explorer with the following examples:
<!--[if IE 6]>
Add HTML for IE 6
<![endif]-->
<!--[if gt IE 6]>
Add HTML for IE browsers greater than IE 6
<![endif]-->
<!--[if gte IE 6]>
Add HTML for IE browsers greater than or equal to IE 6
<![endif]-->
<!--[if lt IE 6]>
Add HTML for IE browsers less than IE 6
<![endif]-->
<!--[if lte IE 6]>
Add HTML for IE browsers less than or equal IE 6
<![endif]-->
It's a bit of a hack, so I try to avoid them as much as possible.
But I thought I'd share this little hint because it can be quite handy for including IE specific HTML or CSS.
Categories:
Design
bee & b
Yesterday I made a trip to Glebe markets, and despite sitting in city traffic and enduring the hot summer heat,
I was fortunate enough to check out
bee & b.
I was very impressed with the range of accessories and dresses on offer.
Despite wanting to buy everything there, I made one small purchase - a cute little white clutch bag.
If anyone is interested in checking them out,
bee & b
should be at Glebe on
January 31st, 2009.
Categories:
Graphic Design
Threadless - who are they?
I fell in love with Threadless (check out
threadless.com) back in 2006 and
this was because they sold awesome t-shirts (thank you Nikka!). They still do - but they have now expanded to prints and their corporation
skinnycorp includes other projects such as
naked & hungry.
So I've been buying their t-shirts for a while now and whenever I'm out and about,
I can pretty much recognise a Threadless tee when I see one.
And what's also cool about this site is that people can participate in designing and scoring t-shirt designs.
A year ago, I decided to try and make a design for a Threadless tee.
It wasn't until a week ago, that I decided to actually submit one.
So I'm going to end this post with a plug for my first submission (let's hope it gets through!)... :)
You can check it out
here
This is my first post for 2009, in fact the first post in a long time.
My blog has been dormant for quite some time now -
and this is mostly because I want to write about something that's worth writing about.
The aim this time around is to write about design in some way or other - mostly around graphic design, web design and software design.
I don't claim to be an expert, but I am interested in design and IT (and I suppose it helps that I work in IT).
I'm slowly going through and redesigning my site - it's pretty much bare bones at the moment, but expect some changes and additions to this site.