I started switching over to Junit 5 (bulk of my tests suites still use Junit4 + AEM Mocks) and noticed an issue where when I interact with the currentResource, i get an NPE because the PageManager object is null.
It appears that the AEM Mocks resourceResolver object cannot be adapted to the PageManager, thus null.
I switched the code to use Junit4 + Junit4 Mocks and everything is fine, so i assume this is a bug somewhere in AEM mocks. AFIAK I'm using the latest of everything (see below).
Here are my dep versions... do note i use both Junit and Junit5 in this project; however this test suite (test file) is a Junit5 test file.
My unit test files are importing the junit5.AemContext - initially i expected this to be the problem.
My dependencies appear to be using 2.7.0 and i dont think i am missing any per your wcm.io docs link (has both aem-mocks and sling mocks)
I’ve added the complete test file, test output and dependencies here. Im not seeing where the gap is.
I noticed there is no “junit5” package in the stacktrace packages - would this indicate that its resolving to junit4 implementations somewhere?
everything in the gist looks fine
can you set brakepoints in this classes to see what goes wrong:
should register the MockAemAdapterFactory
where it should adapt from resource resolver to page manager
if this doe not help perhaps you can give me a link to a branch on https://github.com/Adobe-Marketing-Cloud/asset-share-commons to reproduce the problem myself
@Stefan Seigert .. None of those lines are invoked. It seems like the AemContextExtension isn’t being invoked either…
I pushed the branch up to:
@Stefan Seifert - I was missing the correct Jupiter dependencies and maven surefire config/version.
I got the Junt5 tests to run, and included jupiter-vintage for my Junit4 tests, but now im getting 50+ errors on my Junit4 tests … one error I noticed was in a test I was setting current resource to “/content/resource-name-had-a-type” .. it turned out that test passed w/ junit4 because the test was testing for missing properties (which the empty resource, of course, didn't haveE), but when i ran it with jupiter-vintage, the test failed with an error, which i found strange. I didnt look into it to much but wasnt expecting my existing Junit4 tests that pass with the Junit4 runner to fail under the jupiter-vintage runner.
Anyhow, long story short - you can closet this issue since i hadnt configured my project properly to run w the jupiter-engine/jupiter-vintage and manen-surefire plugin.
alright - good to hear it's solved