|
17 | 17 | package org.springframework.context.annotation;
|
18 | 18 |
|
19 | 19 | import java.util.Map;
|
| 20 | +import java.util.Objects; |
20 | 21 | import java.util.regex.Pattern;
|
21 | 22 |
|
22 | 23 | import org.junit.jupiter.api.Test;
|
@@ -104,19 +105,19 @@ void getBeanByTypeRaisesNoSuchBeanDefinitionException() {
|
104 | 105 |
|
105 | 106 | // attempt to retrieve a bean that does not exist
|
106 | 107 | Class<?> targetType = Pattern.class;
|
107 |
| - assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> |
108 |
| - context.getBean(targetType)) |
109 |
| - .withMessageContaining(format("No qualifying bean of type '%s'", targetType.getName())); |
| 108 | + assertThatExceptionOfType(NoSuchBeanDefinitionException.class) |
| 109 | + .isThrownBy(() -> context.getBean(targetType)) |
| 110 | + .withMessageContaining(format("No qualifying bean of type '%s'", targetType.getName())); |
110 | 111 | }
|
111 | 112 |
|
112 | 113 | @Test
|
113 | 114 | void getBeanByTypeAmbiguityRaisesException() {
|
114 | 115 | ApplicationContext context = new AnnotationConfigApplicationContext(TwoTestBeanConfig.class);
|
115 |
| - assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> |
116 |
| - context.getBean(TestBean.class)) |
117 |
| - .withMessageContaining("No qualifying bean of type '" + TestBean.class.getName() + "'") |
118 |
| - .withMessageContaining("tb1") |
119 |
| - .withMessageContaining("tb2"); |
| 116 | + assertThatExceptionOfType(NoSuchBeanDefinitionException.class) |
| 117 | + .isThrownBy(() -> context.getBean(TestBean.class)) |
| 118 | + .withMessageContaining("No qualifying bean of type '" + TestBean.class.getName() + "'") |
| 119 | + .withMessageContaining("tb1") |
| 120 | + .withMessageContaining("tb2"); |
120 | 121 | }
|
121 | 122 |
|
122 | 123 | /**
|
@@ -309,8 +310,8 @@ void individualBeanWithNullReturningSupplier() {
|
309 | 310 | assertThat(context.getBeansOfType(BeanB.class).values().iterator().next()).isSameAs(context.getBean(BeanB.class));
|
310 | 311 | assertThat(context.getBeansOfType(BeanC.class).values().iterator().next()).isSameAs(context.getBean(BeanC.class));
|
311 | 312 |
|
312 |
| - assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> |
313 |
| - context.getBeanFactory().resolveNamedBean(BeanA.class)); |
| 313 | + assertThatExceptionOfType(NoSuchBeanDefinitionException.class) |
| 314 | + .isThrownBy(() -> context.getBeanFactory().resolveNamedBean(BeanA.class)); |
314 | 315 | assertThat(context.getBeanFactory().resolveNamedBean(BeanB.class).getBeanInstance()).isSameAs(context.getBean(BeanB.class));
|
315 | 316 | assertThat(context.getBeanFactory().resolveNamedBean(BeanC.class).getBeanInstance()).isSameAs(context.getBean(BeanC.class));
|
316 | 317 | }
|
@@ -601,7 +602,6 @@ static class BeanA {
|
601 | 602 | BeanB b;
|
602 | 603 | BeanC c;
|
603 | 604 |
|
604 |
| - |
605 | 605 | @Autowired
|
606 | 606 | BeanA(BeanB b, BeanC c) {
|
607 | 607 | this.b = b;
|
@@ -720,39 +720,18 @@ static class FactoryBeanInjectionPoints extends FactoryResultInjectionPoint {
|
720 | 720 | }
|
721 | 721 | }
|
722 | 722 |
|
| 723 | + |
723 | 724 | class TestBean {
|
724 | 725 |
|
725 | 726 | String name;
|
726 | 727 |
|
727 | 728 | @Override
|
728 |
| - public int hashCode() { |
729 |
| - final int prime = 31; |
730 |
| - int result = 1; |
731 |
| - result = prime * result + (name == null ? 0 : name.hashCode()); |
732 |
| - return result; |
| 729 | + public boolean equals(@Nullable Object other) { |
| 730 | + return (this == other || (other instanceof TestBean that && Objects.equals(this.name, that.name))); |
733 | 731 | }
|
734 | 732 |
|
735 | 733 | @Override
|
736 |
| - public boolean equals(@Nullable Object obj) { |
737 |
| - if (this == obj) { |
738 |
| - return true; |
739 |
| - } |
740 |
| - if (obj == null) { |
741 |
| - return false; |
742 |
| - } |
743 |
| - if (getClass() != obj.getClass()) { |
744 |
| - return false; |
745 |
| - } |
746 |
| - TestBean other = (TestBean) obj; |
747 |
| - if (name == null) { |
748 |
| - if (other.name != null) { |
749 |
| - return false; |
750 |
| - } |
751 |
| - } |
752 |
| - else if (!name.equals(other.name)) { |
753 |
| - return false; |
754 |
| - } |
755 |
| - return true; |
| 734 | + public int hashCode() { |
| 735 | + return this.name.hashCode(); |
756 | 736 | }
|
757 |
| - |
758 | 737 | }
|
0 commit comments