directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r947147 - in /directory/apacheds/trunk: core-api/src/main/java/org/apache/directory/server/core/changelog/ core-api/src/main/java/org/apache/directory/server/core/entry/ core-api/src/test/java/org/apache/directory/server/core/changelog/ cor...
Date Fri, 21 May 2010 19:55:26 GMT
Author: felixk
Date: Fri May 21 19:55:26 2010
New Revision: 947147

URL: http://svn.apache.org/viewvc?rev=947147&view=rev
Log:
- Override hashCode when overriding equals
- Adding simple testcases

Added:
    directory/apacheds/trunk/jdbm/src/test/java/jdbm/recman/
    directory/apacheds/trunk/jdbm/src/test/java/jdbm/recman/LocationTest.java   (with props)
    directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/
    directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java
  (with props)
Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/Tag.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java
    directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/changelog/TagTest.java
    directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/ClonedServerEntryTest.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/Location.java
    directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/Checksum.java
    directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKey.java
    directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddress.java
    directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/ChecksumTest.java
    directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKeyTest.java
    directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java
    directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/NtpTimeStamp.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/Tag.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/Tag.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/Tag.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/Tag.java
Fri May 21 19:55:26 2010
@@ -103,6 +103,27 @@ public class Tag
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( description != null )
+        {
+            hash = hash * 17 + description.hashCode();
+        }
+        hash = hash * 17 + Long.valueOf( revision ).hashCode();
+        
+        return hash;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public boolean equals( Object other )
     {
         if ( other instanceof Tag )

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java
Fri May 21 19:55:26 2010
@@ -452,8 +452,18 @@ public class ClonedServerEntry implement
     
     
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        return 703;
+    }
+
+    /**
      * @see Object#equals(Object);
      */
