yan
yan

Reputation: 169

EasyMock - how to set mock object to a field without setter?

i have a class with the field that initialized without setter using static call:

class A{

private B b = Env.getEnv().getInstance("b");

...

}

i want to test class A supplying a mock of class B. Is it possible? The A class is not mine and i can't use setter, reflection here also not possible.

Any help will be appreceated!

Thank you,

Yan

Upvotes: 0

Views: 1255

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499800

It depends what Env.getEnv(...).getInstance() does. Can you change that to return your mock? If not, you've basically got a class which really isn't designed for testability, and you'll find it hard to inject the dependencies.

Upvotes: 1

Related Questions