How do frameworks inject a resource into a private field without
violating security?
I know how to introspect, and I know how to get annotations, etc. I
just would like to know how to inject something into a private field
for testing purposes.
Danno - 23 Mar 2007 16:55 GMT
> How do frameworks inject a resource into a private field without
> violating security?
>
> I know how to introspect, and I know how to get annotations, etc. I
> just would like to know how to inject something into a private field
> for testing purposes.
Another term is "field injection". Most searches are about how to
use. I am looking at how to implement.
Danno - 23 Mar 2007 17:19 GMT
> How do frameworks inject a resource into a private field without
> violating security?
>
> I know how to introspect, and I know how to get annotations, etc. I
> just would like to know how to inject something into a private field
> for testing purposes.
Alright I got it....It is a simple case of called setAccessible on a
field in order for that to work.
Field field = t.getClass().getDeclaredField("someField");
field.setAccessible(true);
field.set(t, "woo");