incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r960835 - in /incubator/amber/trunk/server/src: main/java/org/apache/amber/server/Access.java test/java/org/apache/amber/server/AccessTest.java
Date Tue, 06 Jul 2010 07:44:38 GMT
Author: tommaso
Date: Tue Jul  6 07:44:37 2010
New Revision: 960835

URL: http://svn.apache.org/viewvc?rev=960835&view=rev
Log:
[AMBER-4] - added hashCode and equals methods

Added:
    incubator/amber/trunk/server/src/test/java/org/apache/amber/server/AccessTest.java   (with
props)
Modified:
    incubator/amber/trunk/server/src/main/java/org/apache/amber/server/Access.java

Modified: incubator/amber/trunk/server/src/main/java/org/apache/amber/server/Access.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/server/src/main/java/org/apache/amber/server/Access.java?rev=960835&r1=960834&r2=960835&view=diff
==============================================================================
--- incubator/amber/trunk/server/src/main/java/org/apache/amber/server/Access.java (original)
+++ incubator/amber/trunk/server/src/main/java/org/apache/amber/server/Access.java Tue Jul
 6 07:44:37 2010
@@ -99,4 +99,31 @@ public final class Access implements Com
         }
     }
 
+    /**
+     * {@inheritDoc}}
+     */
+    @Override
+    public boolean equals(Object obj) {
+      boolean equals = false;
+      if (obj instanceof Access) {
+        Access other = (Access) obj;
+        if (other.timestamp == this.timestamp && other.nonces.equals(this.nonces))
{
+          equals = true;
+        }
+      }
+      return equals;
+    }
+
+    /**
+     * {@inheritDoc}}
+     */
+    @Override
+    public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((nonces == null) ? 0 : nonces.hashCode());
+      result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
+      return result;
+    }
+
 }

Added: incubator/amber/trunk/server/src/test/java/org/apache/amber/server/AccessTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/server/src/test/java/org/apache/amber/server/AccessTest.java?rev=960835&view=auto
==============================================================================
--- incubator/amber/trunk/server/src/test/java/org/apache/amber/server/AccessTest.java (added)
+++ incubator/amber/trunk/server/src/test/java/org/apache/amber/server/AccessTest.java Tue
Jul  6 07:44:37 2010
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.amber.server;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * @version $Id$
+ */
+public class AccessTest {
+
+  @Test
+  public void matchingEqualsHashTest() {
+    Access access1 = new Access(123456, "313121");
+    Access access2 = new Access(123456, "313121");
+    assertTrue(!access1.equals(null));
+    assertTrue(access1.equals(access2) && access1.hashCode() == access2.hashCode());
+  }
+
+  @Test
+  public void notMatchingEqualsHashTest() {
+    Access access1 = new Access(123456, "313121");
+    Access access2 = new Access(123446, "313121");
+    Access access3 = new Access(123456, "313122");
+    Access access4 = new Access(123456, "313121");
+    access4.addNonce("313122");
+    assertTrue(!access1.equals(access2) && access1.hashCode() != access2.hashCode());
+    assertTrue(!access1.equals(access3) && access1.hashCode() != access3.hashCode());
+    assertTrue(!access1.equals(access4) && access1.hashCode() != access4.hashCode());
+  }
+
+}

Propchange: incubator/amber/trunk/server/src/test/java/org/apache/amber/server/AccessTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/amber/trunk/server/src/test/java/org/apache/amber/server/AccessTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/amber/trunk/server/src/test/java/org/apache/amber/server/AccessTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message