@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 testFixtureDetectsStateChangeOutsideOfHandler_AggregateDeleted() { TestExecutor exec = fixture .registerAnnotatedCommandHandler( new MyCommandHandler(fixture.getRepository(), fixture.getEventBus())) .given(new MyEvent("aggregateId", 5)); try { exec.when(new DeleteCommand("aggregateId", true)); fail("Fixture should have failed"); } catch (AssertionError error) { assertTrue( "Wrong message: " + error.getMessage(), error.getMessage().contains("considered deleted")); } }