AEM-junit for text component using textmodel | Community
Skip to main content
New Participant
February 22, 2022
Solved

AEM-junit for text component using textmodel

  • February 22, 2022
  • 3 replies
  • 1496 views

I am building  project with Junit for Text

WHEN I return plain text (Lorem ipsum dolor sit amet.) for getText.

THEN I should see “Lorem ipsum dolor sit amet.” returned for getText().

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by milind_bachani

Hey @vinuu123 ,

 

Here is a quick reference : unit-testing-aem for Junit testing.

 

For your usecase, you need to mock the model under the test and command the Junits as and when required like:
If someone is calling a getter from mockModel you can use :

when(mockModel.getSomeProperty).thenReturn("Lorem Ipsum...");

 

Here's a tutorial on how you use asserting : junit-assert-tutorial .

 

Please feel free to reach out if that doesnt help. Thanks.

3 replies

arunpatidar
New Participant
February 22, 2022
Arun Patidar
milind_bachani
milind_bachaniAccepted solution
Employee
February 22, 2022

Hey @vinuu123 ,

 

Here is a quick reference : unit-testing-aem for Junit testing.

 

For your usecase, you need to mock the model under the test and command the Junits as and when required like:
If someone is calling a getter from mockModel you can use :

when(mockModel.getSomeProperty).thenReturn("Lorem Ipsum...");

 

Here's a tutorial on how you use asserting : junit-assert-tutorial .

 

Please feel free to reach out if that doesnt help. Thanks.

Jineet_Vora
New Participant
February 22, 2022

Hi @vinuu123,

I believe you are looking for Mockito's - when thenReturn function. You will have to use set as below:

when(textModelObject.getText()).thenReturn("Lorem ipsum dolor sit amet.");

with this you will be able to check using assertEquals as below:

assertEquals("Lorem ipsum dolor sit amet.",object.getText());


Hope this helps!
Jineet

vinuu123Author
New Participant
February 23, 2022

what is object here(object.getText()) and what is textmodelobject