title: JUnit&Mockito: how to inject field values to Spring component?
body: <p>I'm trying to test Spring <code>@Repository</code> component but first I've to inject table name to let this work properly.</p>
  
  <p>Here's what I made. It's simple DAO:</p>
  
  <pre><code>@Repository
  @Transactional
  public class AccountDAO {
  
      @Autowired
      private JdbcTemplate jdbcTemplate;
  
      private String table = "accounts"; &lt;-- I need to inject this value from tests
      ...
  }
  </code></pre>
  
  <p>the unit test:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration("classpath:spring-web-servlet.xml")
  @Transactional
  public class AccountDaoTest {
  
      @Autowired
      private AccountDAO accountDAO;
  
      @Before
      public void init() {
          accountDAO = Mockito.spy(accountDAO);
          ReflectionTestUtils.setField(accountDAO, "table", "accounts_test");
      }
  
      ...
  }
  </code></pre>
  
  <p>The problem is that <code>ReflectionTestUtils</code> ignores field assignment and <code>accountDAO</code> still uses <code>accounts</code> table name value instead of <code>accounts_test</code>.</p>
  
  <p>How can I round this problem?</p>