I have lazy singleton MongoConnection class with a static method which returns MongoClient instance on MongoConnection.getClient():
public class MongoConnection {
private static MongoClient mongoclient;
private MongoConnection() {
}
public static MongoClient getClient() {
if (mongoclient == null) {
// code to initialize MongoClient
}
return mongoclient;
}
}
How do I use PowerMockito to mock MongoConnection singleton and test getClient method.
I don't have choice over singleton because there will be single instance of MongoClient across the application (as per MongoDB documentation).
Note: i don't want to connect to actual DB in test because it will be integration test rather than JUnit; I just want to make sure if MongoClient is initialized with expected parameters. How to do I achieve this with PockerMockito?
Thank you