Search in sources :

Example 1 with Bean

use of org.apache.wicket.spring.injection.util.Bean in project wicket by apache.

the class AnnotProxyFieldValueFactoryTest method testFailsIfBeanWithIdIsNotFound.

/**
 * @throws Exception
 */
@Test
public void testFailsIfBeanWithIdIsNotFound() throws Exception {
    InjectableWithReferenceToNonexistingBean obj = new InjectableWithReferenceToNonexistingBean();
    Field field = obj.getClass().getDeclaredField("nonExisting");
    try {
        final Bean bean = (Bean) factory.getFieldValue(field, obj);
        /*
			 * returned bean will not be null even though the bean is not found. what we get instead
			 * is a proxy. we invoke a method on the proxy in order to cause it to try to locate the
			 * bean and that is when it will fail
			 */
        bean.method();
        fail();
    } catch (RuntimeException e) {
        // expected
        assertTrue(true);
    }
}
Also used : Field(java.lang.reflect.Field) Bean(org.apache.wicket.spring.injection.util.Bean) Test(org.junit.Test)

Aggregations

Field (java.lang.reflect.Field)1 Bean (org.apache.wicket.spring.injection.util.Bean)1 Test (org.junit.Test)1