I am writing Junits to test my logs. I am using LogCaptor. I have attached my actual method and my testcases along with pom.xml.
This is my method where i have logs defined.
@Override
public ApplicationResponse createApplication (final String serviceId, final String appId) throws KMSException {
log.debug("Entering createApplication");
try {
final Application application =
applicationOperations.createApplication(appId, serviceId);
return applicationResponse(application);
}
catch (KMSCommonException exception) {
throw new KMSInternalServerErrorException("Not able to create application", exception);
}
}
This is my test method to test Loggers :
@Test
public void testCreateApplicationLogger () throws KMSException {
String expectedInfoMessage = "Entering createApplication";
LogCaptor logCaptor = LogCaptor.forClass(Test.class);
adminAPIApplicationOpService.createApplication(TEST_SERVICE, TEST_APP + 1);
assertTrue( logCaptor.getInfoLogs().contains(expectedInfoMessage));
}