Author: ltheussl
Date: Thu Jan 13 09:32:28 2011
New Revision: 1058474
URL: http://svn.apache.org/viewvc?rev=1058474&view=rev
Log:
take care of null values in sameSite, add test
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptor.java
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptorTest.java
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptor.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptor.java?rev=1058474&r1=1058473&r2=1058474&view=diff
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptor.java
(original)
+++
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptor.java
Thu Jan 13 09:32:28 2011
@@ -200,21 +200,27 @@ public class URIPathDescriptor
* Check if this URIPathDescriptor lives on the same site as the given URI.
*
* @param uri a URI to compare with.
+ * May be null, in which case false is returned.
*
* @return true if {@link #getBaseURI()} shares the same scheme, host and
port with the given URI
* where null values are allowed.
*/
public boolean sameSite( final URI uri )
{
+ if ( uri == null )
+ {
+ return false;
+ }
+
return sameSite( this.baseURI, uri );
}
private static boolean sameSite( final URI baseURI, final URI newBaseURI )
{
final boolean equalScheme = ( baseURI.getScheme() == null ?
newBaseURI.getScheme() == null
- : baseURI.getScheme().equals( newBaseURI.getScheme() ) );
+ : baseURI.getScheme().equalsIgnoreCase( newBaseURI.getScheme()
) );
final boolean equalHost = ( baseURI.getHost() == null ?
newBaseURI.getHost() == null
- : baseURI.getHost().equals( newBaseURI.getHost() ) );
+ : baseURI.getHost().equalsIgnoreCase( newBaseURI.getHost() ) );
final boolean equalPort = ( baseURI.getPort() == newBaseURI.getPort()
);
return ( equalScheme && equalPort && equalHost );
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptorTest.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptorTest.java?rev=1058474&r1=1058473&r2=1058474&view=diff
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptorTest.java
(original)
+++
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptorTest.java
Thu Jan 13 09:32:28 2011
@@ -20,6 +20,8 @@ package org.apache.maven.doxia.site.deco
* under the License.
*/
+import java.net.URI;
+
import junit.framework.TestCase;
/**
@@ -92,4 +94,26 @@ public class URIPathDescriptorTest
path = new URIPathDescriptor( "http://maven.apache.org/doxia",
"http://maven.apache.org/source" );
assertEquals( "../source", path.relativizeLink().toString() );
}
+
+ /**
+ * Test of sameSite method, of class URIPathDescriptor.
+ *
+ * @throws Exception
+ */
+ public void testSameSite()
+ throws Exception
+ {
+ final URIPathDescriptor path = new URIPathDescriptor(
"http://maven.apache.org/", "doxia" );
+
+ assertTrue( path.sameSite( new URI( "http://maven.apache.org/" ) ) );
+ assertTrue( path.sameSite( new URI( "http://maven.apache.org" ) ) );
+ assertTrue( path.sameSite( new URI( "HTTP://maven.apache.org/" ) ) );
+ assertTrue( path.sameSite( new URI( "http://MAVEN.apache.org/" ) ) );
+ assertTrue( path.sameSite( new URI(
"http://maven.apache.org/wagon/index.html" ) ) );
+
+ assertFalse( path.sameSite( null ) );
+ assertFalse( path.sameSite( new URI( "https://maven.apache.org/" ) ) );
+ assertFalse( path.sameSite( new URI( "http://ant.apache.org/" ) ) );
+ assertFalse( path.sameSite( new URI( "http://maven.apache.org:80" ) )
);
+ }
}