Expand my Community achievements bar.

SOLVED

Junit Mock for value map properties of Long type

Avatar

Adobe Champion

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

P_V_Nair_0-1670530575249.png

Below is how i am trying to mock it.

P_V_Nair_0-1670531257197.png

 

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.

1 Accepted Solution

Avatar

Correct answer by
Adobe Champion

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.

View solution in original post

5 Replies

Avatar

Community Advisor

Hello @P_V_Nair 

 

When you are trying to mock, its defined as 

aanchalsikka_0-1670531839639.png

 

But, when validating, it is:

aanchalsikka_2-1670531894226.png

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


Aanchal Sikka

Avatar

Employee Advisor

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

 

 

 

 

Avatar

Adobe Champion

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

P_V_Nair_0-1670532284176.png

 

Avatar

Correct answer by
Adobe Champion

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.