You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Sometimes I want to change the values of private attributes while testing student code. There is no ReflectionTestUtils method to do that.
Describe the solution you'd like
A new method (e.g. setValueForNonPublicAttribute, setValueForAttribute...) in the ReflectionTestUtils, which can also find and change an attribute even if it is defined in one of the superclasses.
Describe alternatives you've considered
I created a method myself.
publicstaticvoidsetValueForNonPublicAttribute(ObjectobjectToModify, StringattributeName, ObjectattributeValueToSet) {
Classcls = objectToModify.getClass();
do {
try {
Fieldfield = cls.getDeclaredField(attributeName);
field.trySetAccessible();
field.set(objectToModify, attributeValueToSet);
return;
} catch (NoSuchFieldExceptione) {
cls = cls.getSuperclass();
} catch (Exceptione) {
fail("In " + objectToModify.getClass().getSimpleName() + ", " + attributeName + " can not be set to " + attributeValueToSet + ".");
}
} while (cls != null);
fail("Could not find the attribute " + attributeName + " in class " + objectToModify.getClass().getSimpleName() + "! Make sure it exists and check for typos.");
}
Ares-Version you are using
1.11.0
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Sometimes I want to change the values of private attributes while testing student code. There is no ReflectionTestUtils method to do that.
Describe the solution you'd like
A new method (e.g. setValueForNonPublicAttribute, setValueForAttribute...) in the ReflectionTestUtils, which can also find and change an attribute even if it is defined in one of the superclasses.
Describe alternatives you've considered
I created a method myself.
Ares-Version you are using
1.11.0
The text was updated successfully, but these errors were encountered: