masooh / intellij-junit-to-spock-converter

JUnit to Spock Converter IntelliJ Plugin: Converts JUnit to Spock. See https://plugins.jetbrains.com/plugin/12335-groovyfier
MIT License
8 stars 3 forks source link

Support conversion of when().thenThrow() #29

Open rojyates opened 3 years ago

rojyates commented 3 years ago

Conversion Request

I would like the plugin to replace

when(repository.findAll(any(Pageable.class)).thenThrow(CannotCreateTransactionException.class)
when(repository.findAll(any(Specification.class), any(Pageable.class))).thenThrow(CannotCreateTransactionException.class)

with

repository.findAll(_ as Pageable) >> { throw new CannotCreateTransactionException("test") }
repository.findAll(_ as Specification, _ as Pageable)) >> { throw new CannotCreateTransactionException("test") }

Regex

I currently use the following regex search:

when\(([\w\.]+)\(([\w,\s]+)\)\)[\r\n\s]*.thenThrow\((.*)(?:\.class)\)

and replace:

$1($2) >> { throw new $3("test") }