How to unit or integration test use of injected messageSource for i18n in Grails 2.0 service

后端 未结 3 456
暖寄归人
暖寄归人 2020-12-16 00:00

I make use of a message bundle in one of my services in a Grails 2.0 project for internationalized text. The use case is an email subject that is sent via the mail plugin in

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 00:13

    There is already a messageSource in unit tests in Grails, it is a StaticMessageSource (see http://static.springsource.org/spring/docs/2.5.4/api/org/springframework/context/support/StaticMessageSource.html), you can add mock messages with the addMessage method:

    messageSource.addMessage("foo.bar", request.locale, "My Message")
    

提交回复
热议问题