Privileged access is a test pattern for working around legacy code that cannot be changed. It uses Java’s Reflection API to read or modify private fields, making otherwise difficult tests possible. section 4.5.3
Inject.staticField("foo").of(LegacyCode.class).with(ourTestDouble);
BeanInject’s Inject utility substitutes a test double into a static field of a legacy class. This lets a test replace an internal dependency without changing the class. section 4.5.3
This workaround is especially useful when legacy code was not designed for testability. It is less useful when a project has used test-driven development from the start. section 4.5.3
