Unit Test for for SlingServlet
Hi All
I need to write a UnitTest for a doGet method in a Servlet that extends SlingSafeMethodsServlet.
This is the doGet method I need to write the UnitTest for and I am not sure how to mock the resource for it:
@Override
protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws IOException {
final JsonResponse jsonResponse = new JsonResponse(response);
final String title = request.getParameter("title");
final List<APIResult> locations = LocationFinderUtil.getLocationResultStream(request, searchService)
.filter(result -> StringUtils.isNotBlank(title) &&
(StringUtils.containsIgnoreCase(result.getTitle(), title) || StringUtils.containsIgnoreCase(result.getAdditionalAddress(), title)))
.map(APIResult::new)
.collect(Collectors.toList());
jsonResponse.write(locations);
}