@Test
 public void withScopedProxy() throws IOException, ClassNotFoundException {
   AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
   ctx.register(ComponentScanWithScopedProxy.class);
   ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
   ctx.refresh();
   // should cast to the interface
   FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
   // should be dynamic proxy
   assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
   // test serializability
   assertThat(bean.foo(1), equalTo("bar"));
   FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
   assertThat(deserialized, notNullValue());
   assertThat(deserialized.foo(1), equalTo("bar"));
 }
  private void aspectIsApplied(ApplicationContext ctx) {
    FooService fooService = ctx.getBean(FooService.class);
    ServiceInvocationCounter counter = ctx.getBean(ServiceInvocationCounter.class);

    assertEquals(0, counter.getCount());

    assertTrue(fooService.isInitCalled());
    assertEquals(1, counter.getCount());

    String value = fooService.foo(1);
    assertEquals("bar", value);
    assertEquals(2, counter.getCount());

    fooService.foo(1);
    assertEquals(3, counter.getCount());
  }