Test 2x AggregateCreation must fail precondition

I need to test that two times creating the same aggregate fails.
Unfortunatly SimpleBus intercepts my assertion exception which is
basically this in
RecipeCommandHandler.java

        try{
          Recipe recipe = repository.load(recipeId);
          Assert.isTrue(false, String.format("RecipeId <%1$s> already
in event store, when calling createRecipe", recipeId));
        }catch(AggregateNotFoundException e){
          Assert.isTrue(true);// not necessary, but i want to express
that you need to come here
        }

IntegrationTest.java
  @Test(expected=IllegalArgumentException.class)
  public void a_new_Recipe_is_issued_two_times() {
    CreateRecipe createRecipe = new CreateRecipe(expectedId,
recipeNameExpected, ownerId);
    // When same create recipe 2x
    cmdBus.dispatch(createRecipe);
    cmdBus.dispatch(createRecipe);
        }

Are such precondition failures testable?

Best Regards,
Roland

Hi Roland,

in your second test, the integration test, you need to use a Callback to detect any errors. The dispatch method only throws exceptions if they happen before the actual dispatching of a command (which will never happen in a SimpleCommandBus).

Use a callback and assert that the onFailure() method is never called. It might work to just call fail(“My message”) in the callback. Otherwise, you could use a mock (e.g. mockito) Callback and make sure the methods was called 0 times.

Cheers,

Allard