Why not set the field b in your object manually to the mock B for unit testing?
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, David On 16 September 2014 14:39, Konstantine Kougios <[email protected]> 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 > dependency? > > 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: [email protected] For additional commands, e-mail: [email protected]

