Refactor tests using Spock's data table and production code using ternary