@Test
 public void testStoringExistingAggregateGeneratesException() {
   fixture.registerAggregateFactory(mockAggregateFactory);
   fixture.registerAnnotatedCommandHandler(
       new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()));
   fixture
       .given(new MyEvent("aggregateId", 1))
       .when(new CreateAggregateCommand("aggregateId"))
       .expectException(EventStoreException.class);
 }
  @SuppressWarnings("unchecked")
  @Test
  public void testConfigureCustomAggregateFactory() {
    fixture.registerAggregateFactory(mockAggregateFactory);
    fixture.registerAnnotatedCommandHandler(
        new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()));

    fixture.given(new MyEvent("id1", 1)).when(new TestCommand("id1"));

    verify(mockAggregateFactory).createAggregateRoot(eq("id1"), isA(DomainEventMessage.class));
  }
 @Test
 public void testReadAggregate_WrongIdentifier() {
   fixture.registerAggregateFactory(mockAggregateFactory);
   fixture.registerAnnotatedCommandHandler(
       new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()));
   TestExecutor exec = fixture.given(new MyEvent("AggregateId", 1));
   try {
     exec.when(new TestCommand("OtherIdentifier"));
     fail("Expected an AssertionError");
   } catch (AssertionError e) {
     assertTrue(
         "Wrong message. Was: " + e.getMessage(), e.getMessage().contains("OtherIdentifier"));
     assertTrue("Wrong message. Was: " + e.getMessage(), e.getMessage().contains("AggregateId"));
   }
 }
  @Test
  public void testAggregateIdentifier_IdentifierAutomaticallyDeducted() {
    fixture.registerAggregateFactory(mockAggregateFactory);
    fixture.registerAnnotatedCommandHandler(
        new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()));
    fixture
        .given(new MyEvent("AggregateId", 1), new MyEvent("AggregateId", 2))
        .when(new TestCommand("AggregateId"))
        .expectEvents(new MyEvent("AggregateId", 3));

    DomainEventStream events = fixture.getEventStore().readEvents("AggregateId");
    for (int t = 0; t < 3; t++) {
      assertTrue(events.hasNext());
      DomainEventMessage next = events.next();
      assertEquals("AggregateId", next.getAggregateIdentifier());
      assertEquals(t, next.getSequenceNumber());
    }
  }
 @SuppressWarnings("unchecked")
 @Test(expected = IncompatibleAggregateException.class)
 public void testConfigurationOfRequiredCustomAggregateFactoryNotProvided_FailureOnGiven() {
   fixture.given(new MyEvent("id1", 1));
 }