diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/OverrideMetadata.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/OverrideMetadata.java index 70510fa3796f..dcda79bcf750 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/OverrideMetadata.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/OverrideMetadata.java @@ -163,7 +163,7 @@ public boolean equals(Object other) { if (other == this) { return true; } - if (other == null || !getClass().isAssignableFrom(other.getClass())) { + if (other == null || other.getClass() != getClass()) { return false; } OverrideMetadata that = (OverrideMetadata) other; @@ -182,7 +182,7 @@ public boolean equals(Object other) { @Override public int hashCode() { - int hash = Objects.hash(this.beanType.getType(), this.beanName, this.strategy); + int hash = Objects.hash(getClass().hashCode(), this.beanType.getType(), this.beanName, this.strategy); return (this.beanName != null ? hash : hash + Objects.hash(this.field.getName(), Arrays.hashCode(this.field.getAnnotations()))); } diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideMetadata.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideMetadata.java index 5078a5dab59b..931b92c4b323 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideMetadata.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideMetadata.java @@ -98,23 +98,6 @@ T createSpy(String name, Object instance) { return (T) mock(toSpy, settings); } - @Override - public boolean equals(@Nullable Object other) { - if (other == this) { - return true; - } - // For SpyBean we want the class to be exactly the same. - if (other == null || other.getClass() != getClass()) { - return false; - } - return super.equals(other); - } - - @Override - public int hashCode() { - return getClass().hashCode() * 29 + super.hashCode(); - } - @Override public String toString() { return new ToStringCreator(this)