I want to create a class which has only static functions. I also need to initialize certain variables before the class functions get called. Since I am using only static functions, I cannot use a constructor to do it.
So now when I try to set the SSLContext in the following manner I get an error: Unhandled exception type NoSuchAlgorithmException. How should I approach this? I can put a try catch in the setContext function and set the value to null, incase of an error. And if I notice somewhere that the context variable is null, I throw an error from one of my functions.
public class HTTPRequest {
private static SSLContext context = setContext();
private static SSLContext setContext() throws NoSuchAlgorithmException {
return SSLContext.getInstance("TLSv1.2");
}
}
Specifically how would this effect while writing JUnit test cases:
Say hypothetically, while testing I want to pass my mocking algorithm? Usually I would set these values through the constructor. In the following way: HTTPRequest(String algo) { context =SSLContext.getInstance(algo); }
But now I won't be able to do that right?