Junit5 AEM Mocks throws NPE due to PageManager being null

Description

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.

Activity

Show:
David Gonzalez
October 24, 2019, 1:16 PM

@Stefan -

  1. My unit test files are importing the junit5.AemContext - initially i expected this to be the problem.

  2. 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?

https://gist.github.com/davidjgonzalez/acab42b7357aac4fa4b83b28bfc6ffb5

 

 

Stefan Seifert
October 24, 2019, 5:57 PM

everything in the gist looks fine

can you set brakepoints in this classes to see what goes wrong:

  1. https://github.com/wcm-io/wcm-io-testing/blob/develop/aem-mock/core/src/main/java/io/wcm/testing/mock/aem/context/AemContextImpl.java#L70
    should register the MockAemAdapterFactory

  2. https://github.com/wcm-io/wcm-io-testing/blob/d8582ab65a375dfa9fd06eb71ea0937d5e3c630c/aem-mock/core/src/main/java/io/wcm/testing/mock/aem/MockAemAdapterFactory.java#L84
    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

David Gonzalez
October 25, 2019, 8:43 PM

@Stefan Seigert .. None of those lines are invoked. It seems like the AemContextExtension isn’t being invoked either…

I pushed the branch up to:

 

David Gonzalez
October 28, 2019, 2:11 PM

@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.

Stefan Seifert
October 28, 2019, 2:26 PM

alright - good to hear it's solved

Done

Assignee

Unassigned

Reporter

David Gonzalez

Labels

None

Components

Affects versions

Priority

Major
Configure