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);
}
}