资 源 简 介
PrivilegedAccessor is a simple to use Java framework for accessing private methods, attributes, and constructors via reflection.
Introduction
In unit-testing you often need to prepare and later inspect the unit-under-test before you can test it. For instance you might need to inject mock-objects in your unit, so your unit-test does not access other units like backend systems. Or you might need to access a private attribute to assert a post-condition of a unit after the test.
This could be easily done if Java had no modifiers like private. Accessing private (or protected or package private) methods, attributes, and constructors from outside is forbidden. And you should never change the modifiers of your production code just for unit-testing purposes!!!
Fortunately we have reflection to access everything in our classes. Unfortunately reflection is somehow complicated:
E