Fix UriComponents.equals() method
Fix HierarchicalUriComponents and OpaqueUriComponents .equals() methods. Issue: SPR-10313
This commit is contained in:
parent
7e2022b9a7
commit
5b7969e726
|
@ -39,6 +39,7 @@ import org.springframework.util.StringUtils;
|
||||||
* Extension of {@link UriComponents} for hierarchical URIs.
|
* Extension of {@link UriComponents} for hierarchical URIs.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @author Phillip Webb
|
||||||
* @since 3.1.3
|
* @since 3.1.3
|
||||||
* @see <a href="http://tools.ietf.org/html/rfc3986#section-1.2.3">Hierarchical URIs</a>
|
* @see <a href="http://tools.ietf.org/html/rfc3986#section-1.2.3">Hierarchical URIs</a>
|
||||||
*/
|
*/
|
||||||
|
@ -430,28 +431,15 @@ final class HierarchicalUriComponents extends UriComponents {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HierarchicalUriComponents other = (HierarchicalUriComponents) obj;
|
HierarchicalUriComponents other = (HierarchicalUriComponents) obj;
|
||||||
if (ObjectUtils.nullSafeEquals(getScheme(), other.getScheme())) {
|
boolean rtn = true;
|
||||||
return false;
|
rtn &= ObjectUtils.nullSafeEquals(getScheme(), other.getScheme());
|
||||||
}
|
rtn &= ObjectUtils.nullSafeEquals(getUserInfo(), other.getUserInfo());
|
||||||
if (ObjectUtils.nullSafeEquals(getUserInfo(), other.getUserInfo())) {
|
rtn &= ObjectUtils.nullSafeEquals(getHost(), other.getHost());
|
||||||
return false;
|
rtn &= getPort() == other.getPort();
|
||||||
}
|
rtn &= this.path.equals(other.path);
|
||||||
if (ObjectUtils.nullSafeEquals(getHost(), other.getHost())) {
|
rtn &= this.queryParams.equals(other.queryParams);
|
||||||
return false;
|
rtn &= ObjectUtils.nullSafeEquals(getFragment(), other.getFragment());
|
||||||
}
|
return rtn;
|
||||||
if (this.port != other.port) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!this.path.equals(other.path)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!this.queryParams.equals(other.queryParams)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ObjectUtils.nullSafeEquals(getFragment(), other.getFragment())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -30,6 +30,7 @@ import org.springframework.util.ObjectUtils;
|
||||||
* Extension of {@link UriComponents} for opaque URIs.
|
* Extension of {@link UriComponents} for opaque URIs.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @author Phillip Webb
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
* @see <a href="http://tools.ietf.org/html/rfc3986#section-1.2.3">Hierarchical vs Opaque URIs</a>
|
* @see <a href="http://tools.ietf.org/html/rfc3986#section-1.2.3">Hierarchical vs Opaque URIs</a>
|
||||||
*/
|
*/
|
||||||
|
@ -145,18 +146,11 @@ final class OpaqueUriComponents extends UriComponents {
|
||||||
}
|
}
|
||||||
|
|
||||||
OpaqueUriComponents other = (OpaqueUriComponents) obj;
|
OpaqueUriComponents other = (OpaqueUriComponents) obj;
|
||||||
|
boolean rtn = true;
|
||||||
if (ObjectUtils.nullSafeEquals(getScheme(), other.getScheme())) {
|
rtn &= ObjectUtils.nullSafeEquals(getScheme(), other.getScheme());
|
||||||
return false;
|
rtn &= ObjectUtils.nullSafeEquals(this.ssp, other.ssp);
|
||||||
}
|
rtn &= ObjectUtils.nullSafeEquals(getFragment(), other.getFragment());
|
||||||
if (ObjectUtils.nullSafeEquals(this.ssp, other.ssp)) {
|
return rtn;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ObjectUtils.nullSafeEquals(getFragment(), other.getFragment())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,9 +26,14 @@ import java.net.URISyntaxException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/** @author Arjen Poutsma */
|
/**
|
||||||
|
* @author Arjen Poutsma
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
public class UriComponentsTests {
|
public class UriComponentsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -92,4 +97,26 @@ public class UriComponentsTests {
|
||||||
assertThat(uriComponents.toString(), equalTo(readObject.toString()));
|
assertThat(uriComponents.toString(), equalTo(readObject.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsHierarchicalUriComponents() throws Exception {
|
||||||
|
UriComponents uriComponents1 = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo}").query("bar={baz}").build();
|
||||||
|
UriComponents uriComponents2 = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo}").query("bar={baz}").build();
|
||||||
|
UriComponents uriComponents3 = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo}").query("bin={baz}").build();
|
||||||
|
assertThat(uriComponents1, instanceOf(HierarchicalUriComponents.class));
|
||||||
|
assertThat(uriComponents1, equalTo(uriComponents1));
|
||||||
|
assertThat(uriComponents1, equalTo(uriComponents2));
|
||||||
|
assertThat(uriComponents1, not(equalTo(uriComponents3)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsOpaqueUriComponents() throws Exception {
|
||||||
|
UriComponents uriComponents1 = UriComponentsBuilder.fromUriString("http:example.com/foo/bar").build();
|
||||||
|
UriComponents uriComponents2 = UriComponentsBuilder.fromUriString("http:example.com/foo/bar").build();
|
||||||
|
UriComponents uriComponents3 = UriComponentsBuilder.fromUriString("http:example.com/foo/bin").build();
|
||||||
|
assertThat(uriComponents1, instanceOf(OpaqueUriComponents.class));
|
||||||
|
assertThat(uriComponents1, equalTo(uriComponents1));
|
||||||
|
assertThat(uriComponents1, equalTo(uriComponents2));
|
||||||
|
assertThat(uriComponents1, not(equalTo(uriComponents3)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue