How to retrieve local object value using powermockito

Skip to first unread message

Srishti Tiwari

May 17, 2021, 5:51:54 AM5/17/21
to mockito

I am new to unit testing and started writing unit test for one of our legacy project, the issue with the project is we have long methods using local variables and object for manipulation. I have come across powermockito which i hope should help me in testing the state of local variables.

The issue what i am facing currently is there is a method which takes input as obj1 and a string param uuid within the method we are assigning the value of uuid to locally created object using setters; prior to converting the obj1 to newObj. I need to verify the newly created object value as part of code coverage and testing.

Below are my code snippets, let me know where i am going wrong in my Unit test case:

public Obj1 processing(Obj1 obj1, String uuid) { 
NewObj newObj = objConverter .convertDtoToNewObj(obj1); 
  if (StringUtils.isNotEmpty(uuid)) { 

Test Snippet :

@Test public void processingTest() throws Exception { 
 NewObj newObj = Mockito.mock(NewObj.class); 
 Obj1 Obj1 = Mockito.mock(Obj1.class); Obj1 Obj1 = new Obj1(); 
  // Skipping the steps for assinging value to Obj1 
//Below is the place where i am going wrong, not sure on how to return newObj uuid set from the method 
 Mockito.when(Test.processing(Obj1, UUID.randomUUID().toString())).thenReturn(Obj1); }
Reply all
Reply to author
0 new messages