EclEmma

Emma is a coverage tool.

EclEmma is an Eclipse plugin that generates Emma coverage. It installs via an update site. It executes via the Run Dialog, so any existing run configuration can be easily “coveraged” (including RCP JUnit tests). An additional coverage tab in the Run Dialog allows you to select which packages will be instrumented.

Results are shown graphically in an Eclipse view, grouped by packages. The view allows you to drill into classes and into methods, showing the coverage of each level along the way. Double-clicking in the view brings up the source code, which is color coded to represent which lines were covered.

This is very useful during the personal development process, as individuals can selectively run unit tests to check for coverage in the related modules they are working with. The results are interactive and allows the developer to quickly see which areas require coverage improvement. This is much easier than waiting and going through a Continuous Integration report later (if any). In fact, I have successfully employed this approach to identify areas lacking coverage, and discovering bugs after having test cases for those areas identified.

JTable column headers

A JTable’s column headers are not shown when you add a JTable to the container.

To show the headers, add the table into a JScrollPane before adding it into the container.

If for whatever reason the scroll pane is not desired, use JTable.getTableHeader() to get the column header component, which you can add to the NORTH side of a BorderLayout for example.

JUnit addons

JUnit-addons is a useful library that extends JUnit asserting features. To name a few:

junitx.framework.ArrayAssert: If you’ve written test cases long enough you’ll know that assertEquals won’t work on arrays, and you’ll repeatedly write a loop to assert so. This class takes care of it all.

junitx.util.PrivateAccessor: I’ve always written utility classes to help me set private fields when mocking test objects. Looks like I’m not the only one with the problem.

junitx.framework.Assert.assertNotEquals(): Might be useful in certain cases. Not really recommended because you really want to match the value you’re asserting. It’s too easy to pass a NotEquals() test.

javax.crypto.Mac not threadsafe

Although not explicit, the usage of the class quite obviously shows that multiple threads shouldn’t use the same instance to calculate a hash.

In particular, even if the update() methods were not used and multiple threads call the doFinal() method together, you are likely to get a bad result (which is worse than an Exception).

Something unit test cases cannot catch.

PHP XML XPath

The problem with the simple XML-RPC wordpress solution was that it did not have feedback whether the post was successful. I knew I could get the response from curl_exec, but I have to figure out the XPath part. Similarly I was hoping for some ready-made function to do that, but it seems things were not so straightforward. Furthermore, being on PHP4 means I didn’t have the luxury of the newer XML functions such as SimpleXML.

After some fiddling, this was the simplest I could go:


$dom = domxml_open_mem($response);
$faultString = xpath_eval(xpath_new_context($dom), 
	  "/methodResponse/fault/value/struct/member[name='faultString']/value/string/text()");
return $faultString->nodeset[0]->content;

The XPath expression was also a level-up: I had to select a node based on the child data of its sibling.

WordPress XML-RPC

I wanted a stripped-down “mobile” version of the WP admin interface for posting, but I couldn’t find a suitable one. So while I thought about writing my own, I looked for ready made XML RPC solutions.

Indeed, as I expected, one function is all it takes.


function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1)){
	$categories = implode(",", $categories);
	$XML = "$title".
	"$categories".
	$body;
	$params = array('','',$username,$password,$XML,1);
	$request = xmlrpc_encode_request('blogger.newPost',$params);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
	curl_setopt($ch, CURLOPT_URL, $rpcurl);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 1);
	curl_exec($ch);
	curl_close($ch);
}

I made a small HTML form and submitted it to this PHP function, and that’s it! 15 minutes worth of work.

VirtualBox remote access

VirtualBox supports RDP (Remote Desktop Protocol), which can be enabled by the following steps.

  1. Power off the Guest machine (doesn’t work in saved state).
  2. Click “Settings” to configure the settings for the VM.
  3. Select the Remote Display tab, check “Enable VRDP Server”.
  4. If you’re on Windows you might need to change the server port because it may conflict with the Remote Desktop for Windows.
  5. Click “OK”.

Start the VM, and run “mstsc /v:hostname:port” from another box to Remote Desktop into the VM.

What I’ve experienced is that the mouse speed is not synchronized, so it becomes difficult to navigate even when I change the mouse sensitivity to be approximately the same. I also haven’t figure out how to have authentication with this method.

Another possible way I’ve yet to succeed is to use Ubuntu’s built in vnc server.