How to write the JUnit | Community
Skip to main content
Level 6
Nov 25, 2021 10:06 AM UTC
Solved

How to write the JUnit

For the below code I am unable to write the JUnit for @Postconstruct init()

 

But for text JUNIT is working fine via JSON. Need help

@586265 private Page currentPage; @ValueMapValue Private String text; private String pageTitle; @PostConstruct protected void init() { if(!(currentPage.getName().equalsIgnoreCase("Product") || currentPage.getTemplate.getPath.equals("/conf/we-retail/settings/wcm/templates/hero"))) { text=""; } } public void getText() { return text;}

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Nov 27, 2021 6:51 PM UTC

Hi,

you don't need to write the junit for initi method. Amke sure you create 2 json one with your template and another with different template to make code coverage 100%

example

https://github.com/arunpatidar02/com.aemlab.junitapp/blob/master/core/src/main/java/com/aemlab/junit/core/models/OverviewModel.java

https://github.com/arunpatidar02/com.aemlab.junitapp/blob/master/core/src/test/java/com/aemlab/junit/core/models/OverviewModelTest.java

Arun Patidar

2 replies

arunpatidar
arunpatidarAccepted solution
New Participant
Nov 27, 2021 6:51 PM UTC

Hi,

you don't need to write the junit for initi method. Amke sure you create 2 json one with your template and another with different template to make code coverage 100%

example

https://github.com/arunpatidar02/com.aemlab.junitapp/blob/master/core/src/main/java/com/aemlab/junit/core/models/OverviewModel.java

https://github.com/arunpatidar02/com.aemlab.junitapp/blob/master/core/src/test/java/com/aemlab/junit/core/models/OverviewModelTest.java

Translate
Arun Patidar
Kiran_Vedantam
New Participant
Nov 25, 2021 2:52 PM UTC