getApplicationContext().getBean(name) may return a org.springframework.beans.factory.support.NullBean bean and does not throw the expected NoSuchBeanDefinitionException that validates the assertion. However, this NullBean is not meant to be, therefore it must be checked prior throwing the assertion error.
Comment From: pivotal-cla
@deadeuzesse Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-cla
@deadeuzesse Thank you for signing the Contributor License Agreement!
Comment From: snicoll
@deadeuzesse thanks for the PR but not throwing NoSuchBeanDefinitionException
would be wrong as the bean definition actually exists (the instance is null
). Can you expand a bit more on the use case? The lack of additional tests in the PR doesn't help from that perspective.
Comment From: deadeuzesse
Indeed, point is not to throw a NoSuchBeanDefinitionException since the bean does exists. I don't know why the applicationContext contains such bean. The point is the bean is of type org.springframework.beans.factory.support.NullBean is not meant to be available: Initial commit : https://github.com/spring-projects/spring-framework/commit/b94302b5bde7475b9926dacb9fb69f3c8c894444
According to that, when I assert my context, I expected they won't be available, that's why i considered the ApplicationContextAssert.doesNotHaveBean(String) should have managed such case.
For now i'm using this convolution, it's a bit sad but it works
// NullBean convolution
Object myBean= context.getBean("myBean");
assertTrue(myBean.equals(null)); // that's a NullBean -_-'
Comment From: wilkinsona
I don't think we should make this change. The context does contain a bean with the requested name so asserting it does not should fail as it currently does. This behaviour is particularly important with @ConditionalOnMissingBean
and @ConditionalOnBean
because a bean definition with a null
value will still affect the matching of those conditions. Thanks anyway.