directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r944692 - in /directory/apacheds/trunk/xdbm-base/src/test: ./ java/ java/org/ java/org/apache/ java/org/apache/directory/ java/org/apache/directory/server/ java/org/apache/directory/server/xdbm/
Date Sat, 15 May 2010 18:08:03 GMT
Author: seelmann
Date: Sat May 15 18:08:03 2010
New Revision: 944692

URL: http://svn.apache.org/viewvc?rev=944692&view=rev
Log:
Added some tests

Added:
    directory/apacheds/trunk/xdbm-base/src/test/
    directory/apacheds/trunk/xdbm-base/src/test/java/
    directory/apacheds/trunk/xdbm-base/src/test/java/org/
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/AbstractIndexCursorTest.java
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/EmptyIndexCursorTest.java
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/ForwardIndexEntryTest.java
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/GenericIndexTest.java
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/IndexNotFoundExceptionTest.java
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/ReverseIndexEntryTest.java
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/SingletonIndexCursorTest.java
    directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/TupleTest.java

Added: directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/AbstractIndexCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/AbstractIndexCursorTest.java?rev=944692&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/AbstractIndexCursorTest.java (added)
+++ directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/AbstractIndexCursorTest.java Sat May 15 18:08:03 2010
@@ -0,0 +1,122 @@
+/*
+ *  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.xdbm;
+
+
+import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+
+import org.apache.directory.shared.ldap.cursor.CursorClosedException;
+import org.apache.directory.shared.ldap.cursor.DefaultClosureMonitor;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Tests the {@link AbstractIndexCursor} class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AbstractIndexCursorTest
+{
+
+    private AbstractIndexCursor<String, Entry, Long> indexCursor;
+
+
+    @Before
+    public void setUp()
+    {
+        indexCursor = new EmptyIndexCursor<String, Entry, Long>();
+    }
+
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testSetClosureMonitorNull()
+    {
+        indexCursor.setClosureMonitor( null );
+    }
+
+
+    @Test
+    public void testSetClosureMonitor()
+    {
+        indexCursor.setClosureMonitor( new DefaultClosureMonitor() );
+    }
+
+
+    @Test
+    public void testCheckNotClosedIfNotClosed() throws Exception
+    {
+        indexCursor.checkNotClosed( "test" );
+    }
+
+
+    @Test(expected = CursorClosedException.class)
+    public void testCheckNotClosedIfClosed() throws Exception
+    {
+        indexCursor.close();
+        indexCursor.checkNotClosed( "test" );
+    }
+
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCheckNotClosedIfClosedWithCustomException() throws Exception
+    {
+        indexCursor.close( new IllegalArgumentException() );
+        indexCursor.checkNotClosed( "test" );
+    }
+
+
+    @Test
+    public void testIsClosed() throws Exception
+    {
+        assertFalse( indexCursor.isClosed() );
+        indexCursor.close();
+        assertTrue( indexCursor.isClosed() );
+    }
+
+
+    @Test
+    public void testClose() throws Exception
+    {
+        indexCursor.close();
+    }
+
+
+    @Test
+    public void testCloseException() throws Exception
+    {
+        indexCursor.close( new IllegalArgumentException() );
+    }
+
+
+    @Test
+    public void testIterator()
+    {
+        Iterator<IndexEntry<String, Entry, Long>> iterator = indexCursor.iterator();
+        assertNotNull( iterator );
+    }
+
+}

Added: directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/EmptyIndexCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/EmptyIndexCursorTest.java?rev=944692&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/EmptyIndexCursorTest.java (added)
+++ directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/EmptyIndexCursorTest.java Sat May 15 18:08:03 2010
@@ -0,0 +1,204 @@
+/*
+ *  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.xdbm;
+
+
+import static junit.framework.Assert.assertFalse;
+
+import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Tests the {@link EmptyIndexCursor} class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EmptyIndexCursorTest
+{
+
+    private EmptyIndexCursor<String, Entry, Long> indexCursor;
+
+
+    @Before
+    public void setUp()
+    {
+        indexCursor = new EmptyIndexCursor<String, Entry, Long>();
+    }
+
+
+    @Test
+    public void testConstructor()
+    {
+        new EmptyIndexCursor<String, Entry, Long>();
+    }
+
+
+    @Test(expected = InvalidCursorPositionException.class)
+    public void testGet() throws Exception
+    {
+        indexCursor.get();
+    }
+
+
+    @Test(expected = InvalidCursorPositionException.class)
+    public void testGetBeforeFirst() throws Exception
+    {
+        indexCursor.beforeFirst();
+        indexCursor.get();
+    }
+
+
+    @Test(expected = InvalidCursorPositionException.class)
+    public void testGetAfterLast() throws Exception
+    {
+        indexCursor.afterLast();
+        indexCursor.get();
+    }
+
+
+    @Test
+    public void testIsElementReused() throws Exception
+    {
+        assertFalse( indexCursor.isElementReused() );
+    }
+
+
+    @Test
+    public void testBeforeFirst() throws Exception
+    {
+        indexCursor.beforeFirst();
+    }
+
+
+    @Test
+    public void testAfterLast() throws Exception
+    {
+        indexCursor.afterLast();
+    }
+
+
+    @Test
+    public void testFirst() throws Exception
+    {
+        assertFalse( indexCursor.first() );
+    }
+
+
+    @Test
+    public void testLast() throws Exception
+    {
+        assertFalse( indexCursor.last() );
+    }
+
+
+    @Test
+    public void testAvailable() throws Exception
+    {
+        assertFalse( indexCursor.available() );
+    }
+
+
+    @Test
+    public void testNext() throws Exception
+    {
+        // not explicitly positioned, implicit before first 
+        assertFalse( indexCursor.next() );
+
+        // position before first
+        indexCursor.beforeFirst();
+        assertFalse( indexCursor.next() );
+
+        // position first
+        indexCursor.first();
+        assertFalse( indexCursor.next() );
+
+        // position last
+        indexCursor.last();
+        assertFalse( indexCursor.next() );
+
+        // position after first
+        indexCursor.afterLast();
+        assertFalse( indexCursor.next() );
+    }
+
+
+    @Test
+    public void testPrevious() throws Exception
+    {
+        // not positioned
+        assertFalse( indexCursor.previous() );
+
+        // position before first
+        indexCursor.beforeFirst();
+        assertFalse( indexCursor.previous() );
+
+        // position first
+        indexCursor.first();
+        assertFalse( indexCursor.previous() );
+
+        // position last
+        indexCursor.last();
+        assertFalse( indexCursor.previous() );
+
+        // position after first
+        indexCursor.afterLast();
+        assertFalse( indexCursor.previous() );
+    }
+
+
+    @Test
+    public void testBefore() throws Exception
+    {
+        indexCursor.before( null );
+    }
+
+
+    @Test
+    public void testBeforeValue() throws Exception
+    {
+        indexCursor.beforeValue( 1L, "test" );
+    }
+
+
+    @Test
+    public void testAfter() throws Exception
+    {
+        indexCursor.after( null );
+    }
+
+
+    @Test
+    public void testAfterValue() throws Exception
+    {
+        indexCursor.afterValue( 1L, "test" );
+    }
+
+
+    @Test
+    public void testClose() throws Exception
+    {
+        indexCursor.close();
+    }
+
+}

Added: directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/ForwardIndexEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/ForwardIndexEntryTest.java?rev=944692&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/ForwardIndexEntryTest.java (added)
+++ directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/ForwardIndexEntryTest.java Sat May 15 18:08:03 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.xdbm;
+
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Tests the {@link ForwardIndexEntry} class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ForwardIndexEntryTest
+{
+
+    private ForwardIndexEntry<String, Entry, Long> indexEntry;
+
+
+    @Before
+    public void setUp()
+    {
+        indexEntry = new ForwardIndexEntry<String, Entry, Long>();
+    }
+
+
+    @Test
+    public void testSetGetId()
+    {
+        assertNull( indexEntry.getId() );
+
+        indexEntry.setId( 1L );
+        assertEquals( Long.valueOf( 1L ), indexEntry.getId() );
+    }
+
+
+    @Test
+    public void testSetGetValue()
+    {
+        assertNull( indexEntry.getValue() );
+
+        indexEntry.setValue( "test" );
+        assertEquals( "test", indexEntry.getValue() );
+    }
+
+
+    @Test
+    public void testSetGetObject()
+    {
+        assertNull( indexEntry.getObject() );
+
+        indexEntry.setObject( new DefaultEntry() );
+        assertEquals( new DefaultEntry(), indexEntry.getObject() );
+    }
+
+
+    @Test
+    public void testSetGetTuple()
+    {
+        assertNotNull( indexEntry.getTuple() );
+        assertNull( indexEntry.getTuple().getKey() );
+        assertNull( indexEntry.getTuple().getValue() );
+
+        indexEntry.setTuple( new Tuple<String, Long>( "a", 1L ), new DefaultEntry() );
+        assertEquals( new Tuple<String, Long>( "a", 1L ), indexEntry.getTuple() );
+        assertEquals( new DefaultEntry(), indexEntry.getObject() );
+    }
+
+
+    @Test
+    public void testClear()
+    {
+        indexEntry.setTuple( new Tuple<String, Long>( "a", 1L ), new DefaultEntry() );
+        indexEntry.clear();
+
+        assertNull( indexEntry.getId() );
+        assertNull( indexEntry.getValue() );
+        assertNull( indexEntry.getObject() );
+        assertNotNull( indexEntry.getTuple() );
+        assertNull( indexEntry.getTuple().getKey() );
+        assertNull( indexEntry.getTuple().getValue() );
+    }
+
+
+    @Test
+    public void testCopy()
+    {
+        // prepare index entry
+        indexEntry.setTuple( new Tuple<String, Long>( "a", 1L ), new DefaultEntry() );
+
+        // create empty index entry and assert empty values
+        ForwardIndexEntry<String, Entry, Long> indexEntry2 = new ForwardIndexEntry<String, Entry, Long>();
+        assertNull( indexEntry2.getId() );
+        assertNull( indexEntry2.getValue() );
+        assertNull( indexEntry2.getObject() );
+        assertNotNull( indexEntry2.getTuple() );
+        assertNull( indexEntry2.getTuple().getKey() );
+        assertNull( indexEntry2.getTuple().getValue() );
+
+        // copy values and assert non-empty values
+        indexEntry2.copy( indexEntry );
+        assertEquals( Long.valueOf( 1L ), indexEntry2.getId() );
+        assertEquals( "a", indexEntry2.getValue() );
+        assertEquals( new DefaultEntry(), indexEntry2.getObject() );
+        assertEquals( new Tuple<String, Long>( "a", 1L ), indexEntry2.getTuple() );
+    }
+
+
+    @Test
+    public void testToString()
+    {
+        indexEntry.setTuple( new Tuple<String, Long>( "asdfghjkl", 1234567890L ), new DefaultEntry() );
+        assertTrue( indexEntry.toString().contains( "asdfghjkl" ) );
+        assertTrue( indexEntry.toString().contains( "1234567890" ) );
+    }
+
+}

Added: directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/GenericIndexTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/GenericIndexTest.java?rev=944692&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/GenericIndexTest.java (added)
+++ directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/GenericIndexTest.java Sat May 15 18:08:03 2010
@@ -0,0 +1,347 @@
+/*
+ *  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.xdbm;
+
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+import static org.junit.Assert.assertFalse;
+
+import java.io.File;
+
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Tests the {@link GenericIndex} class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class GenericIndexTest
+{
+
+    GenericIndex<String, Long, Long> index;
+
+
+    @Before
+    public void setUp()
+    {
+        index = new GenericIndex<String, Long, Long>( "cn", 42, new File( "/tmp" ) );
+    }
+
+
+    @Test
+    public void testConstructor1()
+    {
+        index = new GenericIndex<String, Long, Long>( "cn" );
+        assertEquals( "cn", index.getAttributeId() );
+        assertEquals( GenericIndex.DEFAULT_INDEX_CACHE_SIZE, index.getCacheSize() );
+        assertNull( index.getWkDirPath() );
+    }
+
+
+    @Test
+    public void testConstructor2()
+    {
+        index = new GenericIndex<String, Long, Long>( "cn", 42 );
+        assertEquals( "cn", index.getAttributeId() );
+        assertEquals( 42, index.getCacheSize() );
+        assertNull( index.getWkDirPath() );
+    }
+
+
+    @Test
+    public void testConstructor3()
+    {
+        index = new GenericIndex<String, Long, Long>( "cn", 42, new File( "/tmp" ) );
+        assertEquals( "cn", index.getAttributeId() );
+        assertEquals( 42, index.getCacheSize() );
+        assertNotNull( index.getWkDirPath() );
+        assertEquals( "/tmp", index.getWkDirPath().getPath() );
+    }
+
+
+    @Test
+    public void testSetGetAttributeId()
+    {
+        index.setAttributeId( "sn" );
+        assertEquals( "sn", index.getAttributeId() );
+        index.setAttributeId( null );
+        assertNull( index.getAttributeId() );
+    }
+
+
+    @Test
+    public void testSetGetCacheSize()
+    {
+        index.setCacheSize( 0 );
+        assertEquals( 0, index.getCacheSize() );
+        index.setCacheSize( Integer.MAX_VALUE );
+        assertEquals( Integer.MAX_VALUE, index.getCacheSize() );
+        index.setCacheSize( Integer.MIN_VALUE );
+        assertEquals( Integer.MIN_VALUE, index.getCacheSize() );
+    }
+
+
+    @Test
+    public void testSetGetWkDirPath()
+    {
+        index.setWkDirPath( new File( "/zzz" ) );
+        assertNotNull( index.getWkDirPath() );
+        assertEquals( "/zzz", index.getWkDirPath().getPath() );
+        index.setWkDirPath( null );
+        assertNull( index.getWkDirPath() );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testAdd() throws Exception
+    {
+        index.add( "test", 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testClose() throws Exception
+    {
+        index.close();
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testCount() throws Exception
+    {
+        index.count();
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testCountK() throws Exception
+    {
+        index.count( "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testDropID() throws Exception
+    {
+        index.drop( 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testDropKID() throws Exception
+    {
+        index.drop( "test", 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testForwardCursor() throws Exception
+    {
+        index.forwardCursor();
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testForwardCursorK() throws Exception
+    {
+        index.forwardCursor( "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testForwardLookup() throws Exception
+    {
+        index.forwardLookup( "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testForwardValueCursor() throws Exception
+    {
+        index.forwardValueCursor( "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testForwardK() throws Exception
+    {
+        index.forward( "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testForwardKID() throws Exception
+    {
+        index.forward( "test", 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testReverseID() throws Exception
+    {
+        index.reverse( 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testReverseIDK() throws Exception
+    {
+        index.reverse( 5L, "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testForwardGreaterOrEqK() throws Exception
+    {
+        index.forwardGreaterOrEq( "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testForwardGreaterOrEqKID() throws Exception
+    {
+        index.forwardGreaterOrEq( "test", 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testReverseGreaterOrEqID() throws Exception
+    {
+        index.reverseGreaterOrEq( 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testReverseGreaterOrEqIDK() throws Exception
+    {
+        index.reverseGreaterOrEq( 5L, "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testForwardLessOrEqK() throws Exception
+    {
+        index.forwardLessOrEq( "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testForwardLessOrEqKID() throws Exception
+    {
+        index.forwardLessOrEq( "test", 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testReverseLessOrEqID() throws Exception
+    {
+        index.reverseLessOrEq( 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testReverseLessOrEqIDK() throws Exception
+    {
+        index.reverseLessOrEq( 5L, "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testGetAttribute()
+    {
+        index.getAttribute();
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testGetNormalized() throws Exception
+    {
+        index.getNormalized( "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testGreaterThanCount() throws Exception
+    {
+        index.greaterThanCount( "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testIsCountExact()
+    {
+        index.isCountExact();
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testLessThanCount() throws Exception
+    {
+        index.lessThanCount( "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testReverseCursor() throws Exception
+    {
+        index.reverseCursor();
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testReverseCursorID() throws Exception
+    {
+        index.reverseCursor( 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testReverseLookup() throws Exception
+    {
+        index.reverseLookup( 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testReverseValueCursor() throws Exception
+    {
+        index.reverseValueCursor( 5L );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testSync() throws Exception
+    {
+        index.sync();
+    }
+
+
+    @Test
+    public void testIsDupsEnabled()
+    {
+        assertFalse( index.isDupsEnabled() );
+    }
+
+}

Added: directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/IndexNotFoundExceptionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/IndexNotFoundExceptionTest.java?rev=944692&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/IndexNotFoundExceptionTest.java (added)
+++ directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/IndexNotFoundExceptionTest.java Sat May 15 18:08:03 2010
@@ -0,0 +1,77 @@
+/*
+ *  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.xdbm;
+
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+
+/**
+ * Tests the {@link IndexNotFoundException} class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class IndexNotFoundExceptionTest
+{
+
+    @Test
+    public void testConstructor1()
+    {
+        IndexNotFoundException exception = new IndexNotFoundException( null );
+        assertNull( exception.getIndexName() );
+
+        exception = new IndexNotFoundException( "cn" );
+        assertEquals( "cn", exception.getIndexName() );
+    }
+
+
+    @Test
+    public void testConstructor2()
+    {
+        IndexNotFoundException exception = new IndexNotFoundException( null, null );
+        assertNull( exception.getMessage() );
+        assertNull( exception.getIndexName() );
+
+        exception = new IndexNotFoundException( "message", "cn" );
+        assertEquals( "message", exception.getMessage() );
+        assertEquals( "cn", exception.getIndexName() );
+    }
+
+
+    @Test
+    public void testConstructor3()
+    {
+        IndexNotFoundException exception = new IndexNotFoundException( null, null, null );
+        assertNull( exception.getMessage() );
+        assertNull( exception.getIndexName() );
+        assertNull( exception.getCause() );
+
+        exception = new IndexNotFoundException( "message", "cn", new Exception() );
+        assertEquals( "message", exception.getMessage() );
+        assertEquals( "cn", exception.getIndexName() );
+        assertNotNull( exception.getCause() );
+    }
+
+}

Added: directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/ReverseIndexEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/ReverseIndexEntryTest.java?rev=944692&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/ReverseIndexEntryTest.java (added)
+++ directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/ReverseIndexEntryTest.java Sat May 15 18:08:03 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.xdbm;
+
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Tests the {@link ReverseIndexEntry} class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ReverseIndexEntryTest
+{
+
+    private ReverseIndexEntry<String, Entry, Long> indexEntry;
+
+
+    @Before
+    public void setUp()
+    {
+        indexEntry = new ReverseIndexEntry<String, Entry, Long>();
+    }
+
+
+    @Test
+    public void testSetGetId()
+    {
+        assertNull( indexEntry.getId() );
+
+        indexEntry.setId( 1L );
+        assertEquals( Long.valueOf( 1L ), indexEntry.getId() );
+    }
+
+
+    @Test
+    public void testSetGetValue()
+    {
+        assertNull( indexEntry.getValue() );
+
+        indexEntry.setValue( "test" );
+        assertEquals( "test", indexEntry.getValue() );
+    }
+
+
+    @Test
+    public void testSetGetObject()
+    {
+        assertNull( indexEntry.getObject() );
+
+        indexEntry.setObject( new DefaultEntry() );
+        assertEquals( new DefaultEntry(), indexEntry.getObject() );
+    }
+
+
+    @Test
+    public void testSetGetTuple()
+    {
+        assertNotNull( indexEntry.getTuple() );
+        assertNull( indexEntry.getTuple().getKey() );
+        assertNull( indexEntry.getTuple().getValue() );
+
+        indexEntry.setTuple( new Tuple<Long, String>( 1L, "a" ), new DefaultEntry() );
+        assertEquals( new Tuple<Long, String>( 1L, "a" ), indexEntry.getTuple() );
+        assertEquals( new DefaultEntry(), indexEntry.getObject() );
+    }
+
+
+    @Test
+    public void testClear()
+    {
+        indexEntry.setTuple( new Tuple<Long, String>( 1L, "a" ), new DefaultEntry() );
+        indexEntry.clear();
+
+        assertNull( indexEntry.getId() );
+        assertNull( indexEntry.getValue() );
+        assertNull( indexEntry.getObject() );
+        assertNotNull( indexEntry.getTuple() );
+        assertNull( indexEntry.getTuple().getKey() );
+        assertNull( indexEntry.getTuple().getValue() );
+    }
+
+
+    @Test
+    public void testCopy()
+    {
+        // prepare index entry
+        indexEntry.setTuple( new Tuple<Long, String>( 1L, "a" ), new DefaultEntry() );
+
+        // create empty index entry and assert empty values
+        ReverseIndexEntry<String, Entry, Long> indexEntry2 = new ReverseIndexEntry<String, Entry, Long>();
+        assertNull( indexEntry2.getId() );
+        assertNull( indexEntry2.getValue() );
+        assertNull( indexEntry2.getObject() );
+        assertNotNull( indexEntry2.getTuple() );
+        assertNull( indexEntry2.getTuple().getKey() );
+        assertNull( indexEntry2.getTuple().getValue() );
+
+        // copy values and assert non-empty values
+        indexEntry2.copy( indexEntry );
+        assertEquals( Long.valueOf( 1L ), indexEntry2.getId() );
+        assertEquals( "a", indexEntry2.getValue() );
+        assertEquals( new DefaultEntry(), indexEntry2.getObject() );
+        assertEquals( new Tuple<Long, String>( 1L, "a" ), indexEntry2.getTuple() );
+    }
+
+
+    @Test
+    public void testToString()
+    {
+        indexEntry.setTuple( new Tuple<Long, String>( 1234567890L, "asdfghjkl" ), new DefaultEntry() );
+        assertTrue( indexEntry.toString().contains( "asdfghjkl" ) );
+        assertTrue( indexEntry.toString().contains( "1234567890" ) );
+    }
+
+}

Added: directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/SingletonIndexCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/SingletonIndexCursorTest.java?rev=944692&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/SingletonIndexCursorTest.java (added)
+++ directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/SingletonIndexCursorTest.java Sat May 15 18:08:03 2010
@@ -0,0 +1,261 @@
+/*
+ *  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.xdbm;
+
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Tests the {@link SingletonIndexCursor} class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SingletonIndexCursorTest
+{
+
+    private ForwardIndexEntry<String, Entry, Long> indexEntry;
+    private SingletonIndexCursor<String, Entry, Long> indexCursor;
+
+
+    @Before
+    public void setUp()
+    {
+        indexEntry = new ForwardIndexEntry<String, Entry, Long>();
+        indexEntry.setId( 1L );
+        indexEntry.setObject( new DefaultEntry() );
+        indexEntry.setValue( "test" );
+        indexCursor = new SingletonIndexCursor<String, Entry, Long>( indexEntry );
+    }
+
+
+    @Test
+    public void testConstructor()
+    {
+        new SingletonIndexCursor<String, Entry, Long>( indexEntry );
+    }
+
+
+    @Test(expected = InvalidCursorPositionException.class)
+    public void testGetNotPositioned() throws Exception
+    {
+        indexCursor.get();
+    }
+
+
+    @Test(expected = InvalidCursorPositionException.class)
+    public void testGetBeforeFirst() throws Exception
+    {
+        indexCursor.beforeFirst();
+        indexCursor.get();
+    }
+
+
+    @Test(expected = InvalidCursorPositionException.class)
+    public void testGetAfterLast() throws Exception
+    {
+        indexCursor.afterLast();
+        indexCursor.get();
+    }
+
+
+    @Test
+    public void testGet() throws Exception
+    {
+        // not positioned
+        indexCursor.next();
+        assertNotNull( indexCursor.get() );
+
+        indexCursor.first();
+        assertNotNull( indexCursor.get() );
+
+        indexCursor.last();
+        assertNotNull( indexCursor.get() );
+
+        indexCursor.afterLast();
+        assertTrue( indexCursor.previous() );
+        assertNotNull( indexCursor.get() );
+
+        indexCursor.beforeFirst();
+        assertTrue( indexCursor.next() );
+        assertNotNull( indexCursor.get() );
+    }
+
+
+    @Test
+    public void testIsElementReused() throws Exception
+    {
+        assertTrue( indexCursor.isElementReused() );
+    }
+
+
+    @Test
+    public void testBeforeFirst() throws Exception
+    {
+        // not explicitly positioned, implicit before first 
+        assertTrue( indexCursor.isBeforeFirst() );
+
+        indexCursor.first();
+        assertFalse( indexCursor.isBeforeFirst() );
+
+        indexCursor.beforeFirst();
+        assertTrue( indexCursor.isBeforeFirst() );
+    }
+
+
+    @Test
+    public void testAfterLast() throws Exception
+    {
+        assertFalse( indexCursor.isAfterLast() );
+
+        indexCursor.afterLast();
+        assertTrue( indexCursor.isAfterLast() );
+    }
+
+
+    @Test
+    public void testFirst() throws Exception
+    {
+        assertFalse( indexCursor.isFirst() );
+
+        assertTrue( indexCursor.first() );
+        assertTrue( indexCursor.isFirst() );
+        assertNotNull( indexCursor.get() );
+    }
+
+
+    @Test
+    public void testLast() throws Exception
+    {
+        assertFalse( indexCursor.isLast() );
+
+        assertTrue( indexCursor.last() );
+        assertTrue( indexCursor.isLast() );
+        assertNotNull( indexCursor.get() );
+    }
+
+
+    @Test
+    public void testAvailable() throws Exception
+    {
+        assertFalse( indexCursor.available() );
+
+        indexCursor.first();
+        assertTrue( indexCursor.available() );
+
+        indexCursor.last();
+        assertTrue( indexCursor.available() );
+
+        indexCursor.afterLast();
+        assertFalse( indexCursor.available() );
+
+        indexCursor.beforeFirst();
+        assertFalse( indexCursor.available() );
+    }
+
+
+    @Test
+    public void testNext() throws Exception
+    {
+        // not explicitly positioned, implicit before first 
+        assertTrue( indexCursor.next() );
+        assertFalse( indexCursor.next() );
+
+        // position before first
+        indexCursor.beforeFirst();
+        assertTrue( indexCursor.next() );
+        assertFalse( indexCursor.next() );
+
+        // position first
+        indexCursor.first();
+        assertFalse( indexCursor.next() );
+
+        // position last
+        indexCursor.last();
+        assertFalse( indexCursor.next() );
+
+        // position after first
+        indexCursor.afterLast();
+        assertFalse( indexCursor.next() );
+    }
+
+
+    @Test
+    public void testPrevious() throws Exception
+    {
+        // not positioned
+        assertFalse( indexCursor.previous() );
+
+        // position before first
+        indexCursor.beforeFirst();
+        assertFalse( indexCursor.previous() );
+
+        // position first
+        indexCursor.first();
+        assertFalse( indexCursor.previous() );
+
+        // position last
+        indexCursor.last();
+        assertFalse( indexCursor.previous() );
+
+        // position after first
+        indexCursor.afterLast();
+        assertTrue( indexCursor.previous() );
+        assertFalse( indexCursor.previous() );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testBefore() throws Exception
+    {
+        indexCursor.before( null );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testBeforeValue() throws Exception
+    {
+        indexCursor.beforeValue( 1L, "test" );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testAfter() throws Exception
+    {
+        indexCursor.after( null );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testAfterValue() throws Exception
+    {
+        indexCursor.afterValue( 1L, "test" );
+    }
+
+}

Added: directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/TupleTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/TupleTest.java?rev=944692&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/TupleTest.java (added)
+++ directory/apacheds/trunk/xdbm-base/src/test/java/org/apache/directory/server/xdbm/TupleTest.java Sat May 15 18:08:03 2010
@@ -0,0 +1,232 @@
+/*
+ *  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.xdbm;
+
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Test;
+
+
+/**
+ * Tests the {@link Tuple} class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class TupleTest
+{
+
+    @Test
+    public void testDefaultConstructor()
+    {
+        Tuple<String, Long> tuple = new Tuple<String, Long>();
+        assertNull( tuple.getKey() );
+        assertNull( tuple.getValue() );
+    }
+
+
+    @Test
+    public void testParameterConstructor()
+    {
+        Tuple<String, Long> tuple = new Tuple<String, Long>( "test", 6L );
+        assertEquals( "test", tuple.getKey() );
+        assertEquals( Long.valueOf( 6L ), tuple.getValue() );
+    }
+
+
+    @Test
+    public void testConstructorWithNullParameter()
+    {
+        Tuple<String, Long> tuple1 = new Tuple<String, Long>( null, null );
+        assertNull( tuple1.getKey() );
+        assertNull( tuple1.getValue() );
+
+        Tuple<String, Long> tuple2 = new Tuple<String, Long>( "test", null );
+        assertEquals( "test", tuple2.getKey() );
+        assertNull( tuple2.getValue() );
+
+        Tuple<String, Long> tuple3 = new Tuple<String, Long>( null, 6L );
+        assertNull( tuple3.getKey() );
+        assertEquals( Long.valueOf( 6L ), tuple3.getValue() );
+    }
+
+
+    @Test
+    public void testSetGetKey()
+    {
+        Tuple<String, Long> tuple = new Tuple<String, Long>();
+        assertNull( tuple.getKey() );
+
+        tuple.setKey( "a" );
+        assertEquals( "a", tuple.getKey() );
+
+        tuple.setKey( "b" );
+        assertEquals( "b", tuple.getKey() );
+
+        tuple.setKey( null );
+        assertNull( tuple.getKey() );
+    }
+
+
+    @Test
+    public void testSetGetValue()
+    {
+        Tuple<String, Long> tuple = new Tuple<String, Long>();
+        assertNull( tuple.getValue() );
+
+        tuple.setValue( 1L );
+        assertEquals( Long.valueOf( 1L ), tuple.getValue() );
+
+        tuple.setValue( 2L );
+        assertEquals( Long.valueOf( 2L ), tuple.getValue() );
+
+        tuple.setValue( null );
+        assertNull( tuple.getValue() );
+    }
+
+
+    @Test
+    public void testSetGetBoth()
+    {
+        Tuple<String, Long> tuple = new Tuple<String, Long>();
+        assertNull( tuple.getKey() );
+        assertNull( tuple.getValue() );
+
+        tuple.setBoth( "a", 1L );
+        assertEquals( "a", tuple.getKey() );
+        assertEquals( Long.valueOf( 1L ), tuple.getValue() );
+
+        tuple.setBoth( "b", 2L );
+        assertEquals( "b", tuple.getKey() );
+        assertEquals( Long.valueOf( 2L ), tuple.getValue() );
+
+        tuple.setBoth( null, null );
+        assertNull( tuple.getKey() );
+        assertNull( tuple.getValue() );
+    }
+
+
+    @Test
+    public void testSetGetBothTuple()
+    {
+        Tuple<String, Long> tuple = new Tuple<String, Long>();
+        assertNull( tuple.getKey() );
+        assertNull( tuple.getValue() );
+
+        tuple.setBoth( new Tuple<String, Long>( "a", 1L ) );
+        assertEquals( "a", tuple.getKey() );
+        assertEquals( Long.valueOf( 1L ), tuple.getValue() );
+
+        tuple.setBoth( new Tuple<String, Long>( "b", 2L ) );
+        assertEquals( "b", tuple.getKey() );
+        assertEquals( Long.valueOf( 2L ), tuple.getValue() );
+
+        tuple.setBoth( new Tuple<String, Long>() );
+        assertNull( tuple.getKey() );
+        assertNull( tuple.getValue() );
+    }
+
+
+    @Test
+    public void testEquals()
+    {
+        Tuple<String, Long> tuple0 = new Tuple<String, Long>();
+        Tuple<String, Long> tuple1 = new Tuple<String, Long>( "a", 1L );
+        Tuple<String, Long> tuple2 = new Tuple<String, Long>( "b", 2L );
+        Tuple<String, Long> tuple3 = new Tuple<String, Long>( "a", 2L );
+        Tuple<String, Long> tuple4 = new Tuple<String, Long>( "a", 1L );
+        Tuple<String, Long> tuple5 = new Tuple<String, Long>( "a", null );
+        Tuple<String, Long> tuple6 = new Tuple<String, Long>( null, 1L );
+
+        // test null and other instance
+        assertFalse( tuple0.equals( null ) );
+        assertFalse( tuple0.equals( new Object() ) );
+
+        // test equal tuples
+        assertTrue( tuple0.equals( new Tuple<String, Long>() ) );
+        assertTrue( tuple0.equals( tuple0 ) );
+        assertTrue( tuple1.equals( tuple4 ) );
+        assertTrue( tuple4.equals( tuple1 ) );
+
+        // test tuples with non-null key/value
+        assertFalse( tuple1.equals( tuple2 ) );
+        assertFalse( tuple1.equals( tuple3 ) );
+        assertFalse( tuple2.equals( tuple3 ) );
+
+        // test tuples with null key/value
+        assertFalse( tuple1.equals( tuple0 ) );
+        assertFalse( tuple0.equals( tuple1 ) );
+        assertFalse( tuple1.equals( tuple5 ) );
+        assertFalse( tuple5.equals( tuple1 ) );
+        assertFalse( tuple1.equals( tuple6 ) );
+        assertFalse( tuple6.equals( tuple1 ) );
+        assertFalse( tuple5.equals( tuple6 ) );
+        assertFalse( tuple6.equals( tuple5 ) );
+    }
+
+
+    @Test
+    public void testHashCodeEquals()
+    {
+        Set<Tuple<String, Long>> tupleSet = new HashSet<Tuple<String, Long>>();
+
+        Tuple<String, Long> tuple0 = new Tuple<String, Long>();
+        Tuple<String, Long> tuple1 = new Tuple<String, Long>( "a", 1L );
+        Tuple<String, Long> tuple2 = new Tuple<String, Long>( "b", 2L );
+        Tuple<String, Long> tuple3 = new Tuple<String, Long>( "a", 2L );
+        Tuple<String, Long> tuple4 = new Tuple<String, Long>( "a", 1L );
+
+        tupleSet.add( tuple0 );
+        tupleSet.add( tuple1 );
+        tupleSet.add( tuple2 );
+        tupleSet.add( tuple3 );
+        assertEquals( 4, tupleSet.size() );
+
+        tupleSet.add( tuple4 );
+        assertEquals( 4, tupleSet.size() );
+    }
+
+
+    @Test
+    public void testToString()
+    {
+        Tuple<String, Long> tuple0 = new Tuple<String, Long>();
+        Tuple<String, Long> tuple1 = new Tuple<String, Long>( "a", 1L );
+        Tuple<String, Long> tuple2 = new Tuple<String, Long>( "b", 2L );
+        Tuple<String, Long> tuple3 = new Tuple<String, Long>( "a", 1L );
+
+        assertNotNull( tuple0.toString() );
+        assertNotNull( tuple1.toString() );
+        assertNotNull( tuple2.toString() );
+        assertNotNull( tuple3.toString() );
+        assertFalse( tuple0.toString().equals( tuple1.toString() ) );
+        assertFalse( tuple1.toString().equals( tuple2.toString() ) );
+        assertTrue( tuple1.toString().equals( tuple3.toString() ) );
+    }
+
+}



Mime
View raw message