I am writing unit test using Mockito but I am still unable to understand how to cover the third party APIs - I have a public API called deleteApplication(String clientId) and a private API called getApplicationObjectId(String clientId)
So inside my private method - I have a code which belongs to library Microsoft Graph SDK - Java and I need to mock it so I have a code coverage for below these two lines -
ApplicationCollectionRequest request = this.graphServiceClient.applications().buildRequest(options);
ApplicationCollectionPage appCollectionPage = request.get();
And...like wise I have this line in my public method - I need to mock this so that I have code coverage for this...
Application application = this.graphServiceClient.applications(appClientObjId)
.buildRequest()
.delete();
Is it possible to mock in these scenarios, if yes what is the best approach? I am using Jacoco for code coverage. Below is my public and private methods.
public boolean deleteApplication(String clientId) {
String appClientObjId = getApplicationObjectId(clientId);
Application application = this.graphServiceClient.applications(appClientObjId)
.buildRequest()
.delete();
return application.appId == null;
}
private String getApplicationObjectId(String clientId) {
String queryTerm = String.format("appId eq '%s'", clientId);
LinkedList<Option> options = new LinkedList<>();
options.add(new QueryOption("$filter", queryTerm));
ApplicationCollectionRequest request = this.graphServiceClient.applications().buildRequest(options);
ApplicationCollectionPage appCollectionPage = request.get();
if (!appCollectionPage.getCurrentPage().isEmpty()) {
return appCollectionPage.getCurrentPage().get(0).id;
}
throw new Exception("Could not find application resource.");
}