Hi
I need to write a Unit Test for an AEM component that uses a service that returns a list of paths based on a Query.
How do I write a Unit Test for such a method.
getBlogItemsForPaths(someService.findPages(filter), resource, blogContext);
the someService returns a list of paths:
public List<String> someService(@Nonnull BlogArticleFilter filter) {
if (filter.getTagList().isEmpty()) {
return Collections.emptyList();
}
final String pathQuery = buildDesendantNodeString(filter.getPathList());
final String tagQuery = buildTagQuery(filter);
final String query = String.format(QUERY, pathQuery, Constants.TemplateType.BLOG_ARTICLE_PAGE.getTemplatePath(), tagQuery);
return resourceResolverUsageService.withServiceUserResourceResolver(ServiceUser.CONTENT_READER, resolver -> {
return StreamUtil.iteratorStream(resolver.findResources(query, Query.JCR_SQL2))
.sorted(Comparator.comparing(this::getDate, Comparator.reverseOrder()))
.map(Resource::getPath)
.filter(s -> !filter.getIgnoreList().contains(s))
.limit(filter.getMaxItems())
.collect(Collectors.toList());
});
}