title: Mocking CGLIB enhanced objects
body: <p>Is it true that mockito can't mock objects that were already enhanced by CGLIB?</p>
  
  <pre><code>public class Article {
  
       @Autowired
       private dbRequestHandler
  
       @Autowired
       private filesystemRequestHandler
  
       @Transactional
       public ArticleDTO getArticleContents() {
  
           //extractText() and then save the data in DTO
           //extractImages() and then save the data in DTO
           // some other calls to other databases to save data in dto
  
         return articleDTO;
  
       }
       public void extractText() {
  
          //call to DB
  
     }
  
     public void extractImages() {
  
          // call to file system
  
     }
  }
  
  
  public class IntegrationTest {
  
    @Autowired
    private Article article;
  
    //setup method {
  
    articleMock = Mockito.spy(article);
  
    doNothing().when(articleMock).extractImages();
   }
  }
  </code></pre>
  
  <p>In the above example when it comes to <code>doNothing().when(articleMock).extractImages();</code> it actually calls the real function. On a closer look articleMock gets enhanced two times. One cause of <code>autowiring</code> and second time cause of <code>spying</code>. </p>
  
  <p>If I can't spy on enhaced objects, then how can I test the <code>getArticle()</code> method in my Integration test, so that I can verify a proper DTO is returned.</p>
  
  <p>Note : I actually don't want to test the method which does filesystem calls. just the DB ones. thats why I need to test the <code>getArticle</code> method.</p>