title: Unit testing: Call @PostConstruct after defining mocked behaviour
body: <p>I have two classes:</p>
  
  <pre><code>public MyService {
      @Autowired
      private MyDao myDao;     
      private List&lt;Items&gt; list; 
  
      @PostConstruct
      private void init(){
           list = myDao.getItems(); 
      }
  }
  </code></pre>
  
  <p>Now I'm wanting to involve <code>MyService</code> in a unit test, and so I'll mock the behaviour <code>MyDao</code>. </p>
  
  <p>XML:</p>
  
  <pre><code>&lt;bean class = "com.package.MyService"&gt; 
  &lt;bean  class="org.mockito.Mockito" factory-method="mock"&gt; 
       &lt;constructor-arg value="com.package.MyDao"/&gt;
  &lt;/bean&gt;
  
  &lt;util:list id="responseItems" value-type="com.package.Item"&gt;
      &lt;ref bean="item1"/&gt;
      &lt;ref bean="item2"/&gt;
  &lt;/util:list&gt;
  </code></pre>
  
  <p>Unit Test:</p>
  
  <pre><code>@ContextConfiguration("/test-context.xml")
  @RunWith(SpringJUnit4ClassRunner.class)
  public class MyServiceTest {
  
      @Autowired 
      MyService myService
  
      @Autowired 
      MyDao myDao;
  
      @Resource
      @Qualifier("responseItems")
      private List&lt;Item&gt; responseItems; 
  
      @Before
      public void setupTests() {
          reset(myDao); 
          when(myDao.getItems()).thenReturn(responseItems); 
      }
  }
  </code></pre>
  
  <p>The problem with this is that the <code>MyService</code> bean is created, and its @PostConstruct bean called before the mocked behaviour is defined. </p>
  
  <p>How can I either define the mocked behaviour in the XML or delay <code>@PostConstruct</code> until after the unit test setup?</p>