Hi,
Working with test certificates is one thing (totally feasible), however working with invalid certificates is another (much worst) thing that you should avoid at all cost. Hostname verification is hardcoded in libraries/protocols themselves, there's no alternative because any such workaround would be a security hole.
If you are on a test instance, you should generate yourself some self-signed certificates. You'll have to tell Java to trust them, but at least they will be valid from a security standpoint.
Best regards,
Nicolas