#1732 - Added equals(…) and hashCode() methods to TypeBasedPayloadMetadata.
$ Conflicts: $ src/test/java/org/springframework/hateoas/server/mvc/WebMvcLinkBuilderUnitTest.java
This commit is contained in:
@@ -115,4 +115,42 @@ class TypeBasedPayloadMetadata implements InputPayloadMetadata {
|
||||
public List<MediaType> getMediaTypes() {
|
||||
return mediaTypes;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof TypeBasedPayloadMetadata)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TypeBasedPayloadMetadata that = (TypeBasedPayloadMetadata) obj;
|
||||
|
||||
return this.type.equals(that.type)
|
||||
&& this.properties.equals(that.properties)
|
||||
&& this.mediaTypes.equals(that.mediaTypes);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
int result = 31;
|
||||
|
||||
result += 17 * type.hashCode();
|
||||
result += 17 * properties.hashCode();
|
||||
result += 17 * mediaTypes.hashCode();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
@@ -683,6 +684,19 @@ class WebMvcLinkBuilderUnitTest extends TestUtils {
|
||||
.forEach(it -> it.withMessageContaining("Expected 1, got 0"));
|
||||
}
|
||||
|
||||
@Test // #1729
|
||||
@SuppressWarnings("null")
|
||||
void linksPointingToTheSameMethodAreEqual() {
|
||||
|
||||
Link first = linkTo(methodOn(ControllerWithMethods.class).methodWithRequestBody(null)).withSelfRel();
|
||||
Link second = linkTo(methodOn(ControllerWithMethods.class).methodWithRequestBody(null)).withSelfRel();
|
||||
|
||||
assertThat(first).isEqualTo(second);
|
||||
assertThat(second).isEqualTo(first);
|
||||
assertThat(first.hashCode()).isEqualTo(second.hashCode());
|
||||
assertThat(second.hashCode()).isEqualTo(first.hashCode());
|
||||
}
|
||||
|
||||
private static UriComponents toComponents(Link link) {
|
||||
return UriComponentsBuilder.fromUriString(link.expand().getHref()).build();
|
||||
}
|
||||
@@ -768,6 +782,12 @@ class WebMvcLinkBuilderUnitTest extends TestUtils {
|
||||
HttpEntity<Void> methodWithMapRequestParam(@RequestParam Map<String, String> params) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// #1729
|
||||
@RequestMapping(method = RequestMethod.POST, path = "/with-request-body")
|
||||
HttpEntity<Void> methodWithRequestBody(@RequestBody Person param) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/parent")
|
||||
|
||||
Reference in New Issue
Block a user