[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Field injection
alesj
do-not-reply at jboss.com
Thu Mar 20 07:24:16 EDT 2008
"adrian at jboss.org" wrote : Write the tests then you'll understand.
|
OK, the test is here, but it doesn't behave as I expect it to behave. :-(
| public void testFieldAcess() throws Throwable
| {
| final FieldsClass tester = new FieldsClass();
|
| final ReflectFieldInfoImpl impl = new ReflectFieldInfoImpl();
| SecurityManager sm = suspendSecurity();
| try
| {
| // e.g. I can't do setAccesible - although you can here, with the current disabled security
| Field myField = FieldsClass.class.getDeclaredField("privString");
| impl.setField(myField); // So I'll use this hole
| }
| finally
| {
| resumeSecurity(sm);
| }
|
| Field field = impl.getField(); // This should have an access check
| field.set(tester, "foobar");
| assertEquals("foobar", tester.getPrivString());
|
| Runnable runnable = new Runnable()
| {
| public void run()
| {
| try
| {
| Field fi = impl.getField(); // This should have an access check
| fi.set(tester, "something"); // this should check for caller
| }
| catch (Throwable t)
| {
| throw new RuntimeException(t);
| }
| }
| };
| ErrorHolderThread other = new ErrorHolderThread(runnable);
| other.start();
| other.join();
| // we should get an error here - but we don't :-(
| assertNotNull("Should get access restriction exception.", other.getError());
| RuntimeException re = assertInstanceOf(other.getError(), RuntimeException.class);
| Throwable cause = re.getCause();
| assertNotNull(cause);
| assertInstanceOf(cause, AccessControlException.class, false);
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138002#4138002
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4138002
More information about the jboss-dev-forums
mailing list