Hi Noam, thank you for proposing your help.
I am pasting all the code ...
Thought: I think the error is due to the use of a static method in the AddressService's transform method.
I read that testing code using static method can be a sign of code smell and that it makes unit testing much more difficult that it should be.
Looking forward to your inputs!
class AddressService {
def lookupService
def provinceService
def addressFormatHelper
def transform(acsAddress, country) {
def address = new Address()
try {
address.addressFormat = addressFormatHelper.getAddressFormat(country)
if (address) {
address.address1 = acsAddress.getAddress1()
/* other address fields */
address.country = lookupService.getCountry(acsAddress.getCountry(), AccountUtils.getUserLocale().getLanguage())
}
} catch (all) {
log.error "$all.message"
}
address
}
}
class AddressServiceSpec extends BaseUnitSpec {
def testTransform() {
setup:
def servletRequest = new MockHttpServletRequest()
service.lookupService = Mock(LookupService)
service.provinceService = Mock(ProvinceService)
service.addressFormatHelper = Mock(AddressFormatHelper)
def utils = Mock(AccountUtils)
utils.getUserLocale() >> new Locale("en")
AcsAddress acsAddress = new AcsAddress()
acsAddress.address1 = "Street Addres 1"
/* other fields */
service.provinceService.find(_,_) >> Mock(Province)
service.lookupService.getCountry(_,_) >> "United States"
service.addressFormatHelper.getAddressFormat(_) >> Mock(AddressFormat)
when:
def address = service.transform (acsAddress, "US")
then:
address.address1 == acsAddress.address1
}
}