title: Aspect testing - can't get right value of aspects bean's property
body: <p><strong>Aspect</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Configurable
  @Aspect
  public class FilmCounter {
  
      private Map&lt;Integer, Integer&gt; filmCounts = 
              new HashMap&lt;Integer, Integer&gt;();
  
      @Pointcut(
          "execution(* soundsystem.CompactDisc.play(int)) " +
          "&amp;&amp; args(filmNumber)" )
      public void filmPlayed(int filmNumber) {}
  
      @Before("filmPlayed(filmNumber)")
      public void countFilm(int filmNumber){      
          int currentCount = getPlayCount(filmNumber);
          filmCounts.put(filmNumber, currentCount + 1);
  
          System.out.println("filmNumber " + filmNumber + " contains in ? " + filmCounts.containsKey(filmNumber) + " then filmCount = " + filmCounts.get(filmNumber));
  
      }
  
      public int getPlayCount(int filmNumber){
          //System.out.println("filmNumber " + filmNumber + " contains in ? " + filmCounts.containsKey(filmNumber) + "");
  
          return filmCounts.containsKey(filmNumber)
                  ? filmCounts.get(filmNumber) : 0;
  
      }
  }
  </code></pre>
  
  <p><strong>Configuration class</strong></p>
  
  <p>Under AspectJ runtime lib so not needed <code>@EnableAspectJAutoProxy</code> annotation</p>
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  public class FilmCounterConfig {
  
      @Bean
      public CompactDisc filmDisk(){
          FilmDisc cd = new FilmDisc();
          cd.setTitle("1981's Melody Films");
          cd.setArtist("Kishor Kumar");
          List&lt;String&gt; films = new ArrayList&lt;String&gt;();
          films.add("Sanam Teri Kasam");
          films.add("Akhari Rasta");
          films.add("Hum Apke Hai Koun");
          films.add("Dil Hain Ke Manata Nahi");
          films.add("Hum Sath Sath Hain");
          cd.setFilms(films);
  
          return cd;
      }   
  
      @Bean
      public FilmCounter filmCounter(){
          return new FilmCounter();
      }
  }
  </code></pre>
  
  <p><strong>Test class</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes=FilmCounterConfig.class)
  public class FilmCounterTest {
  
      @Rule
      public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); 
  
      @Autowired
      private CompactDisc cd;
  
      @Autowired
      private FilmCounter counter;
  
      @Test
      public void testFilmCounter(){
  
          cd.play(1); System.out.println("counter.getPlayCount(1) = " + counter.getPlayCount(1));
          cd.play(2);
          cd.play(3);
          cd.play(3);
          cd.play(3);
          cd.play(3);     
  
          /*assertEquals(1, counter.getPlayCount(1));
          assertEquals(1, counter.getPlayCount(2));
          assertEquals(4, counter.getPlayCount(3));
          */
  
          System.out.println("Film 1 = " + counter.getPlayCount(1));
          System.out.println("Film 2 = " + counter.getPlayCount(2));
          System.out.println("Film 3 = " + counter.getPlayCount(3));
  
      }
  
  }
  </code></pre>
  
  <p>When running the above test case I get the following output:</p>
  
  <p><a href="https://i.stack.imgur.com/xj9ol.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xj9ol.png" alt="Console log"></a></p>
  
  <p>The image shows that the console log output for the first method call <code>cd.play(2);</code> looks OK, but after invoking <code>System.out.println("Film 1 = " + counter.getPlayCount(1));</code> it shows the wrong result (it should display "4" but displays "0").</p>