title: How to test Spring's declarative caching support on Spring Data repositories?
body: <p>I have developed a Spring Data repository, <code>MemberRepository</code> interface, that extends <code>org.springframework.data.jpa.repository.JpaRepository</code>. <code>MemberRepository</code> has a method: </p>
  
  <pre><code>@Cacheable(CacheConfiguration.DATABASE_CACHE_NAME)
  Member findByEmail(String email);
  </code></pre>
  
  <p>The result is cached by Spring cache abstraction (backed by a <code>ConcurrentMapCache</code>).</p>
  
  <p>The issue I have is that I want to write an integration test (against hsqldb) that asserts that the result is <strong>retrieved from db the first time</strong> and <strong>from cache the second time</strong>.</p>
  
  <p>I initially thought of mocking the jpa infrastructure (entity manager, etc.) and somehow assert that the entity manager is not called the second time but it seems too hard/cumbersome (see <a href="https://stackoverflow.com/a/23442457/536299">https://stackoverflow.com/a/23442457/536299</a>).</p>
  
  <p>Can someone then please provide advice as to how to test the caching behavior of a Spring Data Repository method annotated with <code>@Cacheable</code>?</p>