Junit Mock for value map properties of Long type | Community
Skip to main content
New Participant
December 8, 2022
Solved

Junit Mock for value map properties of Long type

  • December 8, 2022
  • 3 replies
  • 2984 views

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.
Best answer by P_V_Nair

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.

3 replies

P_V_NairAuthorAccepted solution
New Participant
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.

P_V_NairAuthor
New Participant
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

 

aanchal-sikka
New Participant
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) ? 

Aanchal Sikka
P_V_NairAuthor
New Participant
December 8, 2022

@aanchal-sikka  You meant to try this right?

Still it is coming as null

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