Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Issue regarding Junit testing of Sightly components

Avatar

Former Community Member

Hello,

We are trying to Unit test Controllers of our Sightly components. 

We are using PowerMock, Mokito and Junit.

Our Controller class extends WCMuse class as our component is in sightly. We tried to do Mock the WCMuse by @Mock annotation. 

But the issue is we get NullPointerException when we try to "getProperties()". This getProperties() is a method in WCMuse class and internally uses the javax.script.Bindings class to fetch the properties.Bindings is private in the WCMuse class. 

As per the  errorstack, this Bindings object is null. So getproperties() is null.Hence the error. As Bindings is private so we are not able to mock it.

Let me know if there is any other way to do it ?Can WCMuse class be mocked?

Please let me know if someone has any successful implementation of JUnit testing of WCMuse.class.

Let me know if you need any other details.

Thanks in advance.

 

Suneel.

1 Accepted Solution

Avatar

Correct answer by
Employee

You need to use something like JMockito here.

View solution in original post

1 Reply

Avatar

Correct answer by
Employee

You need to use something like JMockito here.