FileDocCategorySizeDatePackage
CircularListTest.javaAPI DocGlassfish v2 API5586Fri May 04 22:24:06 BST 2007com.sun.enterprise.management.util.misc

CircularListTest

public class CircularListTest extends TestCase

Fields Summary
Constructors Summary
public CircularListTest()

	
Methods Summary
public voidtestAddPastFull()

 		final int	capacity	= 10;
 		final int	count		= capacity * 10 + 1;
 		final CircularList<Integer>	list	= new CircularList<Integer>( Integer.class, capacity );

 		for( int i = 0; i < count; ++i )
 		{
 			list.add( new Integer( i ) );
 			
 			Integer	value	= (Integer)list.get( list.size() - 1 );
 			assertEquals( i, value.intValue() );
 			
 			if ( i >= capacity )
 			{
 				value	= (Integer)list.get( 0 );
 				assertEquals( 1 + (i - capacity), value.intValue()  );
 			}
 		}
 		assert( list.capacity() == capacity );
 	
public voidtestAddUntilFull()

 		final int	capacity	= 10;
 		final CircularList<Integer>	list	= new CircularList<Integer>( Integer.class, capacity );
 		assertEquals( capacity, list.capacity() );
 		
 		for( int i = 0; i < capacity; ++i )
 		{
 			list.add( new Integer( i ) );
 			assert( list.size() == i + 1 );
 			assert( ((Integer)list.get( i )).intValue() == i  );
 		}
 		assert( list.capacity() == capacity );
 	
public voidtestClear()

 		final CircularList<Object>	list	= new CircularList<Object>( Object.class, 10 );
 		
 		assertEquals( 0, list.size() );
 		
 		list.add( "hello" );
 		assertEquals( 1, list.size() );
 		list.clear();
 		assertEquals( 0, list.size() );
 		
 		assertEquals( 10, list.capacity() );
 	
public voidtestCreate()

 		new CircularList<Object>( Object.class, 10 );
 	
public voidtestCreateIllegal()

 		try
 		{
 			new CircularList<Object>( Object.class, 0 );
 			assert( false );
 		}
 		catch( IllegalArgumentException e )
 		{
 		}
 	
public voidtestEquals()

 		final int	capacity	= 2;
 		final CircularList<String>	list1	= new CircularList<String>( String.class, capacity );
 		final CircularList<String>	list2	= new CircularList<String>( String.class, capacity );
 		assert( list1.equals( list2 ) );
 		
 		list1.add( "hello" );
 		list1.add( "there" );
 		list2.add( "hello" );
 		list2.add( "there" );
 		
 		assert( list1.equals( list2 ) );
 	
public voidtestRemoveFirst()

 		final int	capacity	= 100;
 		final CircularList<Integer>	list	= new CircularList<Integer>( Integer.class, capacity );

 		for( int i = 0; i < capacity; ++i )
 		{
 			list.add( new Integer( i ) );
 		}
 		
 		for( int i = 0; i < capacity; ++i )
 		{
 			final Integer	value	= (Integer)list.removeFirst();
 			assertEquals( i, value.intValue() );
 		}
 	
public voidtestRemoveFirstLast()

 		final int	capacity	= 3;
 		final CircularList<String>	list	= new CircularList<String>( String.class, capacity );
 		
 		list.add( "hello" );
 		list.add( "xxx" );
 		list.add( "there" );
 		
 		assertEquals( "hello", list.removeFirst() );
 		assertEquals( "there", list.removeLast() );
 		assertEquals( 1, list.size() );
 	
public voidtestSet()

 		final int	capacity	= 100;
 		final CircularList<Integer>	list	= new CircularList<Integer>( Integer.class, capacity );

 		for( int i = 0; i < capacity; ++i )
 		{
 			list.add( new Integer( i ) );
 		}
 		
 		for( int i = 0; i < capacity; ++i )
 		{
 			final Integer	value	= (Integer)list.get( i );
 			list.set( i, value );
 			assertEquals( value, list.get( i ) );
 		}
 	
public voidtestSizeAndCapacity()

 		final CircularList<Object>	list	= new CircularList<Object>( Object.class, 10 );
 		
 		assertEquals( 0, list.size() );
 		assertEquals( 10, list.capacity() );