Skip to content

Commit 2d48371

Browse files
committed
Revert polish on Bean Override support
This commit revers the removal of the `private` keyword in the examples of the reference documentation and the tests for consistency. While the default visibility makes the example more concise, it could imply to the reader that the field (or the factory method) cannot be private. Also, there is no need to multiply anything returned from `Objects.hash` as its very distinct on its own already.
1 parent dc2c8d6 commit 2d48371

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-mockitobean.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Java::
4343
----
4444
class OverrideBeanTests {
4545
@MockitoBean // <1>
46-
CustomService customService;
46+
private CustomService customService;
4747
4848
// test case body...
4949
}
@@ -67,7 +67,7 @@ Java::
6767
----
6868
class OverrideBeanTests {
6969
@MockitoBean(name = "service") // <1>
70-
CustomService customService;
70+
private CustomService customService;
7171
7272
// test case body...
7373
@@ -88,7 +88,7 @@ Java::
8888
----
8989
class OverrideBeanTests {
9090
@MockitoSpyBean // <1>
91-
CustomService customService;
91+
private CustomService customService;
9292
9393
// test case body...
9494
}
@@ -111,7 +111,7 @@ Java::
111111
----
112112
class OverrideBeanTests {
113113
@MockitoSpyBean(name = "service") // <1>
114-
CustomService customService;
114+
private CustomService customService;
115115
116116
// test case body...
117117

framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-testbean.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ Java::
3636
----
3737
class OverrideBeanTests {
3838
@TestBean // <1>
39-
CustomService customService;
39+
private CustomService customService;
4040
4141
// test case body...
4242
43-
static CustomService customService() { // <2>
43+
private static CustomService customService() { // <2>
4444
return new MyFakeCustomService();
4545
}
4646
}
@@ -64,11 +64,11 @@ Java::
6464
----
6565
class OverrideBeanTests {
6666
@TestBean(name = "service", methodName = "createCustomService") // <1>
67-
CustomService customService;
67+
private CustomService customService;
6868
6969
// test case body...
7070
71-
static CustomService createCustomService() { // <2>
71+
private static CustomService createCustomService() { // <2>
7272
return new MyFakeCustomService();
7373
}
7474
}

spring-test/src/main/java/org/springframework/test/context/bean/override/OverrideMetadata.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ protected OverrideMetadata(Field field, ResolvableType beanType, @Nullable Strin
8080
* @return a list of {@code OverrideMetadata}
8181
*/
8282
public static List<OverrideMetadata> forTestClass(Class<?> testClass) {
83-
List<OverrideMetadata> metadataList = new LinkedList<>();
84-
ReflectionUtils.doWithFields(testClass, field -> parseField(field, testClass, metadataList));
85-
return metadataList;
83+
List<OverrideMetadata> metadata = new LinkedList<>();
84+
ReflectionUtils.doWithFields(testClass, field -> parseField(field, testClass, metadata));
85+
return metadata;
8686
}
8787

8888
private static void parseField(Field field, Class<?> testClass, List<OverrideMetadata> metadataList) {
@@ -185,7 +185,7 @@ public boolean equals(Object other) {
185185
public int hashCode() {
186186
int hash = Objects.hash(getClass(), this.beanType.getType(), this.beanName, this.strategy);
187187
return (this.beanName != null ? hash : hash +
188-
31 * Objects.hash(this.field.getName(), Arrays.hashCode(this.field.getAnnotations())));
188+
Objects.hash(this.field.getName(), Arrays.hashCode(this.field.getAnnotations())));
189189
}
190190

191191
@Override

spring-test/src/test/java/org/springframework/test/context/bean/override/OverrideMetadataTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -231,27 +231,27 @@ static String foo() {
231231

232232
public static class ConfigA {
233233

234-
ExampleService noQualifier;
234+
private ExampleService noQualifier;
235235

236236
@Qualifier("test")
237-
ExampleService directQualifier;
237+
private ExampleService directQualifier;
238238

239239
@Qualifier("different")
240-
ExampleService differentDirectQualifier;
240+
private ExampleService differentDirectQualifier;
241241

242242
@CustomQualifier
243-
ExampleService customQualifier;
243+
private ExampleService customQualifier;
244244

245245
}
246246

247247
public static class ConfigB {
248248

249-
ExampleService noQualifier;
249+
private ExampleService noQualifier;
250250

251-
ExampleService example;
251+
private ExampleService example;
252252

253253
@Qualifier("test")
254-
ExampleService directQualifier;
254+
private ExampleService directQualifier;
255255

256256
}
257257

spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanContextCustomizerEqualityTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static class Case4 {
8989
@TestBean
9090
private String description;
9191

92-
static String description() {
92+
private static String description() {
9393
return "overridden";
9494
}
9595
}
@@ -99,7 +99,7 @@ static class Case5 {
9999
@TestBean(name = "descriptionBean")
100100
private String description;
101101

102-
static String description() {
102+
private static String description() {
103103
return "overridden";
104104
}
105105
}

0 commit comments

Comments
 (0)