title: Spring MVC Controller Unit Testing : How do I set private instance boolean field?
body: <p>I have a Spring MVC REST controller class that has a private instance boolean field injected via @Value , </p>
  
  <pre><code>@Value("${...property_name..}")
  private boolean isFileIndex;
  </code></pre>
  
  <p>Now to unit test this controller class, I need to inject this boolean. </p>
  
  <p>How do I do that with <code>MockMvc</code>?</p>
  
  <p>I can use reflection but <code>MockMvc</code> instance doesn't give me underlying controller instance to pass to <code>Field.setBoolean()</code> method. </p>
  
  <p>Test class runs without mocking or injecting this dependency with value always being <code>false</code>. I need to set it to <code>true</code> to cover all paths. </p>
  
  <p>Set up looks like below. </p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @WebMvcTest(value=Controller.class,secure=false)
  public class IndexControllerTest {
  
      @Autowired
      private MockMvc mockMvc;
   ....
  }
  </code></pre>