I'm starting to play with some test-driven development practises, and I'm having issues deciding whether, and if so how, to test this bit of my code.
I've got a class AbstractServer which contains a ServerSocketFactory and ServerSocket:
public abstract class AbstractServer extends Thread {
...SNIP...
//ServerSocket and factory.
private ServerSocket ss;
private ServerSocketFactory ssf;
public AbstractServer ( int _port ) {
this.port = _port;
try {
ssf = ServerSocketFactory.getDefault();
ss = ssf.createServerSocket(port);
} catch (IOException e) {
// Couldn't create ServerSocket, die.
System.exit(1);
}
}
... SNIP ...
Both the ServerSocket and the ServerSocketFactory are private, and are never exposed outside of this class.
My questions:
Should I be creating tests to check whether or not I actually create the
ServerSocketand theServerSocketFactory? They'reprivateand not exposed from within the class - how much testing is too much testing?If testing their creation is something I should do, how do I test private, non-exposed (no getter methods) object creation from outside the class? My naive (read: untested) assumption is that I'd create a test class
extendingAbstractServer; I'd then have to make the things I'm testing forprotected, which semi-defeats the purpose of making themprivateto begin with.