Hi,
during one of our tests we came to a point, where we wanted to adapt a
component that is using "wcmmode" and is adaptable from a Resource and a
SlingHttpRequest. While the later one works fine in our unit test, it
was not possible to adapt the component from a Resource as the
AEMObjectInjector needs a Request to adapt to WCMMode (and other
classes):
https://github.com/wcm-io/wcm-io-sling/blob/develop/models/src/main/java/io/wcm/sling/models/injectors/impl/AemObjectInjector.java#L104
We found the solution in MockSlingExtensions:
MockSlingExtensions.setRequestContext(context, context.request());
My proposal:
I can't really see a situation, where I would use the AemContext and a
set request context does any harm. So I think this pitfall could be
removed by automatically setting the RequestContext.
Cheers