From a9fe466614b87f1b3efc6440c6f268f11dc8f7fd Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 26 Oct 2010 20:16:24 -0700 Subject: [PATCH] ensured credentials compare equivalent in subclasses --- .../java/org/jclouds/domain/Credentials.java | 15 +++++---- .../org/jclouds/domain/CredentialsTest.java | 31 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/org/jclouds/domain/Credentials.java b/core/src/main/java/org/jclouds/domain/Credentials.java index eb6cae9992..23eacb0764 100644 --- a/core/src/main/java/org/jclouds/domain/Credentials.java +++ b/core/src/main/java/org/jclouds/domain/Credentials.java @@ -61,8 +61,8 @@ public class Credentials { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((identity == null) ? 0 : identity.hashCode()); result = prime * result + ((credential == null) ? 0 : credential.hashCode()); + result = prime * result + ((identity == null) ? 0 : identity.hashCode()); return result; } @@ -72,20 +72,19 @@ public class Credentials { return true; if (obj == null) return false; - if (getClass() != obj.getClass()) + if (!(obj instanceof Credentials)) return false; Credentials other = (Credentials) obj; - if (identity == null) { - if (other.identity != null) - return false; - } else if (!identity.equals(other.identity)) - return false; if (credential == null) { if (other.credential != null) return false; } else if (!credential.equals(other.credential)) return false; - + if (identity == null) { + if (other.identity != null) + return false; + } else if (!identity.equals(other.identity)) + return false; return true; } diff --git a/core/src/test/java/org/jclouds/domain/CredentialsTest.java b/core/src/test/java/org/jclouds/domain/CredentialsTest.java index 767889bdfd..37bcede059 100644 --- a/core/src/test/java/org/jclouds/domain/CredentialsTest.java +++ b/core/src/test/java/org/jclouds/domain/CredentialsTest.java @@ -32,8 +32,8 @@ import org.testng.annotations.Test; public class CredentialsTest { public void testAzure() { - Credentials creds = Credentials.parse(URI - .create("compute://identity:Base64==@azureblob/container-hyphen/prefix")); + Credentials creds = Credentials + .parse(URI.create("compute://identity:Base64==@azureblob/container-hyphen/prefix")); assertEquals(creds.identity, "identity"); assertEquals(creds.credential, "Base64=="); } @@ -46,36 +46,31 @@ public class CredentialsTest { } public void testDollar() { - Credentials creds = Credentials.parse(URI - .create("compute://user%40domain:pa%24sword@hostingdotcom")); + Credentials creds = Credentials.parse(URI.create("compute://user%40domain:pa%24sword@hostingdotcom")); assertEquals(creds.identity, "user@domain"); assertEquals(creds.credential, "pa$sword"); } public void testTerremark() { - Credentials creds = Credentials.parse(URI - .create("compute://user%40domain:password@terremark")); + Credentials creds = Credentials.parse(URI.create("compute://user%40domain:password@terremark")); assertEquals(creds.identity, "user@domain"); assertEquals(creds.credential, "password"); } public void testTerremark2() { - Credentials creds = Credentials.parse(URI - .create("compute://user%40domain:passw%40rd@terremark")); + Credentials creds = Credentials.parse(URI.create("compute://user%40domain:passw%40rd@terremark")); assertEquals(creds.identity, "user@domain"); assertEquals(creds.credential, "passw@rd"); } public void testTerremark3() { - Credentials creds = Credentials.parse(URI - .create("compute://user%40domain:AbC%21%40943%21@terremark")); + Credentials creds = Credentials.parse(URI.create("compute://user%40domain:AbC%21%40943%21@terremark")); assertEquals(creds.identity, "user@domain"); assertEquals(creds.credential, "AbC!@943!"); } public void testCloudFiles() { - Credentials creds = Credentials.parse(URI - .create("compute://identity:h3c@cloudfiles/container-hyphen/prefix")); + Credentials creds = Credentials.parse(URI.create("compute://identity:h3c@cloudfiles/container-hyphen/prefix")); assertEquals(creds.identity, "identity"); assertEquals(creds.credential, "h3c"); @@ -83,18 +78,22 @@ public class CredentialsTest { public void testS3() { - Credentials creds = Credentials - .parse(URI.create("compute://0AB:aA%2B%2F0@s3/buck-et/prefix")); + Credentials creds = Credentials.parse(URI.create("compute://0AB:aA%2B%2F0@s3/buck-et/prefix")); assertEquals(creds.identity, "0AB"); assertEquals(creds.credential, "aA+/0"); } public void testS3Space() { - Credentials creds = Credentials.parse(URI - .create("compute://0AB:aA%2B%2F0@s3/buck-et/pre%20fix")); + Credentials creds = Credentials.parse(URI.create("compute://0AB:aA%2B%2F0@s3/buck-et/pre%20fix")); assertEquals(creds.identity, "0AB"); assertEquals(creds.credential, "aA+/0"); } + public void testSubClassEquals() { + Credentials creds = new Credentials("user", "pass"); + assertEquals(creds, new Credentials("user", "pass") { + }); + } + }