``` var resultValidator = testExecutor.whe...
# codereview
s
Copy code
var resultValidator = testExecutor.whenever(wheneverCommand!!)
        resultValidator = expects.events?.let { resultValidator.expectEvents(*it.toTypedArray()) } ?: resultValidator
        resultValidator = expects.eventsMatching?.let { resultValidator.expectEventsMatching(it) } ?: resultValidator
        resultValidator = expects.returnValue?.let { resultValidator.expectReturnValue(it) } ?: resultValidator
        resultValidator = expects.returnValueMatching?.let { resultValidator.expectReturnValueMatching(it) } ?: resultValidator
d
Why are you reassigning resultValidator? If to run assertions, then did you try #atrium ? There's some pretty nice advanced assertions, also, if you make the same checks repetedly (with a slight difference), think of making them into custom assertions (possibly w/ a param for slight difference). Also, group custom assertions by functionality tested.
s
These aren't assertions, maybe I should have posted the example where
resultValidator
isn't assigned to anything at first.
So instead of the above think of it like this
Copy code
var resultValidator: ResultValidator
        resultValidator = expects.events?.let { resultValidator.expectEvents(*it.toTypedArray()) } ?: resultValidator
        resultValidator = expects.eventsMatching?.let { resultValidator.expectEventsMatching(it) } ?: resultValidator
        resultValidator = expects.returnValue?.let { resultValidator.expectReturnValue(it) } ?: resultValidator
        resultValidator = expects.returnValueMatching?.let { resultValidator.expectReturnValueMatching(it) } ?: resultValidator
ugh. I'm giving bad examples.
when I get home tonight i'll try to clarify what I was trying to do.
👍🏼 1
Ok, so here's the actual example.
Copy code
var executorBuilder = aggregateTestFixture
        executorBuilder = registerBuilder.repository?.let { aggregateTestFixture.registerRepository(it) } ?: executorBuilder
        executorBuilder = registerBuilder.aggregateFactory?.let { aggregateTestFixture.registerAggregateFactory(it) } ?: executorBuilder
        executorBuilder = registerBuilder.annotatedCommandHandler?.let { aggregateTestFixture.registerAnnotatedCommandHandler(it) }
                ?: executorBuilder
aggregateTestFixture is not actually an executorBuilder.
it's a FixtureConfiguration
but any method called on the aggregateTestFixture returns an ExecutorBuilder.
any of those methods could be called, so I have to check, and reassign no matter what.
😕
d
Maybe look into chain of responsibility design pattern?