I'm attempting to figure out how to test a method written in my LoggingRestService class. I'd like to verify that my (external) error method produces the correct log entry in this logger.
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingRestService.class);
@POST
@Path("debug")
@ApiOperation(value = "Writes js error message log. (not secured)")
@ApiResponse(code = 200, message = "Message logged")
public void getUserList(@ApiParam(value = "Js debug message.")
String message) {
ConverterUtils.error(LOGGER, message, null);
}
}
Here is ConverterUtils error method:
public static void error(Logger logger, String mess, Exception ex) {
Class<?> aClass = logger.getClass();
try {
Method method = aClass.getMethod("error", String.class, Throwable.class);
method.invoke(logger, mess, ex);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
LOGGER.error("get logger error", e);
}
}
I've never used mockito but I am somewhat familiar with the concept of mocking classes..still I'm a little boggled. I was not given much direction for testing and attempting to be self sufficient is slowly rotting my confidence. Thanks a bunch.