Common cause for NullPionterException or Null value in Junit test case for sling model in aem | Community
Skip to main content
Umesh_Thakur
Community Advisor
Community Advisor
March 16, 2022

Common cause for NullPionterException or Null value in Junit test case for sling model in aem

  • March 16, 2022
  • 1 reply
  • 1625 views

Dear Members,

I came across with above problem while debugging some junit test cases for sling model.

 Exctract:

"Let say your sling model is adaptables to sling Resource and in your test class you are trying to get the instance of your respective Object by adapting request of aemContext. In this case you will end up with NullPointerException."

 

Details are below:

https://aemhelper.blogspot.com/2022/03/common-cause-of-nullpionterexception-or.html

 

Please provide your feedback, if any to make it more helpful.

 

Thanks

Umesh Thakur

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
March 17, 2022

You can add, addModelsForPackage, as this is another common null returned from adapt.

aemContext.addModelsForPackage("com.sourcedcode.core.models.utils");