felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantine Kougios <Konstantine.Koug...@akqa.com>
Subject Re: testing a service, mocking dependencies
Date Tue, 16 Sep 2014 13:59:50 GMT
Well, that¹s similar to the forTesting factory I mention but with the
drawback that the state of A is corrupted until the JVM terminates. By
corrupted I mean that my mock will be part of A until either the jvm stops
or something else injects a different thing to A.b. If the mock is set
this way while running in-container tests, A state is corrupted.

On 16/09/2014 14:56, "David Bosschaert" <david.bosschaert@gmail.com> wrote:

>Why not set the field b in your object manually to the mock B for unit
>Just assign it to the field. If you insist on having it private you
>can call 'Field.setAccessible(true)' in your unit test and assign it
>using reflection...
>Best regards,
>On 16 September 2014 14:39, Konstantine Kougios
><Konstantine.Kougios@akqa.com> wrote:
>> Hi, say I got a service A, which has a
>> @Reference private B b;
>> Now I want to write a unit test and mock B, how can I inject the mocked
>> Only reasonable thing I found so far is to have a static factory method
>>on A, public static A forTesting(B b) { Š }
>> Thanks,
>> Kostas
>To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>For additional commands, e-mail: users-help@felix.apache.org

To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org

View raw message