Expand my Community achievements bar.

SOLVED

How to write the JUnit

Avatar

Level 7

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

@inject
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;}

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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...

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



Arun Patidar

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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...

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



Arun Patidar