Run tests in different packages and linked sources with JUnit TestSuite

In a project that I’m working on we’re using linked sources and we have multiple sub-packages with JUnit tests. We ran into some issues with running the test. Thankfully, although the eclipse wizards wouldn’t help us create a test suite that would run all the tests it was trivial to write the suite by hand.

It can look like this:

This will allow you to test any class that you import no matter what package it is in. To run this in eclipse you just right click the AllTests class and run it as JUnit test. It will then run all the tests you define in @SuiteClasses.

This will work with linked sources as well, I use it all the time.

Send a JSON object to server over TCP connection in Java using Socket

So the other day I was struggling with sending a JSON object to a server. The JSON service would not accept this special object over HTTP so I had do dig into some Socket handling to send it. Of course, we could use Netcat to send the object like this:
echo '{"id":1, "method":"object.deleteAll", "params":["myParam"]}' | nc x.x.x.x 3994

But since the application I was working on needed to run some tests on creating and deleting stuff from the server we really needed a Java method to do this for us.

Here’s the code:

Creating the Socket is straight forward, the most noteworthy thing here the Writer that is being used. I tried with so many different Writers that I forgot what they all where called. Also note that the PrintWriter.println() method is used rather then the PrintWrite.print() method.

Nicer looking GitStats and Graphs

Heikki Hokkanen is the author behind the awesome tool GitStats. It is widely used all over the world to bring out some readable statistics from a git repository. Of course it is possible to get some nice command line output but there is nothing like a couple of bar charts and line charts.

The CSS-design of the tool is not the most updated to suit the modern day demands from bosses and customers so if you want to show off some stats you might want to try out my modified version of the tool. I take no credit on the tool what so ever, I’ve only spent a little time re-doing som CSS. I am not completely finished with the work yet since some of the styles are being set in the script that generates the html from the git repos. I will post again once it’s finished until then you can at least give it a try and post some feedback over on GitHub!

 

If you don’t like graphics with more then 8-bit color space and you love the terminal, don’t worry. I have something for you as well. Add the following codes to your ~/.gitconfig file and you will be seing colors all over the place when running the commands git lg/lg2 `