Hi, Dan. Many thanks for your answer.
The problem I was finding when trying to mock the service was that it was a whole new instance, and there's no way to "replace" the default instance by this mocked one, or to "load" the mocked one at first, instead of Isis creating a new instance by means of the IsisSystemForTest.Builder. This was not a priority test (it was an easy to implement functionality and I can simply go to the UI to know if it works) but perhaps there will be more cases where mocked services could be need in the future. If you can send me that TDD slides would be grate! Until now, nearly all our tests are integration tests, but there are some external systems we are connecting through Isis services where unit testing would be wonderful, as they could be tested without being connected to the external system. Thanks! El 19/06/2014, a las 10:25, Dan Haywood <[email protected]> escribió: > Hi Oscar, > > That sample looks *almost* correct. JMockActions.returnEach is a custom > implementation of the JMock Action API that I wrote for some purpose or > other (a method that returns a different value each time it is called); but > normally one would use the built-in action implementations, usually either > "returnValue(...)" or "throwException(...)". > > Thus: > > // given > context.checking(new Expectations() { > { > one([DOMAIN SERVICE]).locale(); > will(returnValue(new Locale("en"))); > } > }); > > Are you certain that [DOMAIN SERVICE] is a mock, though? the > IntegrationTestAbstract will usually return real service implementations? > > (I was about to go on to say say that you could override > IntegrationTestAbstract#getService(...) to return a mock for the service > you want, but on second thoughts I don't think that would work, because the > actual system under test would be using a real implementation of the > service) > > If you are still struggling with JMock, I have a TDD training course that > covers it, happy to send you it off-list. > > Cheers > Dan > > > > > On 18 June 2014 18:43, GESCONSULTOR - Óscar Bou <[email protected]> > wrote: > >> Hi to all. >> >> I have an Integration Test where I want to mock the resulting value of a >> service's method. >> >> I have no experience with JMock and seems quite different from mockito. >> >> I see the "context" property defined on IntegrationTestAbstract, but not >> sure about how to best specify that whenever I invoke that service method, >> the result value should be "x". >> >> I've looked at the samples at [1], but not sure about how to specify >> something like: >> >> // given >> // final UserAccount userAccount = this.service(UserAccount.class); >> this.context.checking(new Expectations() { >> { >> this.one([DOMAIN SERVICE]).locale(); >> this.will(JMockActions.returnEach(new Locale("en"))); >> } >> }); >> >> >> Any help, please? >> >> Thanks, >> >> Oscar >> >> >> Óscar Bou Bou Responsable de Producto Auditor Jefe de Certificación ISO 27001 en BSI CISA, CRISC, APMG ISO 20000, ITIL-F 902 900 231 / 620 267 520 http://www.twitter.com/oscarbou http://es.linkedin.com/in/oscarbou http://www.GesConsultor.com Este mensaje y los ficheros anexos son confidenciales. Los mismos contienen información reservada que no puede ser difundida. Si usted ha recibido este correo por error, tenga la amabilidad de eliminarlo de su sistema y avisar al remitente mediante reenvío a su dirección electrónica; no deberá copiar el mensaje ni divulgar su contenido a ninguna persona. Su dirección de correo electrónico junto a sus datos personales constan en un fichero titularidad de Gesdatos Software, S.L. cuya finalidad es la de mantener el contacto con Ud. Si quiere saber de qué información disponemos de Ud., modificarla, y en su caso, cancelarla, puede hacerlo enviando un escrito al efecto, acompañado de una fotocopia de su D.N.I. a la siguiente dirección: Gesdatos Software, S.L. , Paseo de la Castellana, 153 bajo - 28046 (Madrid), y Avda. Cortes Valencianas num. 50, 1ºC - 46015 (Valencia). Asimismo, es su responsabilidad comprobar que este mensaje o sus archivos adjuntos no contengan virus informáticos, y en caso que los tuvieran eliminarlos.
