Skip to main content
Level 2
December 8, 2022
Solved

Junit Mock for value map properties of Long type

I am trying to write jnuit test classes for my class and attaching the screenshot below from debug view. Photoserialvalue is coming as null in my main class

Below is how i am trying to mock it.

 

Any leads on what is that I am missing? I am getting all other objects mocked and just this variable is coming as null. It is a Long type variable.

Any leads would be much appreciated.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
P_V_NairAccepted solution
Level 2
December 9, 2022

Was able to fix the issue. Removed the null initialisation for the variable photoSerialValue and then it was picking the value from the mocked class.

5 replies

aanchal-sikka
Community Advisor
Community Advisor
December 8, 2022

Hello @p_v_nair 

 

When you are trying to mock, its defined as 

 

But, when validating, it is:

Could we please try by using the same get() method in both places (Long.class as second param) ? 

Translate
Aanchal Sikka
P_V_NairAuthor
Level 2
December 8, 2022

@aanchal-sikka  You meant to try this right?

Still it is coming as null

Translate
Adobe Employee
December 9, 2022

hi @p_v_nair ,

 

As you have mentioned long.class then you don't to typecast.

 

photoSerialValue = properties.get(Constant.PHOTO_SERIAL_ID, Long.class);

 

Hope this helps.

 

Thanks,

Nikita Garg

 

 

 

 

Translate
P_V_NairAuthor
Level 2
December 8, 2022

I tried with another property of the same value map , but it is string value and it is populated with the right value. Only for this long property, it is coming as null

 

Translate
P_V_NairAuthorAccepted solution
Level 2
December 9, 2022

Was able to fix the issue. Removed the null initialisation for the variable photoSerialValue and then it was picking the value from the mocked class.

Translate