Expand my Community achievements bar.

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

Avatar

Community Advisor

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

1 Reply

Avatar

Community Advisor

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

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