Hello, I am having a problem where the resource is not injected into the Sling Model constructor during a test, I was able to inject mock services into the constructor, but unable to with the resource object (I do not wish to inject the Resource via Sling Model Annotations, as I want to use the constructor only):
WebData Sling Model:
@Model(adaptables = {SlingHttpServletRequest.class, Resource.class},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class WebData {
@inject
public WebData(Resource resource) {
}
}
SlingModel Unit Test:
@test
public void itShouldInject() {
Resource resource = context.resourceResolver().getResource("/content/my-site/page/jcr:content/par/web");
undertest = resource.adaptTo(WebData.class);
}