Skip to content

Commit

Permalink
Revert polish on Bean Override support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
snicoll committed Jun 12, 2024
1 parent dc2c8d6 commit 2d48371
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Java::
----
class OverrideBeanTests {
@MockitoBean // <1>
CustomService customService;
private CustomService customService;
// test case body...
}
Expand All @@ -67,7 +67,7 @@ Java::
----
class OverrideBeanTests {
@MockitoBean(name = "service") // <1>
CustomService customService;
private CustomService customService;
// test case body...
Expand All @@ -88,7 +88,7 @@ Java::
----
class OverrideBeanTests {
@MockitoSpyBean // <1>
CustomService customService;
private CustomService customService;
// test case body...
}
Expand All @@ -111,7 +111,7 @@ Java::
----
class OverrideBeanTests {
@MockitoSpyBean(name = "service") // <1>
CustomService customService;
private CustomService customService;
// test case body...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Java::
----
class OverrideBeanTests {
@TestBean // <1>
CustomService customService;
private CustomService customService;
// test case body...
static CustomService customService() { // <2>
private static CustomService customService() { // <2>
return new MyFakeCustomService();
}
}
Expand All @@ -64,11 +64,11 @@ Java::
----
class OverrideBeanTests {
@TestBean(name = "service", methodName = "createCustomService") // <1>
CustomService customService;
private CustomService customService;
// test case body...
static CustomService createCustomService() { // <2>
private static CustomService createCustomService() { // <2>
return new MyFakeCustomService();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ protected OverrideMetadata(Field field, ResolvableType beanType, @Nullable Strin
* @return a list of {@code OverrideMetadata}
*/
public static List<OverrideMetadata> forTestClass(Class<?> testClass) {
List<OverrideMetadata> metadataList = new LinkedList<>();
ReflectionUtils.doWithFields(testClass, field -> parseField(field, testClass, metadataList));
return metadataList;
List<OverrideMetadata> metadata = new LinkedList<>();
ReflectionUtils.doWithFields(testClass, field -> parseField(field, testClass, metadata));
return metadata;
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,27 +231,27 @@ static String foo() {

public static class ConfigA {

ExampleService noQualifier;
private ExampleService noQualifier;

@Qualifier("test")
ExampleService directQualifier;
private ExampleService directQualifier;

@Qualifier("different")
ExampleService differentDirectQualifier;
private ExampleService differentDirectQualifier;

@CustomQualifier
ExampleService customQualifier;
private ExampleService customQualifier;

}

public static class ConfigB {

ExampleService noQualifier;
private ExampleService noQualifier;

ExampleService example;
private ExampleService example;

@Qualifier("test")
ExampleService directQualifier;
private ExampleService directQualifier;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static class Case4 {
@TestBean
private String description;

static String description() {
private static String description() {
return "overridden";
}
}
Expand All @@ -99,7 +99,7 @@ static class Case5 {
@TestBean(name = "descriptionBean")
private String description;

static String description() {
private static String description() {
return "overridden";
}
}
Expand Down

0 comments on commit 2d48371

Please sign in to comment.