package info.ebenoit.ebul.cmp;


import org.junit.Test;
import static org.junit.Assert.*;



/** Tests for {@link DependencyInfo} */
public class TestDependencyInfo
{

	/** Test: name-based constructor throws {@link NullPointerException} if name is <code>null</code> */
	@Test( expected = NullPointerException.class )
	public void testNewWithNullName( )
	{
		new DependencyInfo( (String) null );
	}


	/** Test: class-based constructor throws {@link NullPointerException} if class is <code>null</code> */
	@Test( expected = NullPointerException.class )
	public void testNewWithNullClass( )
	{
		new DependencyInfo( (Class< ? >) null );
	}


	/** Test: class-based constructor throws {@link ComponentDefinitionException} if class is a primitive type */
	@Test( expected = ComponentDefinitionException.class )
	public void testNewWithPrimitiveType( )
	{
		new DependencyInfo( int.class );
	}


	/** Test: class-based constructor throws {@link ComponentDefinitionException} if class is an array type */
	@Test( expected = ComponentDefinitionException.class )
	public void testNewWithArrayType( )
	{
		new DependencyInfo( Object[].class );
	}


	/** Test: equals() method */
	@Test
	public void testEquals( )
	{
		DependencyInfo[] di = new DependencyInfo[] {
				new DependencyInfo( "test" ) , new DependencyInfo( "test" ) , new DependencyInfo( "test2" ) ,
				new DependencyInfo( String.class ) , new DependencyInfo( String.class ) ,
				new DependencyInfo( Object.class )
		};

		assertTrue( di[ 0 ].equals( di[ 0 ] ) );
		assertTrue( di[ 0 ].equals( di[ 1 ] ) );
		assertFalse( di[ 0 ].equals( di[ 2 ] ) );
		assertFalse( di[ 0 ].equals( di[ 3 ] ) );

		assertTrue( di[ 3 ].equals( di[ 3 ] ) );
		assertTrue( di[ 3 ].equals( di[ 4 ] ) );
		assertFalse( di[ 3 ].equals( di[ 5 ] ) );
		assertFalse( di[ 3 ].equals( di[ 0 ] ) );
	}
}