Archive for March, 2009
Referencing Springerlink with BibTex
by Mex on Mar.31, 2009, under Technology
I have been writing a couple of reports recently and took the time to start learning LaTeX and BibTex (through Lyx and JabRef admittedly). When dealing with references some resources like the ACM provide BibTex citations which you can copy and paste into your database, other’s like SpringerLink unfortunatly don’t. This led to me descovering a tool from University of Sydney which automaticly generates BibTex records for SpringerLink for you. They even provide a bookmarklet to make things even easier.
Window 7 on the NC10
by Mex on Mar.18, 2009, under Technology
I recently did a review of my new NC10 netbook, and though it’s a lovely device I would prefer to run something a bit more up to date on it than XP. With the 1 Gig or ram it comes with and the modest CPU Vista was out of the question, but I have geared good things about people getting the Windows 7 beta running on this class of device, so I thought it would be worth giving it a go.
Preparation
The NC10 comes set up with three partitions, the first is a hidden area where the recovery software is installed, followed by a NTFS partition which Windows XP is installed on and a second NTFS partition which is used to store backups with Samsung’s backup software. To make room for Windows 7 I resized the backup partition with a live USB Linux distro called GParted. Because I was installing Windows 7 onto a new device I wasn’t worried about taking a backup, but you should take a backup before doing this normally.
One thing of note is that I made the partition almost the same size and the data on it, and now I am continually getting popups in Windows saying the drive is very full, so it’s prob worth leaving about 25% extra free space in the backup partition when you shrink it.
Installation
The NC10 like other devices in it’s class does not have a CD drive and I don’t own a USB CD drive, so I had to go with installing it off of a USB stick. This was much easier than I expected thanks to a great walk through I found over at dotnetwizard.net. I have heard people saying how much quicker Windows 7 installs that Vista, but it didn’t feel that fast to me.
Problems
I could not get Windows7 on the NC10 to connect to my wifi connection, but this seems to be a problem with our wifi as aposed to the NC10 as it works everywhere else. The Ethernet on the other hand did not work as there are no Windows 7 drivers for this device on Windows Update. The Windows Vista driver from Marvell’s worked fine however.
The other main issue is the reduced battery life, under Windows XP doing casual web browsing etc. I can get almost 6 hours before I need to charge, under Windows 7 it is closer to 4.
The good bits.
The new Areo effects work well, and only stutter under very high load. In-fact other than slightly higher memory usage running Windows 7 doesn’t feel any worse than running Windows XP, and this can easily be remedied by upgrading the memory from 1Gb to 2Gb.
Finally
I think I am going to continue using Windows 7 on the NC10, unless I know I am goign to have a very long day away from the charger. I would like to thank Ade Miller for his excelent blog post which really helped me in setting up Windows 7 on my NC10.
Unit testing private methods in Java.
by Mex on Mar.15, 2009, under Technology
Unit tests are both the saviour and ultimate bane of modern java programmers. Very few people would argue that they are a bad idea, and that they improve the quality of code but for those new to writing unit tests are often lost on where to start. In this post I am going to talk about unit testing private methods, and what is good and bad about doing so.
Some Theory.
In the example below ClassWithPrivateMethod contains the private method someMethod which we want to test. To get access to this method for testing we could make it public/protected; but that would make the classes interface ugly, and give people access to functions that could break the working of the class. We could put the test case inside the class being tested, but this quickly becomes messy. Ideally we want the method to remain private but be accessed from another class. It turns out that private methods are not private, as much as books on Java will tell you they are. Using reflection it is possible to execute private methods as if they were public.
public class ClassWithPrivateMethod { private void someMethod(String param) { System.out.println(param + " World"); } }
To call a method with reflection we first need a reference to the method. This is normaly done with Reflection.getMethod, however because the method we want to access is not public we have to use Reflection.getDeclaredMethod. This gives us a handle on the method, but it is unusable because the method is still private. Calling setAccessible(true) on this method object lets us invoke it. The method can now be called via reflection the same way a public method would be. Bellow is a clearer example of a test that simply invokes the private method.
public class Test { @Test public void test() { Method methodToTest = classWithPrivateMethod.getClass(). getDeclaredMethod("someMethod", String.class); methodToTest.setAccessible(true); methodToTest.invoke(IntancetoInvokeOn, "hello"); } }
This technique can be further extrapolated to testing methods which rely one some state of the object which is difficult to achieve in a normal unit test.
public class ClassWithPrivateMethodandFields { private int x,y; private boolean isPair() { return x==y; } }
public class Test { @Test public void test() { Method methodToTest = classWithPrivateMethod.getClass(). getDeclaredMethod("someMethod", String.class); methodToTest.setAccessible(true); Field x = classWithPrivateMethod.getClass() .getDeclaredField("x"); x.setAccessible(true); Field y = classWithPrivateMethod.getClass() .getDeclaredField("y"); y.setAccessible(true); methodToTest.invoke(IntancetoInvokeOn, "hello"); } }
Finally
This is a powerful tool for testing, but over use can highlight the fact that your interface is not as clean as it could be. I hope this is helpful to people and if you have any ideas or comments please leave them below.
Pipex / Tiscali Update
by Mex on Mar.14, 2009, under Technology
I returned home this weekend to find more letters from Pipex, asking me for payment. The current Outstanding balance is now £56.61, and a bar on our outgoing call facility.
This would be all very good but we have never had a phone line with Pipex, and so our outgoing calls work just fine. It has become clear that calling Pipex will not achieve any thing on this matter so I am going to try snail mail and see if we get any further. I will post with any updates we have.
On another note, when logging into Pipex today i got a nice message saying their security cetificate is invalid, smooth Pipex, smooth.


