'Get a value of a local variable from a void function using mockito

I have a method like below:

public void process {
   ArrayList<String> data = new ArrayList<>();
   ...
   ...
}

data is a local variable, the value of which I want to access after calling myObject.process() inside the test function. Is there any way I can do that?



Solution 1:[1]

Mockito cannot access a local variable which is created by your code. The only way to test the code is to check whether something else is being effected by that variable and verify that change. This answer should help you out.
https://stackoverflow.com/a/30188745/17052051

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ranjit C