AEM - JUnit @Inject annotation
Hi all,
I’am facing an issue regarding the handling of the @586265 annotation with AEM-Junit test scenario.
Here an example of the issue:
Model Class:
@Model(adaptables = {SlingHttpServletRequest.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class SimpleModel {
@586265
private Resource currentResource;
public Resource getCurrentResource(){
return currentResource;
}
}
Test Class:
@ExtendWith({AemContextExtension.class, MockitoExtension.class})
public class SimpleModelTest{
private AemContext context = new AemContext();
private SimpleModel simpleModel;
@BeforeEach
public void setup() throws Exception {
context.addModelsForClasses(SimpleModel.class);
context.load().json("SimpleModelTest.json", "/content/myproject/us");
}
@2785667
void testResource() {
context.currentResource("/content/myproject/us/jcr:content/simple-component");
simpleModel = context.request().adaptTo(SimpleModel.class);
assertNotNull(simpleModel.getCurrentResource());
}
}
The test fails since simpleModel.getCurrentResource() gives me a null resource.
If I change the @586265 annotation in the SimpleModel class with @SlingObject the test doesn't fail, but I don’t want to change every annotation with SlingObject or the similar one.
Could you help me to solve this issue?
