I am trying to test a kafka error handler that takes in an Exception but as soon as I declare it in spock it actually throws it.
def 'test example'() {
when:
service.emitError(new Exception('test exception'))
then:
// do some tests
}
I have tried declaring it in a wrapped java class and running that in main will NOT throw an error but if I pull it into spock it will process it incorrectly.
I am trying to see if I am doing it wrong or if I can't test this with spock.
With help from Jeff I realized that it was an error on mock kafka template. When you have to pass an exception into a mock (not sure if it is just
KafkaTemplatespecific) and the expected mock fails something bubbles up and my try catch caught that instead. I recognize I should have posted the original code - and will in the future. This is testing on pre-refactored code that didn't have tests (not TTD)I was missing
.key('key')which was failing it.Emitter
Test