Unit testing component bean which calls this.getWcmMode().isDisabled() | Community
Skip to main content
Level 4
Jan 12, 2018 9:29 AM UTC
Solved

Unit testing component bean which calls this.getWcmMode().isDisabled()

Hi All,

I am trying to unit test an AEM component bean using JUnit 4.

The component bean extends AbstractSightlyComponentBean and it calls this.getWcmMode().isDisabled().

When unit testing, this.getWcmMode() is returning null.

Does anyone know how I can set or mock WCM Mode within JUnit 4 testing enviromnnent?

Thanks your your time,

Best regards,

Robert

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Peter_Puzanovs
Peter_PuzanovsAccepted solution
New Participant
Jan 15, 2018 1:36 PM UTC

Hi Robert,

Overall answer:

You should use Mockito to Mockito.mock(YourComponentBean.class);

Then tell your mocito$mocked bean which mode to return on getWcmMode method call.

If you could send us YourComponentBean and explain where AbstractSightlyComponentBean is coming from, more concrete answer could be provided.

Regards,

Peter

1 reply

Peter_Puzanovs
Peter_PuzanovsAccepted solution
New Participant
Jan 15, 2018 1:36 PM UTC

Hi Robert,

Overall answer:

You should use Mockito to Mockito.mock(YourComponentBean.class);

Then tell your mocito$mocked bean which mode to return on getWcmMode method call.

If you could send us YourComponentBean and explain where AbstractSightlyComponentBean is coming from, more concrete answer could be provided.

Regards,

Peter

Translate