toThrow() cannot match empty message & cannot match detail

Description

ColdSpring throws coldspring.NoSuchBeanDefinition when you request a non-existent bean, e.g., Wibble, but it uses an empty message and a detail of "Bean definition for bean named: Wibble could not be found."

Assertion.throws() will not match any empty message: reFindNoCase( "", "" ) returns zero, as does reFindNoCase( "^$", "" ) so it seems that a special case is needed for e.message.

In addition, you can't match on the detail of an exception at all which means you can't differentiate between two similar exceptions.

I'm not quite sure what the best solution is here. I'd be tempted to change both calls of reFindNoCase( arguments.regex, e.message ) to ( reFindNoCase( arguments.regex, e.message ) || reFindNoCase( arguments.regex, e.detail ) ). That would solve the immediate problem insofar as you could then match on detail OR message.

Longer term, adding support for matching detail separately and special-casing for message / detail being empty strings would probably be a better solution.

Thoughts?

FWIW, I made the simple change locally of testing regex against message or detail and that's working nicely for me.

Assignee

Luis Majano

Reporter

Sean Corfield

Labels

None

Components

Fix versions

Affects versions

Configure