title: Can I set value to a member variable during a unit test?
body: <p>Firstly I request to not mark it as duplicate of <a href="https://stackoverflow.com/questions/55282156/can-i-access-member-variable-of-method-of-a-class-under-test">previous question</a>. It was incorrectly marked as duplicate and wrongly answered. Please read the question carefully and respond. Thanks..!!</p>
  
  <p>So I want to access a member variable which has scope only inside the method which is to be tested during unit test of my controller class. So the code of my class to be tested looks like below(generic code as cannot post code online).</p>
  
  <pre><code>@Controller
  public class testController(){
  
  @Autowired
  private Dependency dependency;
  
  @RequestMapping("/SearchProject)
  public String systemUnderTest(){
  // some logic
  Integer[] totalrecords = new Integer[1];
  List&lt;SomeObject&gt; aList = dependency.someMethod(.,.,totalRecords,.,.);
  //some logic
  int value = Math.ceil(totalrecords[0]/CONSTANT_VALUE);
  return "string";
  
  }
  </code></pre>
  
  <p>What is happening is totalRecords[0] is set to a value inside someMethod() which I am already mocking in my test class so it remains null during my unit test run.</p>
  
  <p>Is there any way I can access and set this 'totalRecords[0]' variable during my test ? Let me know if any more details are needed.</p>