I\'m writing an end-to-end test that my Java program releases all of its resources - threads, server sockets, client sockets. It\'s a library, so releasing resources by exit
I haven't tried it myself, but the JavaSpecialists newsletter presents a similar problem:
http://www.javaspecialists.eu/archive/Issue169.html
At the bottom, he describes an approach using AspectJ. You could probably put the pointcut around the constructor that creates the socket, and have code that registers socket creation there.