@SuppressWarnings({"unchecked"})
  @Test
  public void testEventHandlerAdapterIsInitializedAndDestroyedProperly() throws Exception {
    Object result1 =
        testSubject.postProcessBeforeInitialization(new AnnotatedCommandHandler(), "beanName");
    CommandHandler postProcessedBean =
        (CommandHandler) testSubject.postProcessAfterInitialization(result1, "beanName");

    verify(mockCommandBus).subscribe(eq(MyCommand.class.getName()), isA(CommandHandler.class));

    verify(mockCommandBus, never())
        .unsubscribe(eq(MyCommand.class.getName()), isA(CommandHandler.class));

    testSubject.postProcessBeforeDestruction(postProcessedBean, "beanName");

    verify(mockCommandBus).unsubscribe(eq(MyCommand.class.getName()), isA(CommandHandler.class));
  }
  @SuppressWarnings({"unchecked"})
  @Test
  public void testEventHandlerCallsRedirectToAdapter() throws Throwable {
    Object result1 =
        testSubject.postProcessBeforeInitialization(new AnnotatedCommandHandler(), "beanName");
    Object postProcessedBean = testSubject.postProcessAfterInitialization(result1, "beanName");

    assertTrue(Enhancer.isEnhanced(postProcessedBean.getClass()));
    assertTrue(postProcessedBean instanceof CommandHandler);
    assertTrue(postProcessedBean instanceof AnnotatedCommandHandler);

    CommandHandler<MyCommand> commandHandler = (CommandHandler<MyCommand>) postProcessedBean;
    AnnotatedCommandHandler annotatedCommandHandler = (AnnotatedCommandHandler) postProcessedBean;
    CommandMessage<MyCommand> myCommand = GenericCommandMessage.asCommandMessage(new MyCommand());
    commandHandler.handle(myCommand, null);

    assertEquals(1, annotatedCommandHandler.getInvocationCount());
  }