@Test
  public void testSnapshotCreated_NoTransaction() throws Exception {
    SpringAggregateSnapshotter snapshotter = testSubject.getObject();
    snapshotter.setApplicationContext(mockApplicationContext);
    snapshotter.scheduleSnapshot(StubAggregate.class, aggregateIdentifier);

    verify(mockEventStore).storeSnapshot(eventSequence(1L));
  }
  @Test
  public void testSnapshotCreated_ExistingTransactionNotCommitted() throws Exception {
    testSubject.setTransactionManager(mockTransactionManager);
    SpringAggregateSnapshotter snapshotter = testSubject.getObject();
    snapshotter.setApplicationContext(mockApplicationContext);
    SimpleTransactionStatus existingTransaction = new SimpleTransactionStatus(false);
    when(mockTransactionManager.getTransaction(isA(TransactionDefinition.class)))
        .thenReturn(existingTransaction);

    snapshotter.scheduleSnapshot(StubAggregate.class, aggregateIdentifier);

    verify(mockEventStore).storeSnapshot(eventSequence(1L));
    verify(mockTransactionManager, never()).commit(existingTransaction);
  }
  @Test
  public void testSnapshotCreated_NewTransactionRolledBack() throws Exception {
    testSubject.setTransactionManager(mockTransactionManager);
    SpringAggregateSnapshotter snapshotter = testSubject.getObject();
    snapshotter.setApplicationContext(mockApplicationContext);
    SimpleTransactionStatus existingTransaction = new SimpleTransactionStatus(true);
    when(mockTransactionManager.getTransaction(any())).thenReturn(existingTransaction);
    doThrow(new RuntimeException("Stub"))
        .when(mockEventStore)
        .storeSnapshot(isA(DomainEventMessage.class));

    snapshotter.scheduleSnapshot(StubAggregate.class, aggregateIdentifier);

    verify(mockEventStore).storeSnapshot(eventSequence(1L));
    verify(mockTransactionManager, never()).commit(existingTransaction);
    verify(mockTransactionManager).rollback(existingTransaction);
  }