+    @Override
     public boolean equals( Object obj )
     {
         // Short circuit

Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/changelog/TagTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/changelog/TagTest.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/changelog/TagTest.java
(original)
+++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/changelog/TagTest.java
Fri May 21 19:55:26 2010
@@ -93,7 +93,6 @@ public class TagTest
 
 
     @Test
-    @Ignore
     public void testHashCodeSymmetric() throws Exception
     {
         assertEquals( tagA.hashCode(), tagACopy.hashCode() );
@@ -111,7 +110,6 @@ public class TagTest
 
 
     @Test
-    @Ignore
     public void testHashCodeTransitive() throws Exception
     {
         assertEquals( tagA.hashCode(), tagACopy.hashCode() );

Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/ClonedServerEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/ClonedServerEntryTest.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/ClonedServerEntryTest.java
(original)
+++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/ClonedServerEntryTest.java
Fri May 21 19:55:26 2010
@@ -104,7 +104,6 @@ public class ClonedServerEntryTest
 
 
     @Test
-    @Ignore
     public void testHashCodeSymmetric() throws Exception
     {
         assertEquals( clonedServerEntryA.hashCode(), clonedServerEntryACopy.hashCode() );
@@ -127,7 +126,6 @@ public class ClonedServerEntryTest
 
 
     @Test
-    @Ignore
     public void testHashCodeTransitive() throws Exception
     {
         assertEquals( clonedServerEntryA.hashCode(), clonedServerEntryACopy.hashCode() );

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/Location.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/Location.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/Location.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/Location.java Fri May 21 19:55:26
2010
@@ -118,12 +118,20 @@ final class Location 
     }
 
     
-    // -----------------------------------------------------------------------
-    // java.lang.Object Overrides
-    // -----------------------------------------------------------------------
- 
-    
-    public boolean equals( Object o ) 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        return 663;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+   public boolean equals( Object o ) 
     {
         if ( o == null || ! ( o instanceof Location ) )
         {

Added: directory/apacheds/trunk/jdbm/src/test/java/jdbm/recman/LocationTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/test/java/jdbm/recman/LocationTest.java?rev=947147&view=auto
==============================================================================
--- directory/apacheds/trunk/jdbm/src/test/java/jdbm/recman/LocationTest.java (added)
+++ directory/apacheds/trunk/jdbm/src/test/java/jdbm/recman/LocationTest.java Fri May 21 19:55:26
2010
@@ -0,0 +1,146 @@
+/*
+ *  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 jdbm.recman;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+/**
+ * Unit tests class LocationEntry.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class LocationTest
+{
+    Location clonedServerEntryA;
+    Location clonedServerEntryACopy;
+    Location clonedServerEntryB;
+    Location clonedServerEntryC;
+    Location clonedServerEntryA1;
+    Location clonedServerEntryACopy1;
+    Location clonedServerEntryB1;
+    Location clonedServerEntryC1;
+    Location clonedServerEntryD1;
+
+
+    /**
+     * Initialize name instances
+     */
+    @Before
+    public void initNames() throws Exception
+    {
+        clonedServerEntryA = new Location( 1L );
+        clonedServerEntryACopy = new Location( 1L );
+        clonedServerEntryB = new Location( 1L );
+        clonedServerEntryC = new Location( 2L );
+        clonedServerEntryA1 = new Location( 1L, ( short ) 1 );
+        clonedServerEntryACopy1 = new Location( 1L, ( short ) 1 );
+        clonedServerEntryB1 = new Location( 1L, ( short ) 1 );
+        clonedServerEntryC1 = new Location( 1L, ( short ) 2 );
+        clonedServerEntryD1 = new Location( 2L, ( short ) 1 );
+    }
+
+
+    @Test
+    public void testEqualsNull() throws Exception
+    {
+        assertFalse( clonedServerEntryA.equals( null ) );
+        assertFalse( clonedServerEntryA1.equals( null ) );
+    }
+
+
+    @Test
+    public void testEqualsReflexive() throws Exception
+    {
+        assertEquals( clonedServerEntryA, clonedServerEntryA );
+        assertEquals( clonedServerEntryA1, clonedServerEntryA1 );
+    }
+
+
+    @Test
+    public void testHashCodeReflexive() throws Exception
+    {
+        assertEquals( clonedServerEntryA.hashCode(), clonedServerEntryA.hashCode() );
+        assertEquals( clonedServerEntryA1.hashCode(), clonedServerEntryA1.hashCode() );
+    }
+
+
+    @Test
+    public void testEqualsSymmetric() throws Exception
+    {
+        assertEquals( clonedServerEntryA, clonedServerEntryACopy );
+        assertEquals( clonedServerEntryACopy, clonedServerEntryA );
+        assertEquals( clonedServerEntryA1, clonedServerEntryACopy1 );
+        assertEquals( clonedServerEntryACopy1, clonedServerEntryA1 );
+    }
+
+
+    @Test
+    @Ignore
+    public void testHashCodeSymmetric() throws Exception
+    {
+        assertEquals( clonedServerEntryA.hashCode(), clonedServerEntryACopy.hashCode() );
+        assertEquals( clonedServerEntryACopy.hashCode(), clonedServerEntryA.hashCode() );
+        assertEquals( clonedServerEntryA1.hashCode(), clonedServerEntryACopy1.hashCode()
);
+        assertEquals( clonedServerEntryACopy1.hashCode(), clonedServerEntryA1.hashCode()
);
+    }
+
+
+    @Test
+    public void testEqualsTransitive() throws Exception
+    {
+        assertEquals( clonedServerEntryA, clonedServerEntryACopy );
+        assertEquals( clonedServerEntryACopy, clonedServerEntryB );
+        assertEquals( clonedServerEntryA, clonedServerEntryB );
+        assertEquals( clonedServerEntryA1, clonedServerEntryACopy1 );
+        assertEquals( clonedServerEntryACopy1, clonedServerEntryB1 );
+        assertEquals( clonedServerEntryA1, clonedServerEntryB1 );
+    }
+
+
+    @Test
+    @Ignore
+    public void testHashCodeTransitive() throws Exception
+    {
+        assertEquals( clonedServerEntryA.hashCode(), clonedServerEntryACopy.hashCode() );
+        assertEquals( clonedServerEntryACopy.hashCode(), clonedServerEntryB.hashCode() );
+        assertEquals( clonedServerEntryA.hashCode(), clonedServerEntryB.hashCode() );
+        assertEquals( clonedServerEntryA1.hashCode(), clonedServerEntryACopy1.hashCode()
);
+        assertEquals( clonedServerEntryACopy1.hashCode(), clonedServerEntryB1.hashCode()
);
+        assertEquals( clonedServerEntryA1.hashCode(), clonedServerEntryB1.hashCode() );
+    }
+
+
+    @Test
+    public void testNotEqualDiffValue() throws Exception
+    {
+        assertFalse( clonedServerEntryA1.equals( clonedServerEntryC1 ) );
+        assertFalse( clonedServerEntryC1.equals( clonedServerEntryA1 ) );
+        assertFalse( clonedServerEntryA1.equals( clonedServerEntryD1 ) );
+        assertFalse( clonedServerEntryD1.equals( clonedServerEntryA1 ) );
+    }
+}

Propchange: directory/apacheds/trunk/jdbm/src/test/java/jdbm/recman/LocationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/apacheds/trunk/jdbm/src/test/java/jdbm/recman/LocationTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/Checksum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/Checksum.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/Checksum.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/Checksum.java
Fri May 21 19:55:26 2010
@@ -90,8 +90,23 @@ public class Checksum extends AbstractAs
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        hash = hash * 17 + cksumtype.hashCode();
+        hash = hash * 17 + Arrays.hashCode( checksum );
+        
+        return hash;
+    }
+
+
+    /**
      * @see Object#equals(Object)
      */
+    @Override
     public boolean equals( Object o )
     {
         if ( this == o )

Modified: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKey.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKey.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKey.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKey.java
Fri May 21 19:55:26 2010
@@ -184,8 +184,23 @@ public class EncryptionKey extends Abstr
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        hash = hash * 17 + keyType.hashCode();
+        hash = hash * 17 + Arrays.hashCode( keyValue );
+        
+        return hash;
+    }
+
+
+    /**
      * @see Object#equals(Object)
      */
+    @Override
     public boolean equals( Object o )
     {
         if ( this == o )

Modified: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddress.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddress.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddress.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddress.java
Fri May 21 19:55:26 2010
@@ -24,6 +24,7 @@ import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.kerberos.shared.messages.value.types.HostAddrType;
@@ -111,11 +112,29 @@ public class HostAddress extends Abstrac
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        hash = hash * 17 + addrType.hashCode();
+        if ( address != null )
+        {
+            hash = hash * 17 + Arrays.hashCode( address );
+        }
+        
+        return hash;
+    }
+
+
+    /**
      * Returns whether one {@link HostAddress} is equal to another.
      *
      * @param that The {@link HostAddress} to compare with
      * @return true if the {@link HostAddress}'s are equal.
      */
+    @Override
     public boolean equals( Object that )
     {
         if ( this == that )

Modified: directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/ChecksumTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/ChecksumTest.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/ChecksumTest.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/ChecksumTest.java
Fri May 21 19:55:26 2010
@@ -20,12 +20,17 @@
 package org.apache.directory.server.kerberos.shared.messages.value;
 
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 
 import org.apache.directory.server.kerberos.shared.crypto.checksum.ChecksumType;
+import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
-import static org.junit.Assert.assertTrue;
 
 
 /**
@@ -36,6 +41,33 @@ import static org.junit.Assert.assertTru
  */
 public class ChecksumTest
 {
+    Checksum checksumA;
+    Checksum checksumACopy;
+    Checksum checksumB;
+    Checksum checksumC;
+    Checksum checksumD;
+
+    byte[] checksumValueA = { ( byte ) 0x30, ( byte ) 0x1A, ( byte ) 0xA0, ( byte ) 0x11,
( byte ) 0x18, ( byte ) 0x0F, ( byte ) 0x32,
+        ( byte ) 0x30 };
+    byte[] checksumValueB = { ( byte ) 0x30, ( byte ) 0x1A, ( byte ) 0xA0, ( byte ) 0x11,
( byte ) 0x18, ( byte ) 0x0F, ( byte ) 0x32,
+        ( byte ) 0x30 };
+    byte[] checksumValueC = { ( byte ) 0x30, ( byte ) 0x1B, ( byte ) 0xA0, ( byte ) 0x11,
( byte ) 0x18, ( byte ) 0x0F, ( byte ) 0x32,
+        ( byte ) 0x30 };
+    
+    /**
+     * Initialize name instances
+     */
+    @Before
+    public void initNames() throws Exception
+    {
+        checksumA = new Checksum ( ChecksumType.RSA_MD5, checksumValueA );
+        checksumACopy = new Checksum ( ChecksumType.RSA_MD5, checksumValueA );
+        checksumB = new Checksum ( ChecksumType.RSA_MD5, checksumValueB );
+        checksumC = new Checksum ( ChecksumType.RSA_MD5, checksumValueC );
+        checksumD = new Checksum ( ChecksumType.RSA_MD4, checksumValueA );
+
+    }
+    
     @Test
     public void testEncodingChecksum() throws Exception
     {
@@ -82,19 +114,69 @@ public class ChecksumTest
     }
 
 
-    /**
-     * Tests that two Checksums are equal if both their type and value are equal.
-     */
     @Test
-    public void testEquality()
+    public void testEqualsNull() throws Exception
+    {
+        assertFalse( checksumA.equals( null ) );
+    }
+
+
+    @Test
+    public void testEqualsReflexive() throws Exception
     {
-        byte[] checksumValue =
-            { ( byte ) 0x30, ( byte ) 0x1A, ( byte ) 0xA0, ( byte ) 0x11, ( byte ) 0x18,
( byte ) 0x0F, ( byte ) 0x32,
-                ( byte ) 0x30 };
+        assertEquals( checksumA, checksumA );
+    }
 
-        Checksum expected = new Checksum( ChecksumType.RSA_MD5, checksumValue );
-        Checksum provided = new Checksum( ChecksumType.RSA_MD5, checksumValue );
 
-        assertTrue( "Checksum equality", expected.equals( provided ) );
+    @Test
+    public void testHashCodeReflexive() throws Exception
+    {
+        assertEquals( checksumA.hashCode(), checksumA.hashCode() );
+    }
+
+
+    @Test
+    public void testEqualsSymmetric() throws Exception
+    {
+        assertEquals( checksumA, checksumACopy );
+        assertEquals( checksumACopy, checksumA );
+    }
+
+
+    @Test
+    @Ignore
+    public void testHashCodeSymmetric() throws Exception
+    {
+        assertEquals( checksumA.hashCode(), checksumACopy.hashCode() );
+        assertEquals( checksumACopy.hashCode(), checksumA.hashCode() );
+    }
+
+
+    @Test
+    public void testEqualsTransitive() throws Exception
+    {
+        assertEquals( checksumA, checksumACopy );
+        assertEquals( checksumACopy, checksumB );
+        assertEquals( checksumA, checksumB );
+    }
+
+
+    @Test
+    @Ignore
+    public void testHashCodeTransitive() throws Exception
+    {
+        assertEquals( checksumA.hashCode(), checksumACopy.hashCode() );
+        assertEquals( checksumACopy.hashCode(), checksumB.hashCode() );
+        assertEquals( checksumA.hashCode(), checksumB.hashCode() );
+    }
+
+
+    @Test
+    public void testNotEqualDiffValue() throws Exception
+    {
+        assertFalse( checksumA.equals( checksumC ) );
+        assertFalse( checksumC.equals( checksumA ) );
+        assertFalse( checksumA.equals( checksumD ) );
+        assertFalse( checksumD.equals( checksumA ) );
     }
 }

Modified: directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKeyTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKeyTest.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKeyTest.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKeyTest.java
Fri May 21 19:55:26 2010
@@ -27,7 +27,12 @@ import java.util.Arrays;
 import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
 import org.apache.directory.server.kerberos.shared.io.encoder.EncryptionKeyEncoder;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 /**
@@ -38,6 +43,32 @@ import static org.junit.Assert.assertTru
  */
 public class EncryptionKeyTest
 {
+    EncryptionKey encryptionA;
+    EncryptionKey encryptionACopy;
+    EncryptionKey encryptionB;
+    EncryptionKey encryptionC;
+    EncryptionKey encryptionD;
+
+    byte[] encryptionValueA = { 0x01, 0x02, 0x03 };
+    byte[] encryptionValueB = { 0x01, 0x02, 0x03 };
+    byte[] encryptionValueC = { 0x01, 0x02, 0x04 };
+
+    
+    /**
+     * Initialize name instances
+     */
+    @Before
+    public void initNames() throws Exception
+    {
+        encryptionA = new EncryptionKey ( EncryptionType.AES128_CTS_HMAC_SHA1_96, encryptionValueA
);
+        encryptionACopy = new EncryptionKey ( EncryptionType.AES128_CTS_HMAC_SHA1_96, encryptionValueA
);
+        encryptionB = new EncryptionKey ( EncryptionType.AES128_CTS_HMAC_SHA1_96, encryptionValueB
);
+        encryptionC = new EncryptionKey ( EncryptionType.AES128_CTS_HMAC_SHA1_96, encryptionValueC
);
+        encryptionD = new EncryptionKey ( EncryptionType.AES256_CTS_HMAC_SHA1_96, encryptionValueA
);
+
+    }
+
+    
     @Test
     public void testEncodingFast() throws Exception
     {
@@ -165,4 +196,71 @@ public class EncryptionKeyTest
 
         System.out.println( "Delta2 = " + ( t1 - t0 ) );
     }
+
+
+    @Test
+    public void testEqualsNull() throws Exception
+    {
+        assertFalse( encryptionA.equals( null ) );
+    }
+
+
+    @Test
+    public void testEqualsReflexive() throws Exception
+    {
+        assertEquals( encryptionA, encryptionA );
+    }
+
+
+    @Test
+    public void testHashCodeReflexive() throws Exception
+    {
+        assertEquals( encryptionA.hashCode(), encryptionA.hashCode() );
+    }
+
+
+    @Test
+    public void testEqualsSymmetric() throws Exception
+    {
+        assertEquals( encryptionA, encryptionACopy );
+        assertEquals( encryptionACopy, encryptionA );
+    }
+
+
+    @Test
+    @Ignore
+    public void testHashCodeSymmetric() throws Exception
+    {
+        assertEquals( encryptionA.hashCode(), encryptionACopy.hashCode() );
+        assertEquals( encryptionACopy.hashCode(), encryptionA.hashCode() );
+    }
+
+
+    @Test
+    public void testEqualsTransitive() throws Exception
+    {
+        assertEquals( encryptionA, encryptionACopy );
+        assertEquals( encryptionACopy, encryptionB );
+        assertEquals( encryptionA, encryptionB );
+    }
+
+
+    @Test
+    @Ignore
+    public void testHashCodeTransitive() throws Exception
+    {
+        assertEquals( encryptionA.hashCode(), encryptionACopy.hashCode() );
+        assertEquals( encryptionACopy.hashCode(), encryptionB.hashCode() );
+        assertEquals( encryptionA.hashCode(), encryptionB.hashCode() );
+    }
+
+
+    @Test
+    public void testNotEqualDiffValue() throws Exception
+    {
+        assertFalse( encryptionA.equals( encryptionC ) );
+        assertFalse( encryptionC.equals( encryptionA ) );
+        assertFalse( encryptionA.equals( encryptionD ) );
+        assertFalse( encryptionD.equals( encryptionA ) );
+    }
 }

Modified: directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java
Fri May 21 19:55:26 2010
@@ -20,12 +20,17 @@
 package org.apache.directory.server.kerberos.shared.messages.value;
 
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 
 import org.apache.directory.server.kerberos.shared.messages.value.types.HostAddrType;
+import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
-import static org.junit.Assert.assertTrue;
 
 /**
  * Test the HostAddress encoding and decoding
@@ -35,15 +40,39 @@ import static org.junit.Assert.assertTru
  */
 public class HostAddressTest
 {
+    HostAddress hostAddressA;
+    HostAddress hostAddressACopy;
+    HostAddress hostAddressB;
+    HostAddress hostAddressC;
+    HostAddress hostAddressD;
+
+    
+    /**
+     * Initialize name instances
+     */
+    @Before
+    public void initNames() throws Exception
+    {
+        hostAddressA = new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
+                                                                            { 0x01, 0x02,
0x03, 0x04 } );
+        hostAddressACopy = new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
+                                                                                { 0x01, 0x02,
0x03, 0x04 } );
+        hostAddressB = new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
+                                                                            { 0x01, 0x02,
0x03, 0x04 } );
+        hostAddressC = new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
+                                                                            { 0x01, 0x02,
0x03, 0x05 } );
+        hostAddressD = new HostAddress( HostAddrType.ADDRTYPE_CHAOS, new byte[]
+                                                                            { 0x01, 0x02,
0x03, 0x04 } );
+
+    }
+
+    
     @Test
     public void testEncodingHostAddressIP() throws Exception
     {
-        HostAddress ha = new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
-            { 0x01, 0x02, 0x03, 0x04 } );
+        ByteBuffer encoded = ByteBuffer.allocate( hostAddressA.computeLength() );
 
-        ByteBuffer encoded = ByteBuffer.allocate( ha.computeLength() );
-
-        ha.encode( encoded );
+        hostAddressA.encode( encoded );
 
         byte[] expectedResult = new byte[]
             { 
@@ -79,4 +108,71 @@ public class HostAddressTest
 
         assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
     }
+
+
+    @Test
+    public void testEqualsNull() throws Exception
+    {
+        assertFalse( hostAddressA.equals( null ) );
+    }
+
+
+    @Test
+    public void testEqualsReflexive() throws Exception
+    {
+        assertEquals( hostAddressA, hostAddressA );
+    }
+
+
+    @Test
+    public void testHashCodeReflexive() throws Exception
+    {
+        assertEquals( hostAddressA.hashCode(), hostAddressA.hashCode() );
+    }
+
+
+    @Test
+    public void testEqualsSymmetric() throws Exception
+    {
+        assertEquals( hostAddressA, hostAddressACopy );
+        assertEquals( hostAddressACopy, hostAddressA );
+    }
+
+
+    @Test
+    @Ignore
+    public void testHashCodeSymmetric() throws Exception
+    {
+        assertEquals( hostAddressA.hashCode(), hostAddressACopy.hashCode() );
+        assertEquals( hostAddressACopy.hashCode(), hostAddressA.hashCode() );
+    }
+
+
+    @Test
+    public void testEqualsTransitive() throws Exception
+    {
+        assertEquals( hostAddressA, hostAddressACopy );
+        assertEquals( hostAddressACopy, hostAddressB );
+        assertEquals( hostAddressA, hostAddressB );
+    }
+
+
+    @Test
+    @Ignore
+    public void testHashCodeTransitive() throws Exception
+    {
+        assertEquals( hostAddressA.hashCode(), hostAddressACopy.hashCode() );
+        assertEquals( hostAddressACopy.hashCode(), hostAddressB.hashCode() );
+        assertEquals( hostAddressA.hashCode(), hostAddressB.hashCode() );
+    }
+
+
+    @Test
+    public void testNotEqualDiffValue() throws Exception
+    {
+        assertFalse( hostAddressA.equals( hostAddressC ) );
+        assertFalse( hostAddressC.equals( hostAddressA ) );
+        assertFalse( hostAddressA.equals( hostAddressD ) );
+        assertFalse( hostAddressD.equals( hostAddressA ) );
+    }
 }

Modified: directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/NtpTimeStamp.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/NtpTimeStamp.java?rev=947147&r1=947146&r2=947147&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/NtpTimeStamp.java
(original)
+++ directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/NtpTimeStamp.java
Fri May 21 19:55:26 2010
@@ -137,6 +137,24 @@ public class NtpTimeStamp
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        hash = hash * 17 + Long.valueOf( seconds ).hashCode();
+        hash = hash * 17 + Long.valueOf( fraction ).hashCode();
+        
+        return hash;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public boolean equals( Object o )
     {
         if ( this == o )

Added: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java?rev=947147&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java
(added)
+++ directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java
Fri May 21 19:55:26 2010
@@ -0,0 +1,143 @@
+/*
+ *  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.directory.server.ntp.messages;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.util.Date;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+/**
+ * Unit tests class NtpTimeStamp.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class NtpTimeStampTest
+{
+    NtpTimeStamp ntpTimeStampA;
+    NtpTimeStamp ntpTimeStampACopy;
+    NtpTimeStamp ntpTimeStampB;
+    NtpTimeStamp ntpTimeStampA1;
+    NtpTimeStamp ntpTimeStampACopy1;
+    NtpTimeStamp ntpTimeStampB1;
+    NtpTimeStamp ntpTimeStampC1;
+
+
+    /**
+     * Initialize name instances
+     */
+    @Before
+    public void initNames() throws Exception
+    {
+        ntpTimeStampA = new NtpTimeStamp();
+        ntpTimeStampACopy = new NtpTimeStamp();
+        ntpTimeStampB = new NtpTimeStamp();
+        Date date = new Date( 1L );
+        ntpTimeStampA1 = new NtpTimeStamp( date );
+        ntpTimeStampACopy1 = new NtpTimeStamp( date );
+        ntpTimeStampB1 = new NtpTimeStamp( date );
+        ntpTimeStampC1 = new NtpTimeStamp( new Date( 2L ) );
+    }
+
+
+    @Test
+    public void testEqualsNull() throws Exception
+    {
+        assertFalse( ntpTimeStampA.equals( null ) );
+        assertFalse( ntpTimeStampA1.equals( null ) );
+    }
+
+
+    @Test
+    public void testEqualsReflexive() throws Exception
+    {
+        assertEquals( ntpTimeStampA, ntpTimeStampA );
+        assertEquals( ntpTimeStampA1, ntpTimeStampA1 );
+    }
+
+
+    @Test
+    public void testHashCodeReflexive() throws Exception
+    {
+        assertEquals( ntpTimeStampA.hashCode(), ntpTimeStampA.hashCode() );
+        assertEquals( ntpTimeStampA1.hashCode(), ntpTimeStampA1.hashCode() );
+    }
+
+
+    @Test
+    public void testEqualsSymmetric() throws Exception
+    {
+        assertEquals( ntpTimeStampA, ntpTimeStampACopy );
+        assertEquals( ntpTimeStampACopy, ntpTimeStampA );
+        assertEquals( ntpTimeStampA1, ntpTimeStampACopy1 );
+        assertEquals( ntpTimeStampACopy1, ntpTimeStampA1 );
+    }
+
+
+    @Test
+    @Ignore
+    public void testHashCodeSymmetric() throws Exception
+    {
+        assertEquals( ntpTimeStampA.hashCode(), ntpTimeStampACopy.hashCode() );
+        assertEquals( ntpTimeStampACopy.hashCode(), ntpTimeStampA.hashCode() );
+        assertEquals( ntpTimeStampA1.hashCode(), ntpTimeStampACopy1.hashCode() );
+        assertEquals( ntpTimeStampACopy1.hashCode(), ntpTimeStampA1.hashCode() );
+    }
+
+
+    @Test
+    public void testEqualsTransitive() throws Exception
+    {
+        assertEquals( ntpTimeStampA, ntpTimeStampACopy );
+        assertEquals( ntpTimeStampACopy, ntpTimeStampB );
+        assertEquals( ntpTimeStampA, ntpTimeStampB );
+        assertEquals( ntpTimeStampA1, ntpTimeStampACopy1 );
+        assertEquals( ntpTimeStampACopy1, ntpTimeStampB1 );
+        assertEquals( ntpTimeStampA1, ntpTimeStampB1 );
+    }
+
+
+    @Test
+    @Ignore
+    public void testHashCodeTransitive() throws Exception
+    {
+        assertEquals( ntpTimeStampA.hashCode(), ntpTimeStampACopy.hashCode() );
+        assertEquals( ntpTimeStampACopy.hashCode(), ntpTimeStampB.hashCode() );
+        assertEquals( ntpTimeStampA.hashCode(), ntpTimeStampB.hashCode() );
+        assertEquals( ntpTimeStampA1.hashCode(), ntpTimeStampACopy1.hashCode() );
+        assertEquals( ntpTimeStampACopy1.hashCode(), ntpTimeStampB1.hashCode() );
+        assertEquals( ntpTimeStampA1.hashCode(), ntpTimeStampB1.hashCode() );
+    }
+
+
+    @Test
+    public void testNotEqualDiffValue() throws Exception
+    {
+        assertFalse( ntpTimeStampA1.equals( ntpTimeStampC1 ) );
+        assertFalse( ntpTimeStampC1.equals( ntpTimeStampA1 ) );
+    }
+}

Propchange: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message