Skip to content

Commit d254bff

Browse files
committed
Polishing
1 parent 6fc5a78 commit d254bff

File tree

2 files changed

+16
-39
lines changed

2 files changed

+16
-39
lines changed

framework-docs/modules/ROOT/pages/core/beans/annotation-config/autowired.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,6 @@ ignored if it cannot be autowired. This allows properties to be assigned default
364364
that can be optionally overridden via dependency injection.
365365
====
366366

367-
368-
369367
[[beans-autowired-annotation-constructor-resolution]]
370368
Injected constructor and factory method arguments are a special case since the `required`
371369
attribute in `@Autowired` has a somewhat different meaning due to Spring's constructor

spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.context.annotation;
1818

1919
import java.util.Map;
20+
import java.util.Objects;
2021
import java.util.regex.Pattern;
2122

2223
import org.junit.jupiter.api.Test;
@@ -104,19 +105,19 @@ void getBeanByTypeRaisesNoSuchBeanDefinitionException() {
104105

105106
// attempt to retrieve a bean that does not exist
106107
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()));
110111
}
111112

112113
@Test
113114
void getBeanByTypeAmbiguityRaisesException() {
114115
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");
120121
}
121122

122123
/**
@@ -309,8 +310,8 @@ void individualBeanWithNullReturningSupplier() {
309310
assertThat(context.getBeansOfType(BeanB.class).values().iterator().next()).isSameAs(context.getBean(BeanB.class));
310311
assertThat(context.getBeansOfType(BeanC.class).values().iterator().next()).isSameAs(context.getBean(BeanC.class));
311312

312-
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
313-
context.getBeanFactory().resolveNamedBean(BeanA.class));
313+
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
314+
.isThrownBy(() -> context.getBeanFactory().resolveNamedBean(BeanA.class));
314315
assertThat(context.getBeanFactory().resolveNamedBean(BeanB.class).getBeanInstance()).isSameAs(context.getBean(BeanB.class));
315316
assertThat(context.getBeanFactory().resolveNamedBean(BeanC.class).getBeanInstance()).isSameAs(context.getBean(BeanC.class));
316317
}
@@ -601,7 +602,6 @@ static class BeanA {
601602
BeanB b;
602603
BeanC c;
603604

604-
605605
@Autowired
606606
BeanA(BeanB b, BeanC c) {
607607
this.b = b;
@@ -720,39 +720,18 @@ static class FactoryBeanInjectionPoints extends FactoryResultInjectionPoint {
720720
}
721721
}
722722

723+
723724
class TestBean {
724725

725726
String name;
726727

727728
@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)));
733731
}
734732

735733
@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();
756736
}
757-
758737
}

0 commit comments

Comments
 (0